CVS commit: src/tests/lib/libutil
Module Name:src Committed By: rillig Date: Mon Apr 1 09:15:51 UTC 2024 Modified Files: src/tests/lib/libutil: t_snprintb.c Log Message: tests/snprintb_m: test null-terminated output in error case While here, clean up the buffer handling for the visualized array content in case of a failed test. To generate a diff of this commit: cvs rdiff -u -r1.31 -r1.32 src/tests/lib/libutil/t_snprintb.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/lib/libutil
Module Name:src Committed By: rillig Date: Mon Apr 1 09:15:51 UTC 2024 Modified Files: src/tests/lib/libutil: t_snprintb.c Log Message: tests/snprintb_m: test null-terminated output in error case While here, clean up the buffer handling for the visualized array content in case of a failed test. To generate a diff of this commit: cvs rdiff -u -r1.31 -r1.32 src/tests/lib/libutil/t_snprintb.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/lib/libutil/t_snprintb.c diff -u src/tests/lib/libutil/t_snprintb.c:1.31 src/tests/lib/libutil/t_snprintb.c:1.32 --- src/tests/lib/libutil/t_snprintb.c:1.31 Mon Mar 25 20:39:27 2024 +++ src/tests/lib/libutil/t_snprintb.c Mon Apr 1 09:15:51 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: t_snprintb.c,v 1.31 2024/03/25 20:39:27 rillig Exp $ */ +/* $NetBSD: t_snprintb.c,v 1.32 2024/04/01 09:15:51 rillig Exp $ */ /* * Copyright (c) 2002, 2004, 2008, 2010, 2024 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2008, 2010, 2024\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_snprintb.c,v 1.31 2024/03/25 20:39:27 rillig Exp $"); +__RCSID("$NetBSD: t_snprintb.c,v 1.32 2024/04/01 09:15:51 rillig Exp $"); #include #include @@ -42,19 +42,16 @@ __RCSID("$NetBSD: t_snprintb.c,v 1.31 20 #include static const char * -vis_arr(const char *arr, size_t arrsize) +vis_arr(char *buf, size_t bufsize, const char *arr, size_t arrsize) { - static char buf[3][1024]; - static size_t i; - - i = (i + 1) % (sizeof(buf) / sizeof(buf[0])); - int rv = strnvisx(buf[i] + 1, sizeof(buf[i]) - 2, arr, arrsize, + ATF_REQUIRE(bufsize >= 2); + int rv = strnvisx(buf + 1, bufsize - 2, arr, arrsize, VIS_WHITE | VIS_OCTAL); ATF_REQUIRE_MSG(rv >= 0, "buffer too small for size %zu", arrsize); - buf[i][0] = '"'; - buf[i][1 + rv] = '"'; - buf[i][1 + rv + 1] = '\0'; - return buf[i]; + buf[0] = '"'; + buf[1 + rv] = '"'; + buf[1 + rv + 1] = '\0'; + return buf; } static void @@ -63,7 +60,7 @@ check_snprintb_m(const char *file, size_ size_t line_max, int want_rv, const char *want_buf, size_t want_bufsize) { - char buf[1024]; + char buf[1024], vis_bitfmt[1024], vis_want_buf[1024], vis_buf[1024]; ATF_REQUIRE(bufsize <= sizeof(buf)); ATF_REQUIRE(want_bufsize <= sizeof(buf)); @@ -103,11 +100,12 @@ check_snprintb_m(const char *file, size_ "\twant: %d bytes %s\n" "\thave: %d bytes %s\n", file, line, - vis_arr(bitfmt, bitfmtlen), + vis_arr(vis_bitfmt, sizeof(vis_bitfmt), bitfmt, bitfmtlen), (uintmax_t)val, line_max, - want_rv, vis_arr(want_buf, want_bufsize), - rv, vis_arr(buf, have_bufsize)); + want_rv, vis_arr(vis_want_buf, sizeof(vis_want_buf), + want_buf, want_bufsize), + rv, vis_arr(vis_buf, sizeof(vis_buf), buf, have_bufsize)); } #define h_snprintb_m_len(bufsize, bitfmt, val, line_max, \ @@ -1501,6 +1499,15 @@ ATF_TC_BODY(snprintb_m, tc) "0x800f0701\0" "0x800f0701\0"); + // new style, missing number base + h_snprintb_m_len( + 1024, + "\177", + 0xff, + 128, + -1, + "#\0"); + // new style, buffer too small for complete number in line 2 h_snprintb_m_len( 15,
CVS commit: src/tests/lib/libutil
Module Name:src Committed By: rillig Date: Sat Feb 24 13:00:00 UTC 2024 Modified Files: src/tests/lib/libutil: t_snprintb.c Log Message: tests/snprintb: clean up tests Always write the value to be formatted in hexadecimal, to make it easily distinguishable from the buffer size and maximum line length. Use consistent wording in the comments of the test cases. Be stricter about mistakes in a format. Fix some wrong numbers in the snprintb_m tests for limited line length. To generate a diff of this commit: cvs rdiff -u -r1.28 -r1.29 src/tests/lib/libutil/t_snprintb.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/lib/libutil
Module Name:src Committed By: rillig Date: Sat Feb 24 13:00:00 UTC 2024 Modified Files: src/tests/lib/libutil: t_snprintb.c Log Message: tests/snprintb: clean up tests Always write the value to be formatted in hexadecimal, to make it easily distinguishable from the buffer size and maximum line length. Use consistent wording in the comments of the test cases. Be stricter about mistakes in a format. Fix some wrong numbers in the snprintb_m tests for limited line length. To generate a diff of this commit: cvs rdiff -u -r1.28 -r1.29 src/tests/lib/libutil/t_snprintb.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/lib/libutil/t_snprintb.c diff -u src/tests/lib/libutil/t_snprintb.c:1.28 src/tests/lib/libutil/t_snprintb.c:1.29 --- src/tests/lib/libutil/t_snprintb.c:1.28 Sat Feb 24 12:40:00 2024 +++ src/tests/lib/libutil/t_snprintb.c Sat Feb 24 13:00:00 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: t_snprintb.c,v 1.28 2024/02/24 12:40:00 rillig Exp $ */ +/* $NetBSD: t_snprintb.c,v 1.29 2024/02/24 13:00:00 rillig Exp $ */ /* * Copyright (c) 2002, 2004, 2008, 2010, 2024 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2008, 2010, 2024\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_snprintb.c,v 1.28 2024/02/24 12:40:00 rillig Exp $"); +__RCSID("$NetBSD: t_snprintb.c,v 1.29 2024/02/24 13:00:00 rillig Exp $"); #include #include @@ -44,15 +44,16 @@ __RCSID("$NetBSD: t_snprintb.c,v 1.28 20 static const char * vis_arr(const char *arr, size_t arrsize) { - static char buf[6][1024]; + static char buf[3][1024]; static size_t i; i = (i + 1) % (sizeof(buf) / sizeof(buf[0])); - buf[i][0] = '"'; int rv = strnvisx(buf[i] + 1, sizeof(buf[i]) - 2, arr, arrsize, VIS_WHITE | VIS_OCTAL); - ATF_REQUIRE_MSG(rv >= 0, "strnvisx failed for size %zu", arrsize); - strcpy(buf[i] + 1 + rv, "\""); + ATF_REQUIRE_MSG(rv >= 0, "buffer too small for size %zu", arrsize); + buf[i][0] = '"'; + buf[i][1 + rv] = '"'; + buf[i][1 + rv + 1] = '\0'; return buf[i]; } @@ -73,12 +74,12 @@ check_snprintb_m(const char *file, size_ file, line); if (bufsize == 0) want_bufsize = 0; + memset(buf, 0x5a, sizeof(buf)); - memset(buf, 'Z', sizeof(buf)); int rv = snprintb_m(buf, bufsize, bitfmt, val, line_max); size_t have_bufsize = sizeof(buf); - while (have_bufsize > 0 && buf[have_bufsize - 1] == 'Z') + while (have_bufsize > 0 && buf[have_bufsize - 1] == 0x5a) have_bufsize--; if (rv > 0 && (unsigned)rv < have_bufsize && buf[rv - 1] == '\0' && buf[rv] == '\0') @@ -122,7 +123,7 @@ check_snprintb_m(const char *file, size_ h_snprintb_m_len(bufsize, bitfmt, val, 0, want_rv, want_buf) #define h_snprintb_error(bitfmt, want_buf)\ - h_snprintb_m_len(1024, bitfmt, 0, 0, -1, want_buf) + h_snprintb_m_len(1024, bitfmt, 0x00, 0, -1, want_buf) #define h_snprintb_m(bitfmt, val, line_max, want_buf) \ h_snprintb_m_len(1024, bitfmt, val, line_max, \ @@ -141,7 +142,7 @@ ATF_TC_BODY(snprintb, tc) // The value 0 does not get a leading '0'. h_snprintb( "\010", - 0, + 0x00, "0"); // style and number base, old style, octal, nonzero value @@ -155,7 +156,7 @@ ATF_TC_BODY(snprintb, tc) // style and number base, old style, decimal, zero value h_snprintb( "\012", - 0, + 0x00, "0"); // style and number base, old style, decimal, nonzero value @@ -169,7 +170,7 @@ ATF_TC_BODY(snprintb, tc) // The value 0 does not get a leading '0x'. h_snprintb( "\020", - 0, + 0x00, "0"); // style and number base, old style, hexadecimal, nonzero value @@ -200,7 +201,7 @@ ATF_TC_BODY(snprintb, tc) // The value 0 does not get a leading '0'. h_snprintb( "\177\010", - 0, + 0x00, "0"); // style and number base, new style, octal, nonzero value @@ -214,7 +215,7 @@ ATF_TC_BODY(snprintb, tc) // style and number base, new style, decimal, zero value h_snprintb( "\177\012", - 0, + 0x00, "0"); // style and number base, new style, decimal, nonzero value @@ -228,7 +229,7 @@ ATF_TC_BODY(snprintb, tc) // The value 0 does not get a leading '0x'. h_snprintb( "\177\020", - 0, + 0x00, "0"); // style and number base, new style, hexadecimal, nonzero value @@ -278,7 +279,7 @@ ATF_TC_BODY(snprintb, tc) "\020" "\001bit1" "\041bit33", - 0x1, + 0x01, "0x1"); // old style, repeated bit numbers @@ -289,14 +290,14 @@ ATF_TC_BODY(snprintb, tc) "\020" "\001once" "\001again", - 0x1, + 0x01, "0x1"); // old style, non-printable description // // The characters ' ' and '\t' are interpreted as bit numbers, - // not as part of the description; the visual arrangement is - // misleading. + // not as part of the description; the visual arrangement in this +
CVS commit: src/tests/lib/libutil
Module Name:src Committed By: rillig Date: Tue Feb 20 21:45:36 UTC 2024 Modified Files: src/tests/lib/libutil: t_snprintb.c Log Message: tests/snprintb: test '=' and '*' directives that can never match To generate a diff of this commit: cvs rdiff -u -r1.24 -r1.25 src/tests/lib/libutil/t_snprintb.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/lib/libutil/t_snprintb.c diff -u src/tests/lib/libutil/t_snprintb.c:1.24 src/tests/lib/libutil/t_snprintb.c:1.25 --- src/tests/lib/libutil/t_snprintb.c:1.24 Tue Feb 20 20:31:56 2024 +++ src/tests/lib/libutil/t_snprintb.c Tue Feb 20 21:45:36 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: t_snprintb.c,v 1.24 2024/02/20 20:31:56 rillig Exp $ */ +/* $NetBSD: t_snprintb.c,v 1.25 2024/02/20 21:45:36 rillig Exp $ */ /* * Copyright (c) 2002, 2004, 2008, 2010, 2024 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2008, 2010, 2024\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_snprintb.c,v 1.24 2024/02/20 20:31:56 rillig Exp $"); +__RCSID("$NetBSD: t_snprintb.c,v 1.25 2024/02/20 21:45:36 rillig Exp $"); #include #include @@ -75,7 +75,9 @@ h_snprintb_loc(const char *file, size_t memset(buf, 'Z', sizeof(buf)); int rv = snprintb(buf, bufsize, bitfmt, val); - ATF_REQUIRE(rv >= 0); + ATF_CHECK_MSG(rv >= 0, "%s:%zu: unexpected rv %d", file, line, rv); + if (rv < 0) + return; size_t have_bufsize = sizeof(buf); while (have_bufsize > 0 && buf[have_bufsize - 1] == 'Z') have_bufsize--; @@ -681,6 +683,15 @@ ATF_TC_BODY(snprintb, tc) 0x3, "0x3"); + // new style bit-field, '=', can never match + h_snprintb( + "\177\020" + "f\000\007f\0" + "=\200never\0" + "=\377never\0", + 0xff, + "0xff"); + // new style, two separate bit-fields h_snprintb( "\177\020" @@ -763,6 +774,18 @@ ATF_TC_BODY(snprintb, tc) 0x1122, "0x1122"); + // new style bit-field default, can never match + h_snprintb( + "\177\020" + "f\010\002f\0" + "=\000zero\0" + "=\001one\0" + "=\002two\0" + "=\003three\0" + "*other\0", + 0xff00, + "0xff00"); + // new style bit-field default, invalid conversion specifier // // There is no reliable way to make snprintf return an error, as such
CVS commit: src/tests/lib/libutil
Module Name:src Committed By: rillig Date: Tue Feb 20 21:45:36 UTC 2024 Modified Files: src/tests/lib/libutil: t_snprintb.c Log Message: tests/snprintb: test '=' and '*' directives that can never match To generate a diff of this commit: cvs rdiff -u -r1.24 -r1.25 src/tests/lib/libutil/t_snprintb.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/lib/libutil
Module Name:src Committed By: rillig Date: Tue Feb 20 19:49:10 UTC 2024 Modified Files: src/tests/lib/libutil: t_snprintb.c Log Message: tests/snprintb: fix out-of-bounds memory read (since 2024-02-16) Before t_snprintb.c 1.20, the buffer size was required to be greater than zero. Allowing the buffer size to be zero led to buf[-1] being checked. On amd64, that byte happened to be 0, on i386 it didn't. Fixes PR lib/57951. To generate a diff of this commit: cvs rdiff -u -r1.22 -r1.23 src/tests/lib/libutil/t_snprintb.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/lib/libutil/t_snprintb.c diff -u src/tests/lib/libutil/t_snprintb.c:1.22 src/tests/lib/libutil/t_snprintb.c:1.23 --- src/tests/lib/libutil/t_snprintb.c:1.22 Mon Feb 19 23:30:56 2024 +++ src/tests/lib/libutil/t_snprintb.c Tue Feb 20 19:49:10 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: t_snprintb.c,v 1.22 2024/02/19 23:30:56 rillig Exp $ */ +/* $NetBSD: t_snprintb.c,v 1.23 2024/02/20 19:49:10 rillig Exp $ */ /* * Copyright (c) 2002, 2004, 2008, 2010, 2024 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2008, 2010, 2024\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_snprintb.c,v 1.22 2024/02/19 23:30:56 rillig Exp $"); +__RCSID("$NetBSD: t_snprintb.c,v 1.23 2024/02/20 19:49:10 rillig Exp $"); #include #include @@ -48,9 +48,11 @@ vis_arr(const char *arr, size_t arrsize) static size_t i; i = (i + 1) % (sizeof(buf) / sizeof(buf[0])); - int rv = strnvisx(buf[i], sizeof(buf[i]), arr, arrsize, + buf[i][0] = '"'; + int rv = strnvisx(buf[i] + 1, sizeof(buf[i]) - 2, arr, arrsize, VIS_WHITE | VIS_OCTAL); ATF_REQUIRE_MSG(rv >= 0, "strnvisx failed for size %zu", arrsize); + strcpy(buf[i] + 1 + rv, "\""); return buf[i]; } @@ -95,7 +97,8 @@ h_snprintb_loc(const char *file, size_t ATF_CHECK_MSG( rv == want_rv && memcmp(buf, want_buf, want_bufsize) == 0 - && buf[rlen < bufsize ? rlen : bufsize - 1] == '\0', + && (bufsize < 1 + || buf[rlen < bufsize ? rlen : bufsize - 1] == '\0'), "failed:\n" "\ttest case: %s:%zu\n" "\tformat: %s\n" @@ -1110,7 +1113,12 @@ h_snprintb_m_loc(const char *file, size_ size_t total = rv; ATF_CHECK_MSG( - total == want_rv && memcmp(buf, want_buf, want_bufsize) == 0, + total == want_rv + && memcmp(buf, want_buf, want_bufsize) == 0 + && (bufsize < 1 + || buf[total < bufsize ? total : bufsize - 1] == '\0') + && (bufsize < 2 + || buf[total < bufsize ? total - 1 : bufsize - 2] == '\0'), "failed:\n" "\ttest case: %s:%zu\n" "\tformat: %s\n"
CVS commit: src/tests/lib/libutil
Module Name:src Committed By: rillig Date: Tue Feb 20 19:49:10 UTC 2024 Modified Files: src/tests/lib/libutil: t_snprintb.c Log Message: tests/snprintb: fix out-of-bounds memory read (since 2024-02-16) Before t_snprintb.c 1.20, the buffer size was required to be greater than zero. Allowing the buffer size to be zero led to buf[-1] being checked. On amd64, that byte happened to be 0, on i386 it didn't. Fixes PR lib/57951. To generate a diff of this commit: cvs rdiff -u -r1.22 -r1.23 src/tests/lib/libutil/t_snprintb.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/lib/libutil
Module Name:src Committed By: rillig Date: Mon Feb 19 23:22:03 UTC 2024 Modified Files: src/tests/lib/libutil: t_snprintb.c Log Message: tests/snprintb: add more tests, especially for snprintb_m To generate a diff of this commit: cvs rdiff -u -r1.20 -r1.21 src/tests/lib/libutil/t_snprintb.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/lib/libutil/t_snprintb.c diff -u src/tests/lib/libutil/t_snprintb.c:1.20 src/tests/lib/libutil/t_snprintb.c:1.21 --- src/tests/lib/libutil/t_snprintb.c:1.20 Fri Feb 16 19:53:40 2024 +++ src/tests/lib/libutil/t_snprintb.c Mon Feb 19 23:22:03 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: t_snprintb.c,v 1.20 2024/02/16 19:53:40 rillig Exp $ */ +/* $NetBSD: t_snprintb.c,v 1.21 2024/02/19 23:22:03 rillig Exp $ */ /* * Copyright (c) 2002, 2004, 2008, 2010, 2024 The NetBSD Foundation, Inc. @@ -30,9 +30,9 @@ */ #include -__COPYRIGHT("@(#) Copyright (c) 2008, 2010\ +__COPYRIGHT("@(#) Copyright (c) 2008, 2010, 2024\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_snprintb.c,v 1.20 2024/02/16 19:53:40 rillig Exp $"); +__RCSID("$NetBSD: t_snprintb.c,v 1.21 2024/02/19 23:22:03 rillig Exp $"); #include #include @@ -58,40 +58,43 @@ static void check_unmodified_loc(const char *file, size_t line, const char *arr, size_t begin, size_t end) { - size_t mod_begin = begin, mod_end = end; - while (mod_begin < mod_end && arr[mod_begin] == 'Z') - mod_begin++; - while (mod_begin < mod_end && arr[mod_end - 1] == 'Z') - mod_end--; + while (begin < end && arr[begin] == 'Z') + begin++; + while (begin < end && arr[end - 1] == 'Z') + end--; ATF_CHECK_MSG( - mod_begin == mod_end, + begin == end, "failed:\n" "\ttest case: %s:%zu\n" "\tout-of-bounds write from %zu to %zu: %s\n", file, line, - mod_begin, mod_end, vis_arr(arr + mod_begin, mod_end - mod_begin)); + begin, end, vis_arr(arr + begin, end - begin)); } static void h_snprintb_loc(const char *file, size_t line, -size_t bufsize, const char *fmt, size_t fmtlen, uint64_t val, -int exp_rv, const char *res, size_t reslen) +size_t bufsize, const char *bitfmt, size_t bitfmtlen, uint64_t val, +int want_rv, const char *want_buf, size_t want_bufsize) { char buf[1024]; ATF_REQUIRE(bufsize <= sizeof(buf)); - ATF_REQUIRE(reslen <= sizeof(buf)); + ATF_REQUIRE(want_bufsize <= sizeof(buf)); + if (bitfmtlen > 2 && bitfmt[0] == '\177') + ATF_REQUIRE_MSG(bitfmt[bitfmtlen - 1] == '\0', + "%s:%zu: missing trailing '\\0' in bitfmt", + file, line); + if (bufsize == 0 && want_bufsize == 1) + want_bufsize = 0; memset(buf, 'Z', sizeof(buf)); - int rv = snprintb(buf, bufsize, fmt, val); + int rv = snprintb(buf, bufsize, bitfmt, val); ATF_REQUIRE(rv >= 0); size_t rlen = rv; - if (bufsize == 0 && reslen == 1) - reslen = 0; ATF_CHECK_MSG( - rv == exp_rv - && memcmp(buf, res, reslen) == 0 + rv == want_rv + && memcmp(buf, want_buf, want_bufsize) == 0 && buf[rlen < bufsize ? rlen : bufsize - 1] == '\0', "failed:\n" "\ttest case: %s:%zu\n" @@ -100,28 +103,28 @@ h_snprintb_loc(const char *file, size_t "\twant: %d bytes %s\n" "\thave: %d bytes %s\n", file, line, - vis_arr(fmt, fmtlen), + vis_arr(bitfmt, bitfmtlen), (uintmax_t)val, - exp_rv, vis_arr(res, reslen), - rv, vis_arr(buf, reslen)); - check_unmodified_loc(file, line, buf, reslen, sizeof(buf)); + want_rv, vis_arr(want_buf, want_bufsize), + rv, vis_arr(buf, want_bufsize)); + check_unmodified_loc(file, line, buf, want_bufsize, sizeof(buf)); } -#define h_snprintb_len(bufsize, fmt, val, exp_rv, res) \ +#define h_snprintb_len(bufsize, bitfmt, val, want_rv, want_buf) \ h_snprintb_loc(__FILE__, __LINE__,\ - bufsize, fmt, sizeof(fmt) - 1, val,\ - exp_rv, res, sizeof(res)) -#define h_snprintb(fmt, val, res) \ - h_snprintb_len(1024, fmt, val, sizeof(res) - 1, res) + bufsize, bitfmt, sizeof(bitfmt) - 1, val, \ + want_rv, want_buf, sizeof(want_buf)) +#define h_snprintb(bitfmt, val, want_buf)\ + h_snprintb_len(1024, bitfmt, val, sizeof(want_buf) - 1, want_buf) static void h_snprintb_error_loc(const char *file, size_t line, -const char *fmt, size_t fmtlen) +const char *bitfmt, size_t bitfmtlen) { char buf[1024]; memset(buf, 'Z', sizeof(buf)); - int rv = snprintb(buf, sizeof(buf), fmt, 0); + int rv = snprintb(buf, sizeof(buf), bitfmt, 0); size_t buflen = rv; ATF_REQUIRE(rv >= -1); @@ -131,12 +134,12 @@ h_snprintb_error_loc(const char *file, s "\tformat: %s\n" "\tresult: %zu bytes %s\n", file, line, - vis_arr(fmt, fmtlen), + vis_arr(bitfmt, bitfmtlen), buflen, vis_arr(buf, buflen)); } -#define h_snprintb_error(fmt) \ - h_snprintb_error_loc(__FILE__, __LINE__, fmt, sizeof(fmt) - 1) +#define
CVS commit: src/tests/lib/libutil
Module Name:src Committed By: rillig Date: Mon Feb 19 23:22:03 UTC 2024 Modified Files: src/tests/lib/libutil: t_snprintb.c Log Message: tests/snprintb: add more tests, especially for snprintb_m To generate a diff of this commit: cvs rdiff -u -r1.20 -r1.21 src/tests/lib/libutil/t_snprintb.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/lib/libutil
Module Name:src Committed By: rillig Date: Fri Feb 16 18:13:47 UTC 2024 Modified Files: src/tests/lib/libutil: t_snprintb.c Log Message: tests/snprintb: fix test for 8-bit field value The previous version tested the behavior on a platform with signed 'char' before the portability fix. To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/tests/lib/libutil/t_snprintb.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/lib/libutil
Module Name:src Committed By: rillig Date: Fri Feb 16 18:13:47 UTC 2024 Modified Files: src/tests/lib/libutil: t_snprintb.c Log Message: tests/snprintb: fix test for 8-bit field value The previous version tested the behavior on a platform with signed 'char' before the portability fix. To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/tests/lib/libutil/t_snprintb.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/lib/libutil/t_snprintb.c diff -u src/tests/lib/libutil/t_snprintb.c:1.17 src/tests/lib/libutil/t_snprintb.c:1.18 --- src/tests/lib/libutil/t_snprintb.c:1.17 Fri Feb 16 18:09:16 2024 +++ src/tests/lib/libutil/t_snprintb.c Fri Feb 16 18:13:47 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: t_snprintb.c,v 1.17 2024/02/16 18:09:16 rillig Exp $ */ +/* $NetBSD: t_snprintb.c,v 1.18 2024/02/16 18:13:47 rillig Exp $ */ /* * Copyright (c) 2002, 2004, 2008, 2010, 2024 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2008, 2010\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_snprintb.c,v 1.17 2024/02/16 18:09:16 rillig Exp $"); +__RCSID("$NetBSD: t_snprintb.c,v 1.18 2024/02/16 18:13:47 rillig Exp $"); #include #include @@ -499,7 +499,7 @@ ATF_TC_BODY(snprintb, tc) ":\377all\0" "*other\0", 0xff00, - "0xff00"); + "0xff00"); // new-style format, bit-fields with no match h_snprintb(
CVS commit: src/tests/lib/libutil
Module Name:src Committed By: rillig Date: Fri Feb 16 01:19:53 UTC 2024 Modified Files: src/tests/lib/libutil: t_snprintb.c Log Message: tests/snprintb: clean up existing tests, add more tests Due to the check that any bytes beyond the expected output must be unmodified, there's no need anymore to explicitly write the "ZZZ" at the end of the expected output. While here, remove the redundant trailing "\0". Add more tests to cover possible situations where an out-of-bounds write may have occurred. In some cases, the line length specified in snprintb_m is exceeded. To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/tests/lib/libutil/t_snprintb.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/lib/libutil/t_snprintb.c diff -u src/tests/lib/libutil/t_snprintb.c:1.15 src/tests/lib/libutil/t_snprintb.c:1.16 --- src/tests/lib/libutil/t_snprintb.c:1.15 Thu Feb 15 23:48:51 2024 +++ src/tests/lib/libutil/t_snprintb.c Fri Feb 16 01:19:53 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: t_snprintb.c,v 1.15 2024/02/15 23:48:51 rillig Exp $ */ +/* $NetBSD: t_snprintb.c,v 1.16 2024/02/16 01:19:53 rillig Exp $ */ /* * Copyright (c) 2002, 2004, 2008, 2010, 2024 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2008, 2010\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_snprintb.c,v 1.15 2024/02/15 23:48:51 rillig Exp $"); +__RCSID("$NetBSD: t_snprintb.c,v 1.16 2024/02/16 01:19:53 rillig Exp $"); #include #include @@ -104,13 +104,13 @@ h_snprintb_loc(const char *file, size_t (uintmax_t)val, exp_rv, vis_arr(res, reslen), rv, vis_arr(buf, reslen)); - check_unmodified_loc(file, line, buf, reslen + 1, sizeof(buf)); + check_unmodified_loc(file, line, buf, reslen, sizeof(buf)); } #define h_snprintb_len(bufsize, fmt, val, exp_rv, res) \ h_snprintb_loc(__FILE__, __LINE__,\ bufsize, fmt, sizeof(fmt) - 1, val,\ - exp_rv, res, sizeof(res) - 1) + exp_rv, res, sizeof(res)) #define h_snprintb(fmt, val, res) \ h_snprintb_len(1024, fmt, val, sizeof(res) - 1, res) @@ -250,44 +250,44 @@ ATF_TC_BODY(snprintb, tc) // behavior due to out-of-bounds 'bp' pointer. h_snprintb_len( 0, "\020", 0, - 1, "ZZZ"); + 1, ""); #endif h_snprintb_len( 1, "\020", 0, - 1, "\0ZZZ"); + 1, ""); h_snprintb_len( 2, "\020", 0, - 1, "0\0ZZZ"); + 1, "0"); h_snprintb_len( 3, "\020", 0, - 1, "0\0ZZZ"); + 1, "0"); h_snprintb_len( 3, "\020", 7, - 3, "0x\0ZZZ"); + 3, "0x"); h_snprintb_len( 4, "\020", 7, - 3, "0x7\0ZZZ"); + 3, "0x7"); h_snprintb_len( 7, "\020\001lsb", 7, - 8, "0x7\0ZZZ"); + 8, "0x7"); h_snprintb_len( 9, "\020\001one\002two", 7, - 12, "0x7\0ZZZ"); + 12, "0x7"); // new-style format, single bits, octal h_snprintb( @@ -596,44 +596,44 @@ ATF_TC_BODY(snprintb, tc) // behavior due to out-of-bounds 'bp' pointer. h_snprintb_len( 0, "\177\020", 0, - 1, "ZZZ"); + 1, ""); #endif h_snprintb_len( 1, "\177\020", 0, - 1, "\0ZZZ"); + 1, ""); h_snprintb_len( 2, "\177\020", 0, - 1, "0\0ZZZ"); + 1, "0"); h_snprintb_len( 3, "\177\020", 0, - 1, "0\0ZZZ"); + 1, "0"); h_snprintb_len( 3, "\177\020", 7, - 3, "0x\0ZZZ"); + 3, "0x"); h_snprintb_len( 4, "\177\020", 7, - 3, "0x7\0ZZZ"); + 3, "0x7"); h_snprintb_len( 7, "\177\020b\000lsb\0", 7, - 8, "0x7\0ZZZ"); + 8, "0x7"); h_snprintb_len( 9, "\177\020b\000one\0b\001two\0", 7, - 12, "0x7\0ZZZ"); + 12, "0x7"); } @@ -670,13 +670,13 @@ h_snprintb_m_loc(const char *file, size_ max, exp_rv, vis_arr(res, reslen), total, vis_arr(buf, reslen)); - check_unmodified_loc(file, line, buf, reslen + 1, sizeof(buf)); + check_unmodified_loc(file, line, buf, reslen, sizeof(buf)); } #define h_snprintb_m_len(bufsize, fmt, val, line_max, exp_rv, res) \ h_snprintb_m_loc(__FILE__, __LINE__,\ bufsize, fmt, sizeof(fmt) - 1, val, line_max, \ - exp_rv, res, sizeof(res) - 1) + exp_rv, res, sizeof(res)) #define h_snprintb_m(fmt, val, max, res)\ h_snprintb_m_len(1024, fmt, val, max, sizeof(res) - 1, res) @@ -697,22 +697,14 @@ ATF_TC_BODY(snprintb_m, tc) 0x, 6, 143, - /* 0 */ "0x>\0" - /* 8 */ "0x<>\0" - /* 17 */ "0xb>\0" - /* 26 */ "0xi>\0" - /* 35 */ "0xt>\0" - /* 44 */ "0x1>\0" - /* 53 */ "0x<>\0" - /* 62 */ "0xff\0\0ZZ" - /* 70 */ "ZZ" - /* 80 */ "ZZ" - /* 90 */ "ZZ" - /* 100 */ "ZZ" - /* 110 */ "ZZ" - /* 120 */ "ZZ" - /* 130 */ "ZZ" - /* 140 */ "ZZ" + "0x>\0" + "0x<>\0" +
CVS commit: src/tests/lib/libutil
Module Name:src Committed By: rillig Date: Fri Feb 16 01:19:53 UTC 2024 Modified Files: src/tests/lib/libutil: t_snprintb.c Log Message: tests/snprintb: clean up existing tests, add more tests Due to the check that any bytes beyond the expected output must be unmodified, there's no need anymore to explicitly write the "ZZZ" at the end of the expected output. While here, remove the redundant trailing "\0". Add more tests to cover possible situations where an out-of-bounds write may have occurred. In some cases, the line length specified in snprintb_m is exceeded. To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/tests/lib/libutil/t_snprintb.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/lib/libutil
Module Name:src Committed By: rillig Date: Wed Feb 14 20:51:17 UTC 2024 Modified Files: src/tests/lib/libutil: t_snprintb.c Log Message: tests/libutil/snprintb_m: add tests for small line length To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/tests/lib/libutil/t_snprintb.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/lib/libutil/t_snprintb.c diff -u src/tests/lib/libutil/t_snprintb.c:1.12 src/tests/lib/libutil/t_snprintb.c:1.13 --- src/tests/lib/libutil/t_snprintb.c:1.12 Sat Jan 27 21:42:29 2024 +++ src/tests/lib/libutil/t_snprintb.c Wed Feb 14 20:51:17 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: t_snprintb.c,v 1.12 2024/01/27 21:42:29 rillig Exp $ */ +/* $NetBSD: t_snprintb.c,v 1.13 2024/02/14 20:51:17 rillig Exp $ */ /* * Copyright (c) 2002, 2004, 2008, 2010, 2024 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2008, 2010\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_snprintb.c,v 1.12 2024/01/27 21:42:29 rillig Exp $"); +__RCSID("$NetBSD: t_snprintb.c,v 1.13 2024/02/14 20:51:17 rillig Exp $"); #include #include @@ -573,36 +573,44 @@ ATF_TC_BODY(snprintb, tc) static void h_snprintb_m_loc(const char *file, size_t line, -const char *fmt, size_t fmtlen, uint64_t val, int line_max, -const char *res, size_t reslen) +size_t bufsize, const char *fmt, size_t fmtlen, uint64_t val, size_t max, +size_t exp_rv, const char *res, size_t reslen) { char buf[1024]; - int rv = snprintb_m(buf, sizeof(buf), fmt, val, line_max); + ATF_REQUIRE(bufsize > 1); + ATF_REQUIRE(bufsize <= sizeof(buf)); - ATF_REQUIRE_MSG(rv >= 0, "formatting %jx with '%s' returns error %d", + memset(buf, 'Z', sizeof(buf)); + int rv = snprintb_m(buf, bufsize, fmt, val, max); + ATF_REQUIRE_MSG(rv >= 0, + "formatting %jx with '%s' returns error %d", (uintmax_t)val, vis_arr(fmt, fmtlen), rv); - size_t buflen = rv; + size_t total = rv; ATF_CHECK_MSG( - buflen == reslen && memcmp(buf, res, reslen) == 0, + total == exp_rv && memcmp(buf, res, reslen) == 0, "failed:\n" "\ttest case: %s:%zu\n" "\tformat: %s\n" "\tvalue: %#jx\n" + "\tmax: %zu\n" "\twant: %zu bytes %s\n" "\thave: %zu bytes %s\n", file, line, vis_arr(fmt, fmtlen), (uintmax_t)val, - reslen, vis_arr(res, reslen), - buflen, vis_arr(buf, buflen)); + max, + exp_rv, vis_arr(res, reslen), + total, vis_arr(buf, reslen)); } -#define h_snprintb_m(fmt, val, line_max, res)\ +#define h_snprintb_m_len(bufsize, fmt, val, line_max, exp_rv, res) \ h_snprintb_m_loc(__FILE__, __LINE__,\ - fmt, sizeof(fmt) - 1, val, line_max, \ - res, sizeof(res) - 1) + bufsize, fmt, sizeof(fmt) - 1, val, line_max, \ + exp_rv, res, sizeof(res) - 1) +#define h_snprintb_m(fmt, val, max, res)\ + h_snprintb_m_len(1024, fmt, val, max, sizeof(res) - 1, res) ATF_TC(snprintb_m); ATF_TC_HEAD(snprintb_m, tc) @@ -611,6 +619,68 @@ ATF_TC_HEAD(snprintb_m, tc) } ATF_TC_BODY(snprintb_m, tc) { + // old-style format, small maximum line length + h_snprintb_m_len( + 68, + "\020" + "\001bit1" + "\002bit2" + "\003bit3", + 0x, + 6, + 143, + /* 0 */ "0x>\0" + /* 8 */ "0x<>\0" + /* 17 */ "0xb>\0" + /* 26 */ "0xi>\0" + /* 35 */ "0xt>\0" + /* 44 */ "0x1>\0" + /* 53 */ "0x<>\0" + /* 62 */ "0xff\0" + /* 67 */ "ZZZ" + /* 70 */ "ZZ" + /* 80 */ "ZZ" + /* 90 */ "ZZ" + /* 100 */ "ZZ" + /* 110 */ "ZZ" + /* 116 */ "\0\0" /* FIXME: out-of-bounds write */ + /* 118 */ "ZZ" + /* 120 */ "ZZ" + /* 130 */ "ZZ" + /* 140 */ "ZZ" + ); + + // new-style format, small maximum line length + h_snprintb_m_len( + 68, + "\177\020" + "b\000bit1\0" + "b\001bit2\0" + "b\002bit3\0", + 0x, + 6, + 143, + /* 0 */ "0x>\0" + /* 8 */ "0x<>\0" + /* 17 */ "0xb>\0" + /* 26 */ "0xi>\0" + /* 35 */ "0xt>\0" + /* 44 */ "0x1>\0" + /* 53 */ "0x<>\0" + /* 62 */ "0xff\0" + /* 67 */ "ZZZ" + /* 70 */ "ZZ" + /* 80 */ "ZZ" + /* 90 */ "ZZ" + /* 100 */ "ZZ" + /* 110 */ "ZZ" + /* 116 */ "\0\0" /* FIXME: out-of-bounds write */ + /* 118 */ "ZZ" + /* 120 */ "ZZ" + /* 130 */ "ZZ" + /* 140 */ "ZZ" + ); + h_snprintb_m( "\177\020" "b\0LSB\0"
CVS commit: src/tests/lib/libutil
Module Name:src Committed By: rillig Date: Wed Feb 14 20:51:17 UTC 2024 Modified Files: src/tests/lib/libutil: t_snprintb.c Log Message: tests/libutil/snprintb_m: add tests for small line length To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/tests/lib/libutil/t_snprintb.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/lib/libutil
Module Name:src Committed By: rillig Date: Sat Jan 27 21:42:29 UTC 2024 Modified Files: src/tests/lib/libutil: t_snprintb.c Log Message: tests/libutil/snprintb: remove redundant integer constant suffixes I added these because lint told me so. Lint was wrong though, as it had not implemented the C99 rules for integer constants. To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/tests/lib/libutil/t_snprintb.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/lib/libutil/t_snprintb.c diff -u src/tests/lib/libutil/t_snprintb.c:1.11 src/tests/lib/libutil/t_snprintb.c:1.12 --- src/tests/lib/libutil/t_snprintb.c:1.11 Sat Jan 27 10:32:03 2024 +++ src/tests/lib/libutil/t_snprintb.c Sat Jan 27 21:42:29 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: t_snprintb.c,v 1.11 2024/01/27 10:32:03 rillig Exp $ */ +/* $NetBSD: t_snprintb.c,v 1.12 2024/01/27 21:42:29 rillig Exp $ */ /* * Copyright (c) 2002, 2004, 2008, 2010, 2024 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2008, 2010\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_snprintb.c,v 1.11 2024/01/27 10:32:03 rillig Exp $"); +__RCSID("$NetBSD: t_snprintb.c,v 1.12 2024/01/27 21:42:29 rillig Exp $"); #include #include @@ -161,7 +161,7 @@ ATF_TC_BODY(snprintb, tc) // The old-style format supports only 32 bits, interpreting the // \041 as part of the text belonging to bit 1. "\04133", - 0x00ff0f35ULL, + 0x00ff0f35, "0x00ff0f35<24,6,5,3,1!33>"); // old-style format, hexadecimal, from lsb to msb @@ -181,7 +181,7 @@ ATF_TC_BODY(snprintb, tc) // The old-style format supports only 32 bits, interpreting the // \041 as part of the text belonging to bit 32. "\04133", - 0xff00f0caULL, + 0xff00f0ca, "0xff00f0ca<2,4,7,8,16,32!33>"); // The bits can be listed in arbitrary order, there can also be @@ -208,7 +208,7 @@ ATF_TC_BODY(snprintb, tc) "\020" "\177undefined_behavior" "\001lsb", - 0xULL, + 0x, "0x"); #endif @@ -276,7 +276,7 @@ ATF_TC_BODY(snprintb, tc) "b\037bit31\0" "b\040bit32\0" "b\077bit63\0", - 0xf00ff00fULL, + 0xf00ff00f, "01777600017"); // new-style format, single bits, decimal @@ -286,7 +286,7 @@ ATF_TC_BODY(snprintb, tc) "b\037bit31\0" "b\040bit32\0" "b\077bit63\0", - 0xf00ff00fULL, + 0xf00ff00f, "17293822637553745935"); // new-style format, single bits, hexadecimal @@ -296,7 +296,7 @@ ATF_TC_BODY(snprintb, tc) "b\037bit31\0" "b\040bit32\0" "b\077bit63\0", - 0xf00ff00fULL, + 0xf00ff00f, "0xf00ff00f"); // new-style format, invalid number base 2
CVS commit: src/tests/lib/libutil
Module Name:src Committed By: rillig Date: Sat Jan 27 21:42:29 UTC 2024 Modified Files: src/tests/lib/libutil: t_snprintb.c Log Message: tests/libutil/snprintb: remove redundant integer constant suffixes I added these because lint told me so. Lint was wrong though, as it had not implemented the C99 rules for integer constants. To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/tests/lib/libutil/t_snprintb.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/lib/libutil
Module Name:src Committed By: rillig Date: Sat Jan 27 10:32:03 UTC 2024 Modified Files: src/tests/lib/libutil: t_snprintb.c Log Message: tests/libutil/snprintb: fix test for 32-bit platforms To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/tests/lib/libutil/t_snprintb.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/lib/libutil/t_snprintb.c diff -u src/tests/lib/libutil/t_snprintb.c:1.10 src/tests/lib/libutil/t_snprintb.c:1.11 --- src/tests/lib/libutil/t_snprintb.c:1.10 Sat Jan 27 08:54:15 2024 +++ src/tests/lib/libutil/t_snprintb.c Sat Jan 27 10:32:03 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: t_snprintb.c,v 1.10 2024/01/27 08:54:15 rillig Exp $ */ +/* $NetBSD: t_snprintb.c,v 1.11 2024/01/27 10:32:03 rillig Exp $ */ /* * Copyright (c) 2002, 2004, 2008, 2010, 2024 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2008, 2010\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_snprintb.c,v 1.10 2024/01/27 08:54:15 rillig Exp $"); +__RCSID("$NetBSD: t_snprintb.c,v 1.11 2024/01/27 10:32:03 rillig Exp $"); #include #include @@ -81,7 +81,8 @@ h_snprintb_loc(const char *file, size_t "\twant: %d bytes %s\n" "\thave: %d bytes %s\n", file, line, - vis_arr(fmt, fmtlen), (uintmax_t)val, + vis_arr(fmt, fmtlen), + (uintmax_t)val, exp_rv, vis_arr(res, reslen), rv, vis_arr(buf, reslen)); } @@ -180,7 +181,7 @@ ATF_TC_BODY(snprintb, tc) // The old-style format supports only 32 bits, interpreting the // \041 as part of the text belonging to bit 32. "\04133", - 0xff00f0ca, + 0xff00f0caULL, "0xff00f0ca<2,4,7,8,16,32!33>"); // The bits can be listed in arbitrary order, there can also be @@ -207,7 +208,7 @@ ATF_TC_BODY(snprintb, tc) "\020" "\177undefined_behavior" "\001lsb", - 0x, + 0xULL, "0x"); #endif @@ -592,7 +593,8 @@ h_snprintb_m_loc(const char *file, size_ "\twant: %zu bytes %s\n" "\thave: %zu bytes %s\n", file, line, - vis_arr(fmt, fmtlen), (uintmax_t)val, + vis_arr(fmt, fmtlen), + (uintmax_t)val, reslen, vis_arr(res, reslen), buflen, vis_arr(buf, buflen)); }
CVS commit: src/tests/lib/libutil
Module Name:src Committed By: rillig Date: Sat Jan 27 10:32:03 UTC 2024 Modified Files: src/tests/lib/libutil: t_snprintb.c Log Message: tests/libutil/snprintb: fix test for 32-bit platforms To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/tests/lib/libutil/t_snprintb.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/lib/libutil
Module Name:src Committed By: rillig Date: Sat Jan 27 08:54:15 UTC 2024 Modified Files: src/tests/lib/libutil: t_snprintb.c Log Message: tests/libutil/snprintb: add more tests Test all number bases (octal, decimal, hexadecimal), in both old-style and new-style formats, as well as small buffer sizes. Document working edge cases such as empty descriptions or descriptions containing spaces, as well as situations that invoke undefined behavior. Add comments to the individual test cases, as reading the actual format strings takes more time. To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/tests/lib/libutil/t_snprintb.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/lib/libutil/t_snprintb.c diff -u src/tests/lib/libutil/t_snprintb.c:1.9 src/tests/lib/libutil/t_snprintb.c:1.10 --- src/tests/lib/libutil/t_snprintb.c:1.9 Thu Jan 25 18:13:14 2024 +++ src/tests/lib/libutil/t_snprintb.c Sat Jan 27 08:54:15 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: t_snprintb.c,v 1.9 2024/01/25 18:13:14 rillig Exp $ */ +/* $NetBSD: t_snprintb.c,v 1.10 2024/01/27 08:54:15 rillig Exp $ */ /* * Copyright (c) 2002, 2004, 2008, 2010, 2024 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2008, 2010\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_snprintb.c,v 1.9 2024/01/25 18:13:14 rillig Exp $"); +__RCSID("$NetBSD: t_snprintb.c,v 1.10 2024/01/27 08:54:15 rillig Exp $"); #include #include @@ -42,47 +42,80 @@ __RCSID("$NetBSD: t_snprintb.c,v 1.9 202 #include static const char * -vis_fmt(const char *fmt, size_t fmtlen) +vis_arr(const char *arr, size_t arrlen) { - static char buf[4][1024]; + static char buf[6][1024]; static size_t i; - i = (i + 1) % 4; - ATF_REQUIRE_MSG( - strnvisx(buf[i], sizeof(buf[i]), fmt, fmtlen, VIS_WHITE | VIS_OCTAL) >= 0, - "strnvisx failed for length %zu", fmtlen); + i = (i + 1) % (sizeof(buf) / sizeof(buf[0])); + int rv = strnvisx(buf[i], sizeof(buf[i]), arr, arrlen, + VIS_WHITE | VIS_OCTAL); + ATF_REQUIRE_MSG(rv >= 0, "strnvisx failed for length %zu", arrlen); return buf[i]; } static void -h_snprintb(const char *file, size_t line, const char *fmt, size_t fmtlen, uint64_t val, -const char *res, size_t reslen) +h_snprintb_loc(const char *file, size_t line, +size_t bufsize, const char *fmt, size_t fmtlen, uint64_t val, +int exp_rv, const char *res, size_t reslen) { char buf[1024]; - int rv = snprintb(buf, sizeof(buf), fmt, val); - - ATF_REQUIRE_MSG(rv > 0, "formatting %jx with '%s' returns error %d", - (uintmax_t)val, vis_fmt(fmt, fmtlen), rv); + // Calling snprintb with bufsize == 0 invokes undefined + // behavior due to out-of-range 'bp'. + ATF_REQUIRE(bufsize > 0); + ATF_REQUIRE(bufsize <= sizeof(buf)); + + memset(buf, 'Z', sizeof(buf)); + int rv = snprintb(buf, bufsize, fmt, val); + ATF_REQUIRE(rv >= 0); + size_t rlen = rv; - size_t buflen = rv; ATF_CHECK_MSG( - buflen == reslen && memcmp(buf, res, reslen) == 0, + rv == exp_rv && memcmp(buf, res, reslen) == 0 + && buf[rlen < bufsize ? rlen : bufsize - 1] == '\0', "failed:\n" "\ttest case: %s:%zu\n" "\tformat: %s\n" "\tvalue: %#jx\n" - "\twant: %3zu bytes %s\n" - "\thave: %3zu bytes %s\n", + "\twant: %d bytes %s\n" + "\thave: %d bytes %s\n", file, line, - vis_fmt(fmt, fmtlen), (uintmax_t)val, - reslen, vis_fmt(res, reslen), - buflen, vis_fmt(buf, buflen)); + vis_arr(fmt, fmtlen), (uintmax_t)val, + exp_rv, vis_arr(res, reslen), + rv, vis_arr(buf, reslen)); } +#define h_snprintb_len(bufsize, fmt, val, exp_rv, res) \ + h_snprintb_loc(__FILE__, __LINE__,\ + bufsize, fmt, sizeof(fmt) - 1, val,\ + exp_rv, res, sizeof(res) - 1) #define h_snprintb(fmt, val, res) \ - h_snprintb(__FILE__, __LINE__, fmt, sizeof(fmt) - 1, \ - val, res, sizeof(res) - 1) + h_snprintb_len(1024, fmt, val, sizeof(res) - 1, res) + +static void +h_snprintb_error_loc(const char *file, size_t line, +const char *fmt, size_t fmtlen) +{ + char buf[1024]; + + memset(buf, 'Z', sizeof(buf)); + int rv = snprintb(buf, sizeof(buf), fmt, 0); + size_t buflen = rv; + + ATF_REQUIRE(rv >= -1); + ATF_CHECK_MSG(rv == -1, + "expected error but got success:\n" + "\ttest case: %s:%zu\n" + "\tformat: %s\n" + "\tresult: %zu bytes %s\n", + file, line, + vis_arr(fmt, fmtlen), + buflen, vis_arr(buf, buflen)); +} + +#define h_snprintb_error(fmt) \ + h_snprintb_error_loc(__FILE__, __LINE__, fmt, sizeof(fmt) - 1) ATF_TC(snprintb); ATF_TC_HEAD(snprintb, tc) @@ -91,6 +124,8 @@ ATF_TC_HEAD(snprintb, tc) } ATF_TC_BODY(snprintb, tc) { + + // old-style format, octal h_snprintb( "\010" "\002BITTWO" @@ -98,14 +133,189 @@ ATF_TC_BODY(snprintb, tc) 3, "03"); + // old-style format, decimal
CVS commit: src/tests/lib/libutil
Module Name:src Committed By: rillig Date: Sat Jan 27 08:54:15 UTC 2024 Modified Files: src/tests/lib/libutil: t_snprintb.c Log Message: tests/libutil/snprintb: add more tests Test all number bases (octal, decimal, hexadecimal), in both old-style and new-style formats, as well as small buffer sizes. Document working edge cases such as empty descriptions or descriptions containing spaces, as well as situations that invoke undefined behavior. Add comments to the individual test cases, as reading the actual format strings takes more time. To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/tests/lib/libutil/t_snprintb.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/lib/libutil
Module Name:src Committed By: rillig Date: Thu Jan 25 18:13:14 UTC 2024 Modified Files: src/tests/lib/libutil: t_snprintb.c Log Message: tests/libutil/snprintb: clean up and extend tests In case of a failure, print the details of the test case, including file and line number of the actual test data. Do not write the format strings directly to the output, as they contain non-printable bytes and embedded null bytes. After a failed test case, continue with the others. Lay out the format strings according to their structure, to make them more readable. Remove redundant "\0" at the end of the new-style format strings. Fix an off-by-one error in the test data: 0xf is FIFTEEN, not SIXTEEN. Add a test for performing a restricted subset of rot13 in the format string, to explore the limits of snprintb formatting. What's still missing are tests for edge cases and error cases. To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/tests/lib/libutil/t_snprintb.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/lib/libutil/t_snprintb.c diff -u src/tests/lib/libutil/t_snprintb.c:1.8 src/tests/lib/libutil/t_snprintb.c:1.9 --- src/tests/lib/libutil/t_snprintb.c:1.8 Sun Dec 8 17:37:16 2019 +++ src/tests/lib/libutil/t_snprintb.c Thu Jan 25 18:13:14 2024 @@ -1,10 +1,11 @@ -/* $NetBSD: t_snprintb.c,v 1.8 2019/12/08 17:37:16 christos Exp $ */ +/* $NetBSD: t_snprintb.c,v 1.9 2024/01/25 18:13:14 rillig Exp $ */ /* - * Copyright (c) 2002, 2004, 2008, 2010 The NetBSD Foundation, Inc. + * Copyright (c) 2002, 2004, 2008, 2010, 2024 The NetBSD Foundation, Inc. * All rights reserved. * - * This code was contributed to The NetBSD Foundation by Christos Zoulas. + * This code was contributed to The NetBSD Foundation by Christos Zoulas and + * Roland Illig. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -31,27 +32,58 @@ #include __COPYRIGHT("@(#) Copyright (c) 2008, 2010\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_snprintb.c,v 1.8 2019/12/08 17:37:16 christos Exp $"); +__RCSID("$NetBSD: t_snprintb.c,v 1.9 2024/01/25 18:13:14 rillig Exp $"); +#include #include #include +#include #include +static const char * +vis_fmt(const char *fmt, size_t fmtlen) +{ + static char buf[4][1024]; + static size_t i; + + i = (i + 1) % 4; + ATF_REQUIRE_MSG( + strnvisx(buf[i], sizeof(buf[i]), fmt, fmtlen, VIS_WHITE | VIS_OCTAL) >= 0, + "strnvisx failed for length %zu", fmtlen); + return buf[i]; +} + static void -h_snprintb(const char *fmt, uint64_t val, const char *expected) +h_snprintb(const char *file, size_t line, const char *fmt, size_t fmtlen, uint64_t val, +const char *res, size_t reslen) { - char actual[1024]; - int len, rlen; + char buf[1024]; + + int rv = snprintb(buf, sizeof(buf), fmt, val); - len = snprintb(actual, sizeof(actual), fmt, val); - rlen = (int)strlen(actual); + ATF_REQUIRE_MSG(rv > 0, "formatting %jx with '%s' returns error %d", + (uintmax_t)val, vis_fmt(fmt, fmtlen), rv); - ATF_REQUIRE_STREQ_MSG(expected, actual, "format=%s val=%" PRIu64, - fmt, val); - ATF_REQUIRE_EQ_MSG(rlen, len, "expected=%d actual=%d", rlen, len); + size_t buflen = rv; + ATF_CHECK_MSG( + buflen == reslen && memcmp(buf, res, reslen) == 0, + "failed:\n" + "\ttest case: %s:%zu\n" + "\tformat: %s\n" + "\tvalue: %#jx\n" + "\twant: %3zu bytes %s\n" + "\thave: %3zu bytes %s\n", + file, line, + vis_fmt(fmt, fmtlen), (uintmax_t)val, + reslen, vis_fmt(res, reslen), + buflen, vis_fmt(buf, buflen)); } +#define h_snprintb(fmt, val, res) \ + h_snprintb(__FILE__, __LINE__, fmt, sizeof(fmt) - 1, \ + val, res, sizeof(res) - 1) + ATF_TC(snprintb); ATF_TC_HEAD(snprintb, tc) { @@ -59,72 +91,190 @@ ATF_TC_HEAD(snprintb, tc) } ATF_TC_BODY(snprintb, tc) { - h_snprintb("\10\2BITTWO\1BITONE", 3, "03"); - h_snprintb("\177\20b\0A\0\0", 0, "0"); - - h_snprintb("\177\20b\05NOTBOOT\0b\06FPP\0b\013SDVMA\0b\015VIDEO\0" - "b\020LORES\0b\021FPA\0b\022DIAG\0b\016CACHE\0" - "b\017IOCACHE\0b\022LOOPBACK\0b\04DBGCACHE\0", - 0xe860, "0xe860"); - - h_snprintb("\177\20f\0\4FOO\0=\1ONE\0=\2TWO\0\0", 1, + h_snprintb( + "\010" + "\002BITTWO" + "\001BITONE", + 3, + "03"); + + h_snprintb( + "\177\20" + "b\0A\0", + 0, + "0"); + + h_snprintb( + "\177\020" + "b\05NOTBOOT\0" + "b\06FPP\0" + "b\13SDVMA\0" + "b\15VIDEO\0" + "b\20LORES\0" + "b\21FPA\0" + "b\22DIAG\0" + "b\16CACHE\0" + "b\17IOCACHE\0" + "b\22LOOPBACK\0" + "b\04DBGCACHE\0", + 0xe860, + "0xe860"); + + h_snprintb( + "\177\20" + "f\0\4FOO\0" + "=\1ONE\0" + "=\2TWO\0", + 1, "0x1"); - h_snprintb("\177\20f\0\4X\0=\1ONE\0=\2TWO\0\0", 1, + h_snprintb( + "\177\20"
CVS commit: src/tests/lib/libutil
Module Name:src Committed By: rillig Date: Thu Jan 25 18:13:14 UTC 2024 Modified Files: src/tests/lib/libutil: t_snprintb.c Log Message: tests/libutil/snprintb: clean up and extend tests In case of a failure, print the details of the test case, including file and line number of the actual test data. Do not write the format strings directly to the output, as they contain non-printable bytes and embedded null bytes. After a failed test case, continue with the others. Lay out the format strings according to their structure, to make them more readable. Remove redundant "\0" at the end of the new-style format strings. Fix an off-by-one error in the test data: 0xf is FIFTEEN, not SIXTEEN. Add a test for performing a restricted subset of rot13 in the format string, to explore the limits of snprintb formatting. What's still missing are tests for edge cases and error cases. To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/tests/lib/libutil/t_snprintb.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/lib/libutil
Module Name:src Committed By: msaitoh Date: Mon Nov 7 08:34:31 UTC 2022 Modified Files: src/tests/lib/libutil: t_sockaddr_snprintf.c Log Message: Sync with if_dl.h rev. 1.31's change. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libutil/t_sockaddr_snprintf.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/lib/libutil
Module Name:src Committed By: msaitoh Date: Mon Nov 7 08:34:31 UTC 2022 Modified Files: src/tests/lib/libutil: t_sockaddr_snprintf.c Log Message: Sync with if_dl.h rev. 1.31's change. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libutil/t_sockaddr_snprintf.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/lib/libutil/t_sockaddr_snprintf.c diff -u src/tests/lib/libutil/t_sockaddr_snprintf.c:1.3 src/tests/lib/libutil/t_sockaddr_snprintf.c:1.4 --- src/tests/lib/libutil/t_sockaddr_snprintf.c:1.3 Thu Oct 27 12:59:59 2022 +++ src/tests/lib/libutil/t_sockaddr_snprintf.c Mon Nov 7 08:34:30 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: t_sockaddr_snprintf.c,v 1.3 2022/10/27 12:59:59 msaitoh Exp $ */ +/* $NetBSD: t_sockaddr_snprintf.c,v 1.4 2022/11/07 08:34:30 msaitoh Exp $ */ /* * Copyright (c) 2002, 2004, 2008, 2010 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2008, 2010\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_sockaddr_snprintf.c,v 1.3 2022/10/27 12:59:59 msaitoh Exp $"); +__RCSID("$NetBSD: t_sockaddr_snprintf.c,v 1.4 2022/11/07 08:34:30 msaitoh Exp $"); #include /* AF_ */ #include /* sun */ @@ -169,7 +169,7 @@ ATF_TC_BODY(sockaddr_snprintf_dl, tc) (struct sockaddr *)); ATF_REQUIRE_EQ_MSG(i, 17, "bad length for sdl"); - ATF_REQUIRE_STREQ(buf, "18 20 1.2.3.4.5.6"); + ATF_REQUIRE_STREQ(buf, "18 32 1.2.3.4.5.6"); } ATF_TP_ADD_TCS(tp)
CVS commit: src/tests/lib/libutil
Module Name:src Committed By: msaitoh Date: Thu Oct 27 12:59:59 UTC 2022 Modified Files: src/tests/lib/libutil: t_sockaddr_snprintf.c Log Message: Revert for if_dl.h's change. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libutil/t_sockaddr_snprintf.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/lib/libutil
Module Name:src Committed By: msaitoh Date: Thu Oct 27 12:59:59 UTC 2022 Modified Files: src/tests/lib/libutil: t_sockaddr_snprintf.c Log Message: Revert for if_dl.h's change. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libutil/t_sockaddr_snprintf.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/lib/libutil/t_sockaddr_snprintf.c diff -u src/tests/lib/libutil/t_sockaddr_snprintf.c:1.2 src/tests/lib/libutil/t_sockaddr_snprintf.c:1.3 --- src/tests/lib/libutil/t_sockaddr_snprintf.c:1.2 Mon Oct 24 13:42:55 2022 +++ src/tests/lib/libutil/t_sockaddr_snprintf.c Thu Oct 27 12:59:59 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: t_sockaddr_snprintf.c,v 1.2 2022/10/24 13:42:55 msaitoh Exp $ */ +/* $NetBSD: t_sockaddr_snprintf.c,v 1.3 2022/10/27 12:59:59 msaitoh Exp $ */ /* * Copyright (c) 2002, 2004, 2008, 2010 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2008, 2010\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_sockaddr_snprintf.c,v 1.2 2022/10/24 13:42:55 msaitoh Exp $"); +__RCSID("$NetBSD: t_sockaddr_snprintf.c,v 1.3 2022/10/27 12:59:59 msaitoh Exp $"); #include /* AF_ */ #include /* sun */ @@ -169,7 +169,7 @@ ATF_TC_BODY(sockaddr_snprintf_dl, tc) (struct sockaddr *)); ATF_REQUIRE_EQ_MSG(i, 17, "bad length for sdl"); - ATF_REQUIRE_STREQ(buf, "18 32 1.2.3.4.5.6"); + ATF_REQUIRE_STREQ(buf, "18 20 1.2.3.4.5.6"); } ATF_TP_ADD_TCS(tp)
CVS commit: src/tests/lib/libutil
Module Name:src Committed By: msaitoh Date: Mon Oct 24 13:42:55 UTC 2022 Modified Files: src/tests/lib/libutil: t_sockaddr_snprintf.c Log Message: Sync with if_dl.h rev. 1.29's change. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libutil/t_sockaddr_snprintf.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/lib/libutil/t_sockaddr_snprintf.c diff -u src/tests/lib/libutil/t_sockaddr_snprintf.c:1.1 src/tests/lib/libutil/t_sockaddr_snprintf.c:1.2 --- src/tests/lib/libutil/t_sockaddr_snprintf.c:1.1 Fri Jul 16 13:56:32 2010 +++ src/tests/lib/libutil/t_sockaddr_snprintf.c Mon Oct 24 13:42:55 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: t_sockaddr_snprintf.c,v 1.1 2010/07/16 13:56:32 jmmv Exp $ */ +/* $NetBSD: t_sockaddr_snprintf.c,v 1.2 2022/10/24 13:42:55 msaitoh Exp $ */ /* * Copyright (c) 2002, 2004, 2008, 2010 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2008, 2010\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_sockaddr_snprintf.c,v 1.1 2010/07/16 13:56:32 jmmv Exp $"); +__RCSID("$NetBSD: t_sockaddr_snprintf.c,v 1.2 2022/10/24 13:42:55 msaitoh Exp $"); #include /* AF_ */ #include /* sun */ @@ -169,7 +169,7 @@ ATF_TC_BODY(sockaddr_snprintf_dl, tc) (struct sockaddr *)); ATF_REQUIRE_EQ_MSG(i, 17, "bad length for sdl"); - ATF_REQUIRE_STREQ(buf, "18 20 1.2.3.4.5.6"); + ATF_REQUIRE_STREQ(buf, "18 32 1.2.3.4.5.6"); } ATF_TP_ADD_TCS(tp)
CVS commit: src/tests/lib/libutil
Module Name:src Committed By: msaitoh Date: Mon Oct 24 13:42:55 UTC 2022 Modified Files: src/tests/lib/libutil: t_sockaddr_snprintf.c Log Message: Sync with if_dl.h rev. 1.29's change. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libutil/t_sockaddr_snprintf.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/lib/libutil
Module Name:src Committed By: christos Date: Mon May 2 19:57:50 UTC 2022 Modified Files: src/tests/lib/libutil: t_parsedate.c Log Message: explicitly set TZ=UTC so that we don't depend on the testing rig for it. To generate a diff of this commit: cvs rdiff -u -r1.32 -r1.33 src/tests/lib/libutil/t_parsedate.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/lib/libutil/t_parsedate.c diff -u src/tests/lib/libutil/t_parsedate.c:1.32 src/tests/lib/libutil/t_parsedate.c:1.33 --- src/tests/lib/libutil/t_parsedate.c:1.32 Sat Apr 23 09:08:49 2022 +++ src/tests/lib/libutil/t_parsedate.c Mon May 2 15:57:50 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: t_parsedate.c,v 1.32 2022/04/23 13:08:49 christos Exp $ */ +/* $NetBSD: t_parsedate.c,v 1.33 2022/05/02 19:57:50 christos Exp $ */ /*- * Copyright (c) 2010, 2015 The NetBSD Foundation, Inc. * All rights reserved. @@ -29,7 +29,7 @@ */ #include -__RCSID("$NetBSD: t_parsedate.c,v 1.32 2022/04/23 13:08:49 christos Exp $"); +__RCSID("$NetBSD: t_parsedate.c,v 1.33 2022/05/02 19:57:50 christos Exp $"); #include #include @@ -620,7 +620,8 @@ ATF_TC_BODY(gibberish, tc) ATF_TP_ADD_TCS(tp) { - unsetenv("TZ"); + setenv("TZ", "UTC", 1); + tzset(); ATF_TP_ADD_TC(tp, dates); ATF_TP_ADD_TC(tp, times); ATF_TP_ADD_TC(tp, dsttimes);
CVS commit: src/tests/lib/libutil
Module Name:src Committed By: christos Date: Mon May 2 19:57:50 UTC 2022 Modified Files: src/tests/lib/libutil: t_parsedate.c Log Message: explicitly set TZ=UTC so that we don't depend on the testing rig for it. To generate a diff of this commit: cvs rdiff -u -r1.32 -r1.33 src/tests/lib/libutil/t_parsedate.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/lib/libutil
Module Name:src Committed By: christos Date: Sat Apr 23 13:08:49 UTC 2022 Modified Files: src/tests/lib/libutil: t_parsedate.c Log Message: 1. add check for December in MM/DD/ 2. unsetenv("TZ") since tests assume UTC (all relative tests and one date test fail otherwise) To generate a diff of this commit: cvs rdiff -u -r1.31 -r1.32 src/tests/lib/libutil/t_parsedate.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/lib/libutil/t_parsedate.c diff -u src/tests/lib/libutil/t_parsedate.c:1.31 src/tests/lib/libutil/t_parsedate.c:1.32 --- src/tests/lib/libutil/t_parsedate.c:1.31 Mon Oct 19 11:06:49 2020 +++ src/tests/lib/libutil/t_parsedate.c Sat Apr 23 09:08:49 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: t_parsedate.c,v 1.31 2020/10/19 15:06:49 kre Exp $ */ +/* $NetBSD: t_parsedate.c,v 1.32 2022/04/23 13:08:49 christos Exp $ */ /*- * Copyright (c) 2010, 2015 The NetBSD Foundation, Inc. * All rights reserved. @@ -29,7 +29,7 @@ */ #include -__RCSID("$NetBSD: t_parsedate.c,v 1.31 2020/10/19 15:06:49 kre Exp $"); +__RCSID("$NetBSD: t_parsedate.c,v 1.32 2022/04/23 13:08:49 christos Exp $"); #include #include @@ -137,6 +137,8 @@ ATF_TC_BODY(dates, tc) 2006, 11, 17, 0, 0, 0); parsecheck("10/1/2000", NULL, NULL, localtime_r, 2000, 10, 1, 0, 0, 0); /* month/day/year */ + parsecheck("12/01/2022", NULL, NULL, localtime_r, + 2022, 12, 1, 0, 0, 0); /* month/day/year, December */ parsecheck("20 Jun 1994", NULL, NULL, localtime_r, 1994, 6, 20, 0, 0, 0); parsecheck("97 September 2", NULL, NULL, localtime_r, @@ -618,6 +620,7 @@ ATF_TC_BODY(gibberish, tc) ATF_TP_ADD_TCS(tp) { + unsetenv("TZ"); ATF_TP_ADD_TC(tp, dates); ATF_TP_ADD_TC(tp, times); ATF_TP_ADD_TC(tp, dsttimes);
CVS commit: src/tests/lib/libutil
Module Name:src Committed By: christos Date: Sat Apr 23 13:08:49 UTC 2022 Modified Files: src/tests/lib/libutil: t_parsedate.c Log Message: 1. add check for December in MM/DD/ 2. unsetenv("TZ") since tests assume UTC (all relative tests and one date test fail otherwise) To generate a diff of this commit: cvs rdiff -u -r1.31 -r1.32 src/tests/lib/libutil/t_parsedate.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Re: CVS commit: src/tests/lib/libutil
"David A. Holland"writes: > Module Name: src > Committed By: dholland > Date: Thu Dec 31 10:18:00 UTC 2015 > > Modified Files: > src/tests/lib/libutil: t_parsedate.c > > Log Message: > When evaluated on a Sunday, "next Sunday" means 7 days in the future, > not 14. When evaluated on a Monday, it apparently means 13 days in the > future. There's not exactly a spec for parsedate.y, so conform to the > implementation. > > PR 50574. > > XXX: to me at least this is an odd notion of "next Sunday", but whatever... It's clearly a bug. On a Monday, "next Sunday" is 6 days away. "Sunday week" is 13. So perhaps the test should be correct, and the implementation fixed. signature.asc Description: PGP signature
Re: CVS commit: src/tests/lib/libutil
On Thu, Dec 31, 2015 at 04:14:52PM -0500, Greg Troxel wrote: > > When evaluated on a Sunday, "next Sunday" means 7 days in the future, > > not 14. When evaluated on a Monday, it apparently means 13 days in the > > future. There's not exactly a spec for parsedate.y, so conform to the > > implementation. > > > > PR 50574. > > > > XXX: to me at least this is an odd notion of "next Sunday", but > > whatever... > > It's clearly a bug. > > On a Monday, "next Sunday" is 6 days away. "Sunday week" is 13. > > So perhaps the test should be correct, and the implementation fixed. Well, it treats "this Sunday" as 6 days away. It apparently thinks "this X" is in the next seven days and "next X" is the week past that. That is not entirely crazy, though it's not really consistent with the conventional usage I know... but that usage isn't well defined. On Monday, "this Sunday" and "next Sunday" are pretty clearly the same day; but on Saturday, they probably aren't, and it's not clear what the crossover is. Meanwhile, these usages are regional. I've never understood the "next Sunday week" or "this Sunday week" business no matter how many times I run across it in lit from across the pond. Anyhow, if you care, I suggest writing a spec for parsedate }:-) -- David A. Holland dholl...@netbsd.org