projects
/
open-adventure.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix broken unpacking algorithm.
[open-adventure.git]
/
misc.c
diff --git
a/misc.c
b/misc.c
index 801331bdd06b14b3264ff1fbe5818daba780a44c..9da70dc8e447d0d9f04455c4659115bd465b0348 100644
(file)
--- a/
misc.c
+++ b/
misc.c
@@
-23,12
+23,24
@@
void* xmalloc(size_t size)
void packed_to_token(long packed, char token[6])
{
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;
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';
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) */
}
/* I/O routines (SPEAK, PSPEAK, RSPEAK, SETPRM, GETIN, YES) */