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