ref: 5863cd10b85c49fa0e3b2a1dd0997f0db7bde26b
parent: 40f8e33e6cc293498c3e3ad53c534ebf66d262ac
author: JL2210 <[email protected]>
date: Wed Apr 8 13:25:26 EDT 2020
Fix possible null pointer dereference It's possible that if the FILE passed to yy_create_buffer is at the end-of file, there may be a null pointer dereference. This should hopefully fix that. Found with clang-tools' scan-build: src/asm/lexer.c:281:25: warning: Array access (via field 'pBuffer') results in a null pointer dereference pBuffer->pBuffer[size] = 0; ~~~~~~~ ^ 1 warning generated. Signed-off-by: JL2210 <[email protected]>
--- a/src/asm/lexer.c
+++ b/src/asm/lexer.c
@@ -254,7 +254,7 @@
else if (capacity == 0)
capacity = 1;
- while (!feof(f)) {
+ do {
if (buf == NULL || size >= capacity) {
if (buf)
capacity *= 2;
@@ -273,7 +273,7 @@
fatalerror("%s: fread error", __func__);
size += read_count;
- }
+ } while (!feof(f));
pBuffer->pBufferRealStart = buf;
pBuffer->pBufferStart = buf + SAFETYMARGIN;