summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorkre <kre@NetBSD.org>2019-04-29 07:55:38 +0000
committerkre <kre@NetBSD.org>2019-04-29 07:55:38 +0000
commit723c68f0c5fedc14eac189797d42c306c445a784 (patch)
treea2346b7cedb1f5482ec825fa1a9f14c682a5ee43 /common
parent053d3ccec05ac9b824ba19c1f5a3a64cd1259953 (diff)
snprintb(3) says that, in the new(?) Torek format, all fields specs end with \0
The F spec is one of those, it should be terminated with \0 just like all the others (irrelevant that it has no extra data to delimit). Fix <sys/mman.h> to define the snprintb() format string correctly (include the missing \0's). Fix the copy of that definition included into snprintb(3) to match the updated mman.h version (ride the date bump from the day before yesterday .. this is the same change, just corrected). Undo the previous snprintb.c change ("off by one" fix) which was an attempt to make the broken mman.h usage work (and did, but not the way it should be done). Also, after using the new * format (instead of only when something has already matched) skip the associated data so we don't attempt to interpret it as more field specifiers. This func needs lots of TLC! Fix the ATF tests for snprintb() to not assume that F format is really exactly like f format, and has data after the field specifier. It doesn't. Add several more tests (including testing the '*' field operator recently added).
Diffstat (limited to 'common')
-rw-r--r--common/lib/libutil/snprintb.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/common/lib/libutil/snprintb.c b/common/lib/libutil/snprintb.c
index be2f6f20604..337337c931b 100644
--- a/common/lib/libutil/snprintb.c
+++ b/common/lib/libutil/snprintb.c
@@ -1,4 +1,4 @@
-/* $NetBSD: snprintb.c,v 1.19 2019/04/27 17:45:28 christos Exp $ */
+/* $NetBSD: snprintb.c,v 1.20 2019/04/29 07:55:38 kre Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -41,7 +41,7 @@
# include <sys/cdefs.h>
# if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: snprintb.c,v 1.19 2019/04/27 17:45:28 christos Exp $");
+__RCSID("$NetBSD: snprintb.c,v 1.20 2019/04/29 07:55:38 kre Exp $");
# endif
# include <sys/types.h>
@@ -51,7 +51,7 @@ __RCSID("$NetBSD: snprintb.c,v 1.19 2019/04/27 17:45:28 christos Exp $");
# include <errno.h>
# else /* ! _KERNEL */
# include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: snprintb.c,v 1.19 2019/04/27 17:45:28 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: snprintb.c,v 1.20 2019/04/29 07:55:38 kre Exp $");
# include <sys/param.h>
# include <sys/inttypes.h>
# include <sys/systm.h>
@@ -226,8 +226,12 @@ snprintb_m(char *buf, size_t buflen, const char *bitfmt, uint64_t val,
PUTSEP;
if (restart == 0)
sep = ',';
- if (ch == 'F') /* just extract */
+ if (ch == 'F') { /* just extract */
+ /* duplicate PUTS() effect on bitfmt */
+ while (*bitfmt++ != '\0')
+ continue;
break;
+ }
if (restart == 0)
PUTS(bitfmt);
if (restart == 0)
@@ -258,7 +262,6 @@ snprintb_m(char *buf, size_t buflen, const char *bitfmt, uint64_t val,
if (!matched) {
matched = 1;
FMTSTR(bitfmt, field);
- break;
}
/*FALLTHROUGH*/
default: