Home | History | Annotate | Line # | Download | only in lint1
      1  1.7  rillig /*	$NetBSD: msg_363.c,v 1.7 2024/11/05 06:23:04 rillig Exp $	*/
      2  1.1  rillig # 3 "msg_363.c"
      3  1.1  rillig 
      4  1.5  rillig // Test for message: escaped character '%.*s' in description of conversion '%.*s' [363]
      5  1.1  rillig 
      6  1.1  rillig /*
      7  1.1  rillig  * The purpose of snprintb is to produce a printable, visible representation
      8  1.5  rillig  * of a binary number, therefore the description should consist of simple
      9  1.5  rillig  * characters only, and these should not need to be escaped.  If they are,
     10  1.5  rillig  * it's often due to a typo, such as a missing terminating '\0'.
     11  1.1  rillig  */
     12  1.1  rillig 
     13  1.1  rillig /* lint1-extra-flags: -X 351 */
     14  1.1  rillig 
     15  1.1  rillig typedef typeof(sizeof(0)) size_t;
     16  1.1  rillig typedef unsigned long long uint64_t;
     17  1.1  rillig 
     18  1.6  rillig int snprintb(char *, size_t, const char *, uint64_t);
     19  1.1  rillig 
     20  1.1  rillig void
     21  1.1  rillig old_style_description(unsigned u32)
     22  1.1  rillig {
     23  1.1  rillig 	char buf[64];
     24  1.1  rillig 
     25  1.1  rillig 	/* expect+6: warning: bit position '\t' in '\tprint' should be escaped as octal or hex [369] */
     26  1.5  rillig 	/* expect+5: warning: escaped character '\377' in description of conversion '\nable\377' [363] */
     27  1.1  rillig 	/* expect+4: warning: bit position '\n' in '\nable\377' should be escaped as octal or hex [369] */
     28  1.1  rillig 	snprintb(buf, sizeof(buf),
     29  1.1  rillig 	    "\020"
     30  1.1  rillig 	    "\001non\tprint\nable\377",
     31  1.1  rillig 	    u32);
     32  1.1  rillig 
     33  1.7  rillig 	// In the new format, the description can technically contain
     34  1.7  rillig 	// arbitrary characters, but having non-printable characters would
     35  1.7  rillig 	// produce confusing output, so any escaped characters are suspicious
     36  1.7  rillig 	// of being unintended.
     37  1.7  rillig 	/* expect+6: warning: escaped character '\t' in description of conversion 'b\000non\t' [363] */
     38  1.7  rillig 	/* expect+5: warning: escaped character '\n' in description of conversion 'b\000non\tprint\n' [363] */
     39  1.7  rillig 	/* expect+4: warning: escaped character '\377' in description of conversion 'b\000non\tprint\nable\377' [363] */
     40  1.7  rillig 	snprintb(buf, sizeof(buf),
     41  1.7  rillig 	    "\177\020"
     42  1.7  rillig 	    "b\000non\tprint\nable\377\0",
     43  1.7  rillig 	    u32);
     44  1.7  rillig 
     45  1.5  rillig 	/* expect+10: warning: escaped character '\177' in description of conversion '\002""\177' [363] */
     46  1.5  rillig 	/* expect+9: warning: escaped character '\177' in description of conversion '\003aa""""\177' [363] */
     47  1.5  rillig 	/* expect+8: warning: escaped character '\177' in description of conversion '\004""bb""\177' [363] */
     48  1.5  rillig 	/* expect+7: warning: escaped character '\177' in description of conversion '\005""""cc\177' [363] */
     49  1.4  rillig 	snprintb(buf, sizeof(buf),
     50  1.4  rillig 	    "\020"
     51  1.4  rillig 	    "\002""\177"
     52  1.4  rillig 	    "\003aa""""\177"
     53  1.4  rillig 	    "\004""bb""\177"
     54  1.4  rillig 	    "\005""""cc\177",
     55  1.4  rillig 	    u32);
     56  1.4  rillig 
     57  1.3  rillig 	/* expect+6: warning: bit position '\000' (0) in '\000print' out of range 1..32 [371] */
     58  1.1  rillig 	/* expect+5: warning: bit position '\n' in '\nable' should be escaped as octal or hex [369] */
     59  1.2  rillig 	/* expect+4: warning: redundant '\0' at the end of the format [377] */
     60  1.1  rillig 	snprintb(buf, sizeof(buf),
     61  1.1  rillig 	    "\020"
     62  1.1  rillig 	    "\001non\000print\nable\0",
     63  1.1  rillig 	    u32);
     64  1.1  rillig }
     65