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

@@ -228,7 +228,7 @@ display_cmndspec_long(const struct sudoers_parse_tree *parse_tree,
if (cs->runcwd != NULL)
sudo_lbuf_append(lbuf, " Cwd: %s\n", cs->runcwd);
if (cs->timeout > 0) {
char numbuf[(((sizeof(int) * 8) + 2) / 3) + 2];
char numbuf[STRLEN_MAX_SIGNED(int) + 1];
(void)snprintf(numbuf, sizeof(numbuf), "%d", cs->timeout);
sudo_lbuf_append(lbuf, " Timeout: %s\n", numbuf);
}