core: Avoid trivial snprintfs.
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 34m10s

This commit is contained in:
2025-06-10 21:17:55 -04:00
parent 3a2a829940
commit b135a210cc
13 changed files with 96 additions and 74 deletions

View File

@ -612,7 +612,7 @@ static int _tf_util_backtrace_single_callback(void* data, uintptr_t pc, const ch
{
char** stack = data;
char line[256];
int length = snprintf(line, sizeof(line), "%s", function);
int length = (int)tf_string_set(line, sizeof(line), function);
int current = *stack ? strlen(*stack) : 0;
*stack = tf_resize_vec(*stack, current + length + 1);
memcpy(*stack + current, line, length + 1);
@ -700,3 +700,18 @@ uint32_t tf_util_fnv32a(const void* buffer, int length, uint32_t start)
}
return result;
}
size_t tf_string_set(char* buffer, size_t size, const char* string)
{
size_t length = string ? strlen(string) : 0;
length = tf_min(length, size - 1);
if (size)
{
if (length)
{
memcpy(buffer, string, length);
}
buffer[length] = 0;
}
return length;
}