Skip to content

Commit

Permalink
fix normalise_string to prevent issues when lexer->buflen == 0 (#…
Browse files Browse the repository at this point in the history
…4359)

This was flagged by either the memory sanitizer or the undefined
behavior sanitizer as an issue.

This commit changes the datatype of `i` to be `ssize_t` so that
`lexer->buflen - 1` becomes less than 0 when `lexer->buflen` == 0.
  • Loading branch information
dipinhora committed Jul 7, 2023
1 parent 64dcc74 commit 8b72fa5
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/libponyc/ast/lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ static void normalise_string(lexer_t* lexer)

// Trim trailing empty line
size_t trim = 0;
for (size_t i = (lexer->buflen - 1); i>0; i--)
for (ssize_t i = (lexer->buflen - 1); i>0; i--)
{
char c = lexer->buffer[i];
if (c == '\n')
Expand Down

0 comments on commit 8b72fa5

Please sign in to comment.