Skip to content

Commit

Permalink
Fix allocator bump in printf string allocation
Browse files Browse the repository at this point in the history
Fixes #373.
  • Loading branch information
gchatelet committed Dec 10, 2024
1 parent 0bc979d commit 3b23cdc
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/utils/list_cpu_features.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,13 @@ static Node* CreatePrintfString(const char* format, ...) {
const int written = vsnprintf(ptr, gBumpAllocator.size, format, arglist);
va_end(arglist);
if (written < 0 || written >= (int)gBumpAllocator.size) internal_error();
return CreateConstantString((char*)BA_Bump(written));
const int null_terminated_written = written + 1;
return CreateConstantString((char*)BA_Bump(null_terminated_written));
}

// Adds a string node.
// Adds a non empty string node.
static Node* CreateString(const char* value) {
if (value == NULL || *value == '\0') internal_error();
return CreatePrintfString("%s", value);
}

Expand Down

0 comments on commit 3b23cdc

Please sign in to comment.