Fix broken unpacking algorithm.
Also trim trailing whitespace.
This commit is contained in:
parent
a2e0c55fb4
commit
bcfecca1a1
1 changed files with 13 additions and 1 deletions
14
misc.c
14
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)
|
for (int i = 0; i < 5; ++i)
|
||||||
{
|
{
|
||||||
char advent = (packed >> i * 6) & 63;
|
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) */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue