Home | History | Annotate | Line # | Download | only in lint1
      1  1.5  rillig /*	$NetBSD: msg_377.c,v 1.5 2024/08/31 06:57:32 rillig Exp $	*/
      2  1.1  rillig # 3 "msg_377.c"
      3  1.1  rillig 
      4  1.2  rillig // Test for message: redundant '\0' at the end of the format [377]
      5  1.1  rillig 
      6  1.1  rillig /*
      7  1.4  rillig  * Each conversion in the new-style format ends with a '\0' that needs to be
      8  1.2  rillig  * spelled out.
      9  1.2  rillig  *
     10  1.2  rillig  * In both old-style and new-style formats, the '\0' that ends the whole
     11  1.2  rillig  * format is provided by the compiler as part of the string literal.
     12  1.1  rillig  */
     13  1.1  rillig 
     14  1.1  rillig /* lint1-extra-flags: -X 351 */
     15  1.1  rillig 
     16  1.1  rillig typedef typeof(sizeof(0)) size_t;
     17  1.1  rillig typedef unsigned long long uint64_t;
     18  1.1  rillig 
     19  1.5  rillig int snprintb(char *, size_t, const char *, uint64_t);
     20  1.1  rillig 
     21  1.1  rillig void
     22  1.1  rillig example(unsigned u32, uint64_t u64)
     23  1.1  rillig {
     24  1.1  rillig 	char buf[64];
     25  1.1  rillig 
     26  1.2  rillig 	/* expect+7: warning: bit position '\000' (0) in '\000out-of-range' out of range 1..32 [371] */
     27  1.2  rillig 	/* expect+6: warning: redundant '\0' at the end of the format [377] */
     28  1.1  rillig 	snprintb(buf, sizeof(buf),
     29  1.1  rillig 	    "\020"
     30  1.1  rillig 	    "\005bit"
     31  1.2  rillig 	    "\000out-of-range"
     32  1.1  rillig 	    "\0",
     33  1.1  rillig 	    u32);
     34  1.1  rillig 
     35  1.2  rillig 	/* expect+5: warning: redundant '\0' at the end of the format [377] */
     36  1.1  rillig 	snprintb(buf, sizeof(buf),
     37  1.1  rillig 	    "\177\020"
     38  1.1  rillig 	    "b\005bit\0"
     39  1.1  rillig 	    "\0",
     40  1.1  rillig 	    u64);
     41  1.1  rillig }
     42