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