Check return value of fgets() in Json.c

This commit is contained in:
Jordan Bancino 2022-08-09 20:18:13 -04:00
parent a24d9b6c29
commit 76937a57a4

View file

@ -791,7 +791,12 @@ JsonTokenSeek(JsonParserState * state)
switch (c) switch (c)
{ {
case 't': case 't':
fgets(state->token, 5, state->stream); if (!fgets(state->token, 5, state->stream))
{
state->tokenType = TOKEN_EOF;
return;
}
if (!strcmp("true", state->token)) if (!strcmp("true", state->token))
{ {
state->tokenType = TOKEN_BOOLEAN; state->tokenType = TOKEN_BOOLEAN;
@ -803,7 +808,12 @@ JsonTokenSeek(JsonParserState * state)
} }
break; break;
case 'f': case 'f':
fgets(state->token, 6, state->stream); if (!fgets(state->token, 6, state->stream))
{
state->tokenType = TOKEN_EOF;
return;
}
if (!strcmp("false", state->token)) if (!strcmp("false", state->token))
{ {
state->tokenType = TOKEN_BOOLEAN; state->tokenType = TOKEN_BOOLEAN;
@ -815,7 +825,12 @@ JsonTokenSeek(JsonParserState * state)
} }
break; break;
case 'n': case 'n':
fgets(state->token, 5, state->stream); if (!fgets(state->token, 5, state->stream))
{
state->tokenType = TOKEN_EOF;
return;
}
if (!strcmp("null", state->token)) if (!strcmp("null", state->token))
{ {
state->tokenType = TOKEN_NULL; state->tokenType = TOKEN_NULL;