palm-client: contact keys and unknown-sender prefixes in hex without StrPrintF (showed zeros)

This commit is contained in:
rich committed 2026-11-02 12:39:35 -05:00
1 parent deec3112d4
commit ae4d8453d8
6 files changed
+41 -5

No files matched your search

+4 -4
View File
@@ -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)
+2 -1
View File
@@ -1,6 +1,7 @@
#include <PalmOS.h>
#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)
+3
View File
@@ -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.
+19
View File
@@ -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;
}
+6
View File
@@ -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;
+7
View File
@@ -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);