eolian: fix out-of-bounds indexing on tokens

Fixes CID 1324818 @fix
This commit is contained in:
Daniel Kolesa 2015-10-04 14:52:36 +01:00
parent dad345e574
commit cc0476041f
1 changed files with 3 additions and 2 deletions

View File

@ -1148,8 +1148,9 @@ eo_lexer_token_to_str(int token, char *buf)
{
const char *v;
size_t idx = token - START_CUSTOM;
if (idx >= sizeof(tokens))
v = keywords[idx - sizeof(tokens)];
size_t tsz = sizeof(tokens) / sizeof(tokens[0]);
if (idx >= tsz)
v = keywords[idx - tsz];
else
v = tokens[idx];
memcpy(buf, v, strlen(v) + 1);