Module Name:    src
Committed By:   rillig
Date:           Mon Mar  4 21:35:28 UTC 2024

Modified Files:
        src/common/lib/libutil: snprintb.c
        src/tests/lib/libutil: t_snprintb.c

Log Message:
snprintb: error out on unknown new-style formatting directive


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/common/lib/libutil/snprintb.c
cvs rdiff -u -r1.29 -r1.30 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.41 src/common/lib/libutil/snprintb.c:1.42
--- src/common/lib/libutil/snprintb.c:1.41	Sat Feb 24 12:44:11 2024
+++ src/common/lib/libutil/snprintb.c	Mon Mar  4 21:35:28 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: snprintb.c,v 1.41 2024/02/24 12:44:11 rillig Exp $	*/
+/*	$NetBSD: snprintb.c,v 1.42 2024/03/04 21:35:28 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2024 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #  include <sys/cdefs.h>
 #  if defined(LIBC_SCCS)
-__RCSID("$NetBSD: snprintb.c,v 1.41 2024/02/24 12:44:11 rillig Exp $");
+__RCSID("$NetBSD: snprintb.c,v 1.42 2024/03/04 21:35:28 rillig Exp $");
 #  endif
 
 #  include <sys/types.h>
@@ -45,7 +45,7 @@ __RCSID("$NetBSD: snprintb.c,v 1.41 2024
 #  include <errno.h>
 # else /* ! _KERNEL */
 #  include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: snprintb.c,v 1.41 2024/02/24 12:44:11 rillig Exp $");
+__KERNEL_RCSID(0, "$NetBSD: snprintb.c,v 1.42 2024/03/04 21:35:28 rillig Exp $");
 #  include <sys/param.h>
 #  include <sys/inttypes.h>
 #  include <sys/systm.h>
@@ -215,7 +215,7 @@ new_style(state *s)
 			maybe_wrap_line(s, prev_bitfmt);
 			goto skip_description;
 		default:
-			s->bitfmt += 2;
+			return -1;
 		skip_description:
 			while (*s->bitfmt++ != '\0')
 				continue;

Index: src/tests/lib/libutil/t_snprintb.c
diff -u src/tests/lib/libutil/t_snprintb.c:1.29 src/tests/lib/libutil/t_snprintb.c:1.30
--- src/tests/lib/libutil/t_snprintb.c:1.29	Sat Feb 24 13:00:00 2024
+++ src/tests/lib/libutil/t_snprintb.c	Mon Mar  4 21:35:28 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: t_snprintb.c,v 1.29 2024/02/24 13:00:00 rillig Exp $ */
+/* $NetBSD: t_snprintb.c,v 1.30 2024/03/04 21:35:28 rillig Exp $ */
 
 /*
  * Copyright (c) 2002, 2004, 2008, 2010, 2024 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #include <sys/cdefs.h>
 __COPYRIGHT("@(#) Copyright (c) 2008, 2010, 2024\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_snprintb.c,v 1.29 2024/02/24 13:00:00 rillig Exp $");
+__RCSID("$NetBSD: t_snprintb.c,v 1.30 2024/03/04 21:35:28 rillig Exp $");
 
 #include <stdio.h>
 #include <string.h>
@@ -807,18 +807,24 @@ ATF_TC_BODY(snprintb, tc)
 	    0xff,
 	    "0xff<f=0xff=000000000000000000000000000255%>");
 
-	// new style unknown directive
-	//
-	// Unknown directives are assumed to have a single byte argument
-	// followed by a description; they are skipped up to the next '\0'.
-	h_snprintb(
+	// new style unknown directive, at the beginning
+	h_snprintb_len(
+	    128,
+	    "\177\020"
+	    "unknown\0",
+	    0xff,
+	    -1,
+	    "0xff#");
+
+	// new style unknown directive, after a known directive
+	h_snprintb_len(
+	    128,
 	    "\177\020"
-	    "c\010ignored\0"
-	    "c\000b\0"
-	    "lsb\0"
-	    "b\007msb\0",
+	    "b\007msb\0"
+	    "unknown\0",
 	    0xff,
-	    "0xff<msb>");
+	    -1,
+	    "0xff<msb#");
 
 	// new style combinations, 'b' '='
 	//

Reply via email to