From: Jason S. Ninneman Date: Sun, 11 Jun 2017 21:59:08 +0000 (-0700) Subject: Fix broken unpacking algorithm. X-Git-Tag: 1.1~408 X-Git-Url: https://jxself.org/git/?p=open-adventure.git;a=commitdiff_plain;h=bcfecca1a138d2b53238e213365d16b9e008881b Fix broken unpacking algorithm. Also trim trailing whitespace. --- diff --git a/misc.c b/misc.c index 801331b..9da70dc 100644 --- a/misc.c +++ b/misc.c @@ -23,12 +23,24 @@ void* xmalloc(size_t size) void packed_to_token(long packed, char token[6]) { + // Unpack and map back to ASCII. for (int i = 0; i < 5; ++i) { char advent = (packed >> i * 6) & 63; - token[i] = advent_to_ascii[advent]; + token[4 - i] = advent_to_ascii[advent]; } + + // Ensure the last character is \0. token[5] = '\0'; + + // Replace trailing whitespace with \0. + for (int i = 4; i >= 0; --i) + { + if (token[i] == ' ' || token[i] == '\t') + token[i] = '\0'; + else + break; + } } /* I/O routines (SPEAK, PSPEAK, RSPEAK, SETPRM, GETIN, YES) */