Home | History | Annotate | Line # | Download | only in lint1
msg_366.c revision 1.1
      1  1.1  rillig /*	$NetBSD: msg_366.c,v 1.1 2024/03/01 19:39:28 rillig Exp $	*/
      2  1.1  rillig # 3 "msg_366.c"
      3  1.1  rillig 
      4  1.1  rillig // Test for message: missing '\0' at the end of '%.*s' [366]
      5  1.1  rillig 
      6  1.1  rillig /*
      7  1.1  rillig  * In the new-style format, each directive ends with a '\0'.  If that's not
      8  1.1  rillig  * the case, snprintb will read beyond the end of the format argument, looking
      9  1.1  rillig  * for the terminating '\0'.  In the most common case where the format comes
     10  1.1  rillig  * from a string literal, the '\0' from the directive needs to be spelled out,
     11  1.1  rillig  * while the '\0' that terminates the sequence of directives is provided by
     12  1.1  rillig  * the C compiler.
     13  1.1  rillig  */
     14  1.1  rillig 
     15  1.1  rillig /* lint1-extra-flags: -X 351 */
     16  1.1  rillig 
     17  1.1  rillig typedef typeof(sizeof(0)) size_t;
     18  1.1  rillig typedef unsigned long long uint64_t;
     19  1.1  rillig 
     20  1.1  rillig int snprintb(char*, size_t, const char*, uint64_t);
     21  1.1  rillig 
     22  1.1  rillig void
     23  1.1  rillig example(unsigned u32)
     24  1.1  rillig {
     25  1.1  rillig 	char buf[64];
     26  1.1  rillig 
     27  1.1  rillig 	/* expect+4: warning: unknown directive '\0' [374] */
     28  1.1  rillig 	snprintb(buf, sizeof(buf),
     29  1.1  rillig 	    "\177\020"
     30  1.1  rillig 	    "\0",
     31  1.1  rillig 	    u32);
     32  1.1  rillig 
     33  1.1  rillig 	/* expect+4: warning: missing '\0' at the end of 'b\007' [366] */
     34  1.1  rillig 	snprintb(buf, sizeof(buf),
     35  1.1  rillig 	    "\177\020"
     36  1.1  rillig 	    "b\007",
     37  1.1  rillig 	    u32);
     38  1.1  rillig 
     39  1.1  rillig 	/* expect+4: warning: missing '\0' at the end of 'f\007\000' [366] */
     40  1.1  rillig 	snprintb(buf, sizeof(buf),
     41  1.1  rillig 	    "\177\020"
     42  1.1  rillig 	    "f\007\000",
     43  1.1  rillig 	    u32);
     44  1.1  rillig 
     45  1.1  rillig 	/* expect+4: warning: missing '\0' at the end of 'F\007\000' [366] */
     46  1.1  rillig 	snprintb(buf, sizeof(buf),
     47  1.1  rillig 	    "\177\020"
     48  1.1  rillig 	    "F\007\000",
     49  1.1  rillig 	    u32);
     50  1.1  rillig 
     51  1.1  rillig 	/* expect+4: warning: missing '\0' at the end of '=\007value' [366] */
     52  1.1  rillig 	snprintb(buf, sizeof(buf),
     53  1.1  rillig 	    "\177\020"
     54  1.1  rillig 	    "=\007value",
     55  1.1  rillig 	    u32);
     56  1.1  rillig 
     57  1.1  rillig 	/* expect+4: warning: missing '\0' at the end of ':\007value' [366] */
     58  1.1  rillig 	snprintb(buf, sizeof(buf),
     59  1.1  rillig 	    "\177\020"
     60  1.1  rillig 	    ":\007value",
     61  1.1  rillig 	    u32);
     62  1.1  rillig 
     63  1.1  rillig 	/* expect+4: warning: missing '\0' at the end of '*default' [366] */
     64  1.1  rillig 	snprintb(buf, sizeof(buf),
     65  1.1  rillig 	    "\177\020"
     66  1.1  rillig 	    "*default",
     67  1.1  rillig 	    u32);
     68  1.1  rillig }
     69