Skip to content

Commit

Permalink
Fix bug in scratch_buffer_printf.
Browse files Browse the repository at this point in the history
  • Loading branch information
lerno committed Apr 9, 2024
1 parent 18b4fce commit 0473858
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion releasenotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
- Added `print-input` command argument to print all files used for compilation

### Fixes
None
- Incorrect length passed to scratch buffer printf.

### Stdlib changes
None
Expand Down
5 changes: 3 additions & 2 deletions src/utils/stringutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,9 @@ void scratch_buffer_printf(const char *format, ...)
{
va_list args;
va_start(args, format);
uint32_t len_needed = (uint32_t)vsnprintf(&scratch_buffer.str[scratch_buffer.len], MAX_STRING_BUFFER, format, args);
if (scratch_buffer.len + len_needed > MAX_STRING_BUFFER - 1)
size_t available = MAX_STRING_BUFFER - scratch_buffer.len;
uint32_t len_needed = (uint32_t)vsnprintf(&scratch_buffer.str[scratch_buffer.len], available, format, args);
if (len_needed > available - 1)
{
error_exit("Scratch buffer size (%d chars) exceeded", MAX_STRING_BUFFER - 1);
}
Expand Down

0 comments on commit 0473858

Please sign in to comment.