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

@@ -302,7 +302,7 @@ sudo_lbuf_append_v1(struct sudo_lbuf *lbuf, const char * restrict fmt, ...)
num_end++;
if (num_end[0] == '$' && num_end[1] == 's' && num_end > num_start) {
/* Convert the numeric part to an integer */
char numbuf[(((sizeof(int) * 8) + 2) / 3) + 2];
char numbuf[STRLEN_MAX_SIGNED(int) + 1];
len = (unsigned int)(num_end - num_start);
if (len >= sizeof(numbuf)) {
errno = EINVAL;