From ae4d8453d8375dd541da88ab2d49a2470e797dc3 Mon Sep 17 00:00:00 2001 From: "Rich O." Date: Mon, 2 Nov 2026 12:39:35 -0500 Subject: [PATCH] palm-client: contact keys and unknown-sender prefixes in hex without StrPrintF (showed zeros) --- palm-client/src/contact_form.c | 8 ++++---- palm-client/src/convos.c | 3 ++- palm-client/src/sections.h | 3 +++ palm-client/src/ui/text.c | 19 +++++++++++++++++++ palm-client/src/ui/text.h | 6 ++++++ palm-client/tests/test_text.c | 7 +++++++ 6 files changed, 41 insertions(+), 5 deletions(-) diff --git a/palm-client/src/contact_form.c b/palm-client/src/contact_form.c index 2f63ed0..9b3193f 100644 --- a/palm-client/src/contact_form.c +++ b/palm-client/src/contact_form.c @@ -83,11 +83,11 @@ static void FormatWhen(Char *out, UInt32 utc) static void DrawHex(const UInt8 *bytes, UInt16 n, Coord x, Coord y) { Char hex[2 * 16 + 1]; - UInt16 i; - for (i = 0; i < n && i < 16; i++) - StrPrintF(hex + 2 * i, "%02x", bytes[i]); - WinDrawChars(hex, (Int16)(2 * i), x, y); + if (n > 16) + n = 16; + TxtHex(bytes, n, hex); + WinDrawChars(hex, (Int16)(2 * n), x, y); } static void DrawRow(UInt16 row, const RectangleType *b, void *ctx) diff --git a/palm-client/src/convos.c b/palm-client/src/convos.c index cf504a3..5eff346 100644 --- a/palm-client/src/convos.c +++ b/palm-client/src/convos.c @@ -1,6 +1,7 @@ #include #include "protocol.h" #include "ui/glyphs.h" +#include "ui/text.h" #include "channels.h" #include "contacts.h" #include "messages.h" @@ -18,7 +19,7 @@ static void SetPreview(VmConvRow *r, const VmMsgHeader *h) VM_SECT2; static void HexPrefix(const UInt8 *p, Char *out) { - StrPrintF(out, "%02x%02x%02x%02x", p[0], p[1], p[2], p[3]); + TxtHex(p, 4, out); } void ContactNameForPrefix(const UInt8 *prefix, Char *out, UInt16 size) diff --git a/palm-client/src/sections.h b/palm-client/src/sections.h index debc07a..aa883a8 100644 --- a/palm-client/src/sections.h +++ b/palm-client/src/sections.h @@ -20,6 +20,9 @@ * be const (font widths and presets hit this). * - -fwritable-strings: literals move to .data but are still addressed * PC-relative. Don't use it. + * - A static const table inside a function in an extra section (e.g. a hex + * digit string) reads as garbage on the Visor, and check_sections.py doesn't + * catch it. Compute such values instead (ui/text.c TxtHex). * tools/check_sections.py runs after every link and fails the build on any * PC-relative reference from vmcode2 to outside it. * On the host (tests) and in the editor's clang checker the attribute compiles away. diff --git a/palm-client/src/ui/text.c b/palm-client/src/ui/text.c index 25d3345..0cfbe84 100644 --- a/palm-client/src/ui/text.c +++ b/palm-client/src/ui/text.c @@ -266,3 +266,22 @@ UInt16 TxtPalmToUtf8(const Char *in, UInt16 inLen, UInt8 *out, UInt16 outSize) } return o; } + +/* Arithmetic, not a digit table: a static table here sits outside vmcode2 + * and read as garbage on the Visor (sections.h). */ +static Char HexDigit(UInt8 d) VM_SECT2; +static Char HexDigit(UInt8 d) +{ + return (Char)(d < 10 ? '0' + d : 'a' + d - 10); +} + +void TxtHex(const UInt8 *bytes, UInt16 n, Char *out) +{ + UInt16 i; + + for (i = 0; i < n; i++) { + *out++ = HexDigit(bytes[i] >> 4); + *out++ = HexDigit(bytes[i] & 15); + } + *out = 0; +} diff --git a/palm-client/src/ui/text.h b/palm-client/src/ui/text.h index ed87826..5efe57d 100644 --- a/palm-client/src/ui/text.h +++ b/palm-client/src/ui/text.h @@ -34,6 +34,12 @@ UInt16 TxtWrap(const Char *s, UInt16 len, Int16 maxW, TxtWidthFn w, UInt16 *cons /* "now", "5m", "23h", "3d", "2y" (MeshTerm's aligned-column ages). */ void TxtFormatAge(Char *out, UInt32 seconds) VM_SECT2; +/* + * n bytes as 2n lowercase hex digits plus a NUL. Not StrPrintF: the Visor's + * %x prints 4 digits for a byte, so "%02x" per byte overlapped and showed zeros. + */ +void TxtHex(const UInt8 *bytes, UInt16 n, Char *out) VM_SECT2; + /* SNR in quarter dB as a whole number: "+6dB", "-3dB", "0dB". */ void TxtFormatSnr(Char *out, Int8 quarterDb) VM_SECT2; diff --git a/palm-client/tests/test_text.c b/palm-client/tests/test_text.c index 6a01d80..a60e09f 100644 --- a/palm-client/tests/test_text.c +++ b/palm-client/tests/test_text.c @@ -80,6 +80,13 @@ static void test_age_and_snr(void) { char buf[16]; + { + static const UInt8 key[] = { 0x00, 0x9c, 0xd8, 0xff, 0x0a }; + Char hex[11]; + + TxtHex(key, 5, hex); CHECK(strcmp(hex, "009cd8ff0a") == 0); + TxtHex(key, 0, hex); CHECK(hex[0] == 0); + } TxtFormatAge(buf, 0); CHECK(strcmp(buf, "now") == 0); TxtFormatAge(buf, 59); CHECK(strcmp(buf, "now") == 0); TxtFormatAge(buf, 300); CHECK(strcmp(buf, "5m") == 0);