From 6be3584467ee5b56d7c7f857f8cbc70cd460d411 Mon Sep 17 00:00:00 2001 From: Rangi Date: Thu, 15 Apr 2021 19:52:50 -0400 Subject: [PATCH] LexerState's 'size' and 'offset' for mmapped files are unsigned These were using signed 'off_t' because that is the type of 'st_size' from 'stat()', but neither one can be negative. --- src/asm/lexer.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/asm/lexer.c b/src/asm/lexer.c index 358e40e8..11837a6d 100644 --- a/src/asm/lexer.c +++ b/src/asm/lexer.c @@ -309,7 +309,7 @@ struct Expansion { char const *unowned; char *owned; } contents; - size_t len; + size_t len; /* Length of the contents */ size_t totalLen; size_t distance; /* Distance between the beginning of this expansion and of its parent */ bool owned; /* Whether or not to free contents when this expansion is freed */ @@ -329,8 +329,8 @@ struct LexerState { union { struct { /* If mmap()ed */ char *ptr; /* Technically `const` during the lexer's execution */ - off_t size; - off_t offset; + size_t size; + size_t offset; bool isReferenced; /* If a macro in this file requires not unmapping it */ }; struct { /* Otherwise */ @@ -501,7 +501,8 @@ struct LexerState *lexer_OpenFile(char const *path) state->isMmapped = true; state->isReferenced = false; // By default, a state isn't referenced state->ptr = mappingAddr; - state->size = fileInfo.st_size; + assert(fileInfo.st_size >= 0); + state->size = (size_t)fileInfo.st_size; state->offset = 0; if (verbose) @@ -876,7 +877,7 @@ restart: if (lexerState->macroArgScanDistance > 0) return c; - lexerState->macroArgScanDistance = 1; /* Do not consider again */ + lexerState->macroArgScanDistance++; /* Do not consider again */ if (c == '\\' && !lexerState->disableMacroArgs) { /* If character is a backslash, check for a macro arg */