From: Todd C. Miller Date: Fri, 11 May 2018 03:17:03 +0000 (-0600) Subject: Fix a format-truncation warning in newer gcc by avoiding using %0x X-Git-Tag: SUDO_1_8_24^2~92 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6e290763ca51a3ef45eb1c799b519425ecfa7d41;p=sudo Fix a format-truncation warning in newer gcc by avoiding using %0x and %0X in the test. We are formatting a single byte so just do it one nybble at a time. --- diff --git a/plugins/sudoers/regress/parser/check_hexchar.c b/plugins/sudoers/regress/parser/check_hexchar.c index f0bf7c835..d4f965783 100644 --- a/plugins/sudoers/regress/parser/check_hexchar.c +++ b/plugins/sudoers/regress/parser/check_hexchar.c @@ -50,6 +50,8 @@ main(int argc, char *argv[]) { struct hexchar_test *test_data; int i, ntests, result, errors = 0; + static const char xdigs_lower[] = "0123456789abcdef"; + static const char xdigs_upper[] = "0123456789ABCDEF"; initprogname(argc > 0 ? argv[0] : "check_hexchar"); @@ -58,11 +60,13 @@ main(int argc, char *argv[]) test_data = calloc(sizeof(*test_data), ntests); for (i = 0; i < 256; i++) { /* lower case */ - snprintf(test_data[i].hex, sizeof(test_data[i].hex), "%02x", i); test_data[i].value = i; + test_data[i].hex[1] = xdigs_lower[ (i & 0x0f)]; + test_data[i].hex[0] = xdigs_lower[((i & 0xf0) >> 4)]; /* upper case */ - snprintf(test_data[i + 256].hex, sizeof(test_data[i + 256].hex), "%02X", i); test_data[i + 256].value = i; + test_data[i + 256].hex[1] = xdigs_upper[ (i & 0x0f)]; + test_data[i + 256].hex[0] = xdigs_upper[((i & 0xf0) >> 4)]; } /* Also test invalid data */ test_data[ntests - 3].hex[0] = '\0'; @@ -75,7 +79,7 @@ main(int argc, char *argv[]) for (i = 0; i < ntests; i++) { result = hexchar(test_data[i].hex); if (result != test_data[i].value) { - fprintf(stderr, "check_hexchar: expected %d, got %d", + fprintf(stderr, "check_hexchar: expected %d, got %d\n", test_data[i].value, result); errors++; }