Home | History | Annotate | Line # | Download | only in lint1
msg_358.c revision 1.2
      1 /*	$NetBSD: msg_358.c,v 1.2 2024/03/03 13:09:23 rillig Exp $	*/
      2 # 3 "msg_358.c"
      3 
      4 // Test for message: hex escape '%.*s' has more than 2 digits [358]
      5 
      6 /*
      7  * In the format argument of the snprintb and snprintb_m functions, a bit
      8  * position or field width is written as an octal or hexadecimal escape
      9  * sequence.  If the description that follows starts with hex digits (A-Fa-f),
     10  * these digits are still part of the escape sequence instead of the
     11  * description.
     12  */
     13 
     14 /* lint1-extra-flags: -X 351 */
     15 
     16 typedef typeof(sizeof(0)) size_t;
     17 typedef unsigned long long uint64_t;
     18 
     19 int snprintb(char*, size_t, const char*, uint64_t);
     20 
     21 void
     22 examples(unsigned u32, uint64_t u64)
     23 {
     24 	char buf[64];
     25 
     26 	/* expect+3: warning: hex escape '\x01B' has more than 2 digits [358] */
     27 	snprintb(buf, sizeof(buf),
     28 	    "\020\x01BIT",
     29 	    u32);
     30 
     31 	/* expect+3: warning: hex escape '\x01b' has more than 2 digits [358] */
     32 	snprintb(buf, sizeof(buf),
     33 	    "\020\x01bit",
     34 	    u32);
     35 
     36 	// This mismatch goes undetected as it has only 2 digits, does not mix
     37 	// case and is in bounds.  A spellchecker could mark the unknown word
     38 	// 'ield' to give a hint.
     39 	snprintb(buf, sizeof(buf),
     40 	    "\020\x1FIELD",
     41 	    u32);
     42 
     43 	/* expect+3: warning: hex escape '\x01b' has more than 2 digits [358] */
     44 	snprintb(buf, sizeof(buf),
     45 	    "\177\020b\x01bit\0",
     46 	    u64);
     47 
     48 	/* expect+3: warning: hex escape '\x02b' has more than 2 digits [358] */
     49 	snprintb(buf, sizeof(buf),
     50 	    "\177\020f\x00\x02bit\0",
     51 	    u64);
     52 
     53 	// In this example from the snprintb manual page, the descriptions
     54 	// that start with a hexadecimal digit must be separated from the
     55 	// hexadecimal escape sequence for the bit position.
     56 	snprintb(buf, sizeof(buf),
     57 	    "\20\x10NOTBOOT\x0f" "FPP\x0eSDVMA\x0cVIDEO"
     58 	    "\x0bLORES\x0a" "FPA\x09" "DIAG\x07" "CACHE"
     59 	    "\x06IOCACHE\x05LOOPBACK\x04" "DBGCACHE",
     60 	    u32);
     61 }
     62