Add macros to determine the length of an integer type in string form.

Adapted from answer #6 in:
https://stackoverflow.com/questions/10536207/ansi-c-maximum-number-of-characters-printing-a-decimal-int
This commit is contained in:
Todd C. Miller
2023-09-19 15:15:02 -06:00
parent 221a10340c
commit d53bbb54b2
12 changed files with 16 additions and 12 deletions

View File

@@ -318,7 +318,7 @@ sudo_json_add_value_int(struct json_container *jsonc, const char *name,
struct json_value *value, bool as_object)
{
struct json_container saved_container = *jsonc;
char numbuf[(((sizeof(long long) * 8) + 2) / 3) + 2];
char numbuf[STRLEN_MAX_SIGNED(long long) + 1];
debug_decl(sudo_json_add_value, SUDO_DEBUG_UTIL);
/* Add comma if we are continuing an object/array. */