mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-21 10:42:07 +00:00
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 <larrowe.semaj11@gmail.com>
This commit is contained in:
@@ -254,7 +254,7 @@ YY_BUFFER_STATE yy_create_buffer(FILE *f)
|
|||||||
else if (capacity == 0)
|
else if (capacity == 0)
|
||||||
capacity = 1;
|
capacity = 1;
|
||||||
|
|
||||||
while (!feof(f)) {
|
do {
|
||||||
if (buf == NULL || size >= capacity) {
|
if (buf == NULL || size >= capacity) {
|
||||||
if (buf)
|
if (buf)
|
||||||
capacity *= 2;
|
capacity *= 2;
|
||||||
@@ -273,7 +273,7 @@ YY_BUFFER_STATE yy_create_buffer(FILE *f)
|
|||||||
fatalerror("%s: fread error", __func__);
|
fatalerror("%s: fread error", __func__);
|
||||||
|
|
||||||
size += read_count;
|
size += read_count;
|
||||||
}
|
} while (!feof(f));
|
||||||
|
|
||||||
pBuffer->pBufferRealStart = buf;
|
pBuffer->pBufferRealStart = buf;
|
||||||
pBuffer->pBufferStart = buf + SAFETYMARGIN;
|
pBuffer->pBufferStart = buf + SAFETYMARGIN;
|
||||||
|
|||||||
Reference in New Issue
Block a user