Module Name: src Committed By: kre Date: Mon Apr 29 07:55:38 UTC 2019
Modified Files: src/common/lib/libutil: snprintb.c src/lib/libutil: snprintb.3 src/sys/sys: mman.h src/tests/lib/libutil: t_snprintb.c Log Message: 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). To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/common/lib/libutil/snprintb.c cvs rdiff -u -r1.20 -r1.21 src/lib/libutil/snprintb.3 cvs rdiff -u -r1.58 -r1.59 src/sys/sys/mman.h cvs rdiff -u -r1.5 -r1.6 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/common/lib/libutil/snprintb.c diff -u src/common/lib/libutil/snprintb.c:1.19 src/common/lib/libutil/snprintb.c:1.20 --- src/common/lib/libutil/snprintb.c:1.19 Sat Apr 27 17:45:28 2019 +++ src/common/lib/libutil/snprintb.c Mon Apr 29 07:55:38 2019 @@ -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 # 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, con 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, con if (!matched) { matched = 1; FMTSTR(bitfmt, field); - break; } /*FALLTHROUGH*/ default: Index: src/lib/libutil/snprintb.3 diff -u src/lib/libutil/snprintb.3:1.20 src/lib/libutil/snprintb.3:1.21 --- src/lib/libutil/snprintb.3:1.20 Sat Apr 27 17:58:51 2019 +++ src/lib/libutil/snprintb.3 Mon Apr 29 07:55:38 2019 @@ -1,4 +1,4 @@ -.\" $NetBSD: snprintb.3,v 1.20 2019/04/27 17:58:51 wiz Exp $ +.\" $NetBSD: snprintb.3,v 1.21 2019/04/29 07:55:38 kre Exp $ .\" .\" Copyright (c) 1998 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -280,11 +280,11 @@ b\e7INHERIT\e0\e b\e11HASSEMAPHORE\e0\e b\e12TRYFIXED\e0\e b\e13WIRED\e0\e -F\e14\e1\e +F\e14\e1\e0\e :\e0FILE\e0\e :\e1ANONYMOUS\e0\e b\e15STACK\e0\e -F\e30\e010\e +F\e30\e010\e0\e :\e000ALIGN=NONE\e0\e :\e012ALIGN=1KB\e0\e :\e013ALIGN=2KB\e0\e Index: src/sys/sys/mman.h diff -u src/sys/sys/mman.h:1.58 src/sys/sys/mman.h:1.59 --- src/sys/sys/mman.h:1.58 Sat Apr 27 17:53:26 2019 +++ src/sys/sys/mman.h Mon Apr 29 07:55:38 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: mman.h,v 1.58 2019/04/27 17:53:26 christos Exp $ */ +/* $NetBSD: mman.h,v 1.59 2019/04/29 07:55:38 kre Exp $ */ /*- * Copyright (c) 1982, 1986, 1993 @@ -128,11 +128,11 @@ b\7INHERIT\0\ b\11HASSEMAPHORE\0\ b\12TRYFIXED\0\ b\13WIRED\0\ -F\14\1\ +F\14\1\0\ :\0FILE\0\ :\1ANONYMOUS\0\ b\15STACK\0\ -F\30\010\ +F\30\010\0\ :\000ALIGN=NONE\0\ :\012ALIGN=1KB\0\ :\013ALIGN=2KB\0\ Index: src/tests/lib/libutil/t_snprintb.c diff -u src/tests/lib/libutil/t_snprintb.c:1.5 src/tests/lib/libutil/t_snprintb.c:1.6 --- src/tests/lib/libutil/t_snprintb.c:1.5 Sat Oct 14 18:41:44 2017 +++ src/tests/lib/libutil/t_snprintb.c Mon Apr 29 07:55:38 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: t_snprintb.c,v 1.5 2017/10/14 18:41:44 ryo Exp $ */ +/* $NetBSD: t_snprintb.c,v 1.6 2019/04/29 07:55:38 kre Exp $ */ /* * Copyright (c) 2002, 2004, 2008, 2010 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include <sys/cdefs.h> __COPYRIGHT("@(#) Copyright (c) 2008, 2010\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_snprintb.c,v 1.5 2017/10/14 18:41:44 ryo Exp $"); +__RCSID("$NetBSD: t_snprintb.c,v 1.6 2019/04/29 07:55:38 kre Exp $"); #include <string.h> #include <util.h> @@ -70,11 +70,33 @@ ATF_TC_BODY(snprintb, tc) "0x1<FOO=0x1=ONE>"); h_snprintb("\177\20f\0\4X\0=\1ONE\0=\2TWO\0\0", 1, "0x1<X=0x1=ONE>"); - - h_snprintb("\177\020F\0\4FOO\0:\1ONE\0:\2TWO\0\0", 1, - "0x1<ONE>"); - h_snprintb("\177\020F\0\4X\0:\1ONE\0:\2TWO\0\0", 1, + h_snprintb("\177\020F\0\4\0:\1ONE\0:\2TWO\0\0", 1, "0x1<ONE>"); + + h_snprintb("\177\20f\0\4FOO\0=\1ONE\0=\2TWO\0\0", 2, + "0x2<FOO=0x2=TWO>"); + h_snprintb("\177\20f\0\4X\0=\1ONE\0=\2TWO\0\0", 2, + "0x2<X=0x2=TWO>"); + h_snprintb("\177\020F\0\4\0:\1ONE\0:\2TWO\0\0", 2, + "0x2<TWO>"); + + h_snprintb("\177\20f\0\4FOO\0=\1ONE\0=\2TWO\0*=OTHER\0\0", 3, + "0x3<FOO=0x3=OTHER>"); + h_snprintb("\177\20f\0\4X\0=\1ONE\0=\2TWO\0*=Other(%d)\0\0", 3, + "0x3<X=0x3=Other(3)>"); + h_snprintb("\177\20f\0\x8X\0=\1ONE\0=\2TWO\0*=other(%o)\0\0", 0x20, + "0x20<X=0x20=other(40)>"); + h_snprintb("\177\020F\0\4\0:\1ONE\0:\2TWO\0\0", 3, + "0x3<>"); + + h_snprintb("\177\20f\0\4Field_1\0=\1ONE\0=\2TWO\0" + "f\4\4Field_2\0=\1ONE\0=\2TWO\0\0", 0x12, + "0x12<Field_1=0x2=TWO,Field_2=0x1=ONE>"); + + h_snprintb("\177\20f\0\4Field_1\0=\1ONE\0=\2TWO\0" + "F\x8\4\0*Field_3=%d\0" + "f\4\4Field_2\0:\1:ONE\0:\2:TWO\0\0", 0xD12, + "0xd12<Field_1=0x2=TWO,Field_3=13,Field_2=0x1:ONE>"); } static void