Home | History | Annotate | Line # | Download | only in lint1
msg_377.c revision 1.1
      1 /*	$NetBSD: msg_377.c,v 1.1 2024/03/03 00:50:41 rillig Exp $	*/
      2 # 3 "msg_377.c"
      3 
      4 // Test for message: redundant '\0' at the end of new-style format [377]
      5 
      6 /*
      7  * Each directive in the new-style format ends with a '\0'. The final '\0'
      8  * that ends the whole format is provided implicitly by the compiler as part
      9  * of the string literal.
     10  */
     11 
     12 /* lint1-extra-flags: -X 351 */
     13 
     14 typedef typeof(sizeof(0)) size_t;
     15 typedef unsigned long long uint64_t;
     16 
     17 int snprintb(char*, size_t, const char*, uint64_t);
     18 
     19 void
     20 example(unsigned u32, uint64_t u64)
     21 {
     22 	char buf[64];
     23 
     24 	/* expect+6: warning: old-style format contains '\0' [362] */
     25 	/* expect+5: warning: empty description in '\0' [367] */
     26 	snprintb(buf, sizeof(buf),
     27 	    "\020"
     28 	    "\005bit"
     29 	    "\0",
     30 	    u32);
     31 
     32 	/* expect+5: warning: redundant '\0' at the end of new-style format [377] */
     33 	snprintb(buf, sizeof(buf),
     34 	    "\177\020"
     35 	    "b\005bit\0"
     36 	    "\0",
     37 	    u64);
     38 }
     39