aboutsummaryrefslogtreecommitdiff
path: root/asm
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2024-04-14 01:57:04 +0630
committerAryadev Chavali <aryadev@aryadevchavali.com>2024-04-14 02:00:17 +0630
commit4e9eb0a42eacdf11c9f5f3d2d9e16ef1b7ce9610 (patch)
treeae454c44e4bd961e041ca54c6501f79c3aecf4f4 /asm
parente2667eda65068cf1aad40f3e34fafb7814d75b1f (diff)
downloadovm-0.0.1.tar.gz
ovm-0.0.1.tar.bz2
ovm-0.0.1.zip
fix! loops in preprocess_use_blocks iterate to the wrong bound0.0.1
A token_stream being constructed on the spot has different used/available properties to a fully constructed one: a fully constructed token stream uses available to hold the total number of tokens and used as an internal iterator, while one that is still being constructed uses the semantics of a standard darr. Furthermore, some loops didn't divide by ~sizeof(token_t)~ which lead to iteration over bound errors.
Diffstat (limited to 'asm')
-rw-r--r--asm/parser.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/asm/parser.c b/asm/parser.c
index d976e67..d326d14 100644
--- a/asm/parser.c
+++ b/asm/parser.c
@@ -379,7 +379,7 @@ perr_t preprocess_use_blocks(token_stream_t *stream, token_stream_t *new)
DARR_AT(token_t, stream->data, i + 1).type != TOKEN_LITERAL_STRING)
{
stream->used = i + 1 >= stream->available ? i : i + 1;
- for (size_t i = 0; i < (new_stream.available / sizeof(token_t)); ++i)
+ for (size_t i = 0; i < (new_stream.used / sizeof(token_t)); ++i)
free(TOKEN_STREAM_AT(new_stream.data, i).str);
free(new_stream.data);
return PERR_PREPROCESSOR_EXPECTED_STRING;
@@ -390,7 +390,7 @@ perr_t preprocess_use_blocks(token_stream_t *stream, token_stream_t *new)
FILE *fp = fopen(t.str, "rb");
if (!fp)
{
- for (size_t i = 0; i < new_stream.available; ++i)
+ for (size_t i = 0; i < (new_stream.used / sizeof(token_t)); ++i)
free(TOKEN_STREAM_AT(new_stream.data, i).str);
free(new_stream.data);
stream->used = i;
@@ -410,7 +410,7 @@ perr_t preprocess_use_blocks(token_stream_t *stream, token_stream_t *new)
free(TOKEN_STREAM_AT(fstream.data, i).str);
free(fstream.data);
}
- for (size_t i = 0; i < new_stream.available; ++i)
+ for (size_t i = 0; i < (new_stream.used / sizeof(token_t)); ++i)
free(TOKEN_STREAM_AT(new_stream.data, i).str);
free(new_stream.data);
stream->used = i;