Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src snprintb(3) says that, in the new(?) Torek format, all field...



details:   https://anonhg.NetBSD.org/src/rev/f6b4d1aa9eb9
branches:  trunk
changeset: 456246:f6b4d1aa9eb9
user:      kre <kre%NetBSD.org@localhost>
date:      Mon Apr 29 07:55:38 2019 +0000

description:
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:

 common/lib/libutil/snprintb.c  |  13 ++++++++-----
 lib/libutil/snprintb.3         |   6 +++---
 sys/sys/mman.h                 |   6 +++---
 tests/lib/libutil/t_snprintb.c |  34 ++++++++++++++++++++++++++++------
 4 files changed, 42 insertions(+), 17 deletions(-)

diffs (151 lines):

diff -r 9e513fe42eaa -r f6b4d1aa9eb9 common/lib/libutil/snprintb.c
--- a/common/lib/libutil/snprintb.c     Mon Apr 29 05:42:09 2019 +0000
+++ b/common/lib/libutil/snprintb.c     Mon Apr 29 07:55:38 2019 +0000
@@ -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 @@
 #  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 @@
                                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 @@
                                if (!matched) {
                                        matched = 1;
                                        FMTSTR(bitfmt, field);
-                                       break;
                                }
                                /*FALLTHROUGH*/
                        default:
diff -r 9e513fe42eaa -r f6b4d1aa9eb9 lib/libutil/snprintb.3
--- a/lib/libutil/snprintb.3    Mon Apr 29 05:42:09 2019 +0000
+++ b/lib/libutil/snprintb.3    Mon Apr 29 07:55:38 2019 +0000
@@ -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\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
diff -r 9e513fe42eaa -r f6b4d1aa9eb9 sys/sys/mman.h
--- a/sys/sys/mman.h    Mon Apr 29 05:42:09 2019 +0000
+++ b/sys/sys/mman.h    Mon Apr 29 07:55:38 2019 +0000
@@ -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\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\
diff -r 9e513fe42eaa -r f6b4d1aa9eb9 tests/lib/libutil/t_snprintb.c
--- a/tests/lib/libutil/t_snprintb.c    Mon Apr 29 05:42:09 2019 +0000
+++ b/tests/lib/libutil/t_snprintb.c    Mon Apr 29 07:55:38 2019 +0000
@@ -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 @@
            "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,
+       h_snprintb("\177\020F\0\4\0:\1ONE\0:\2TWO\0\0", 1,
            "0x1<ONE>");
-       h_snprintb("\177\020F\0\4X\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



Home | Main Index | Thread Index | Old Index