msg_357.c revision 1.1
11.1Srillig/* $NetBSD: msg_357.c,v 1.1 2024/03/01 19:39:28 rillig Exp $ */ 21.1Srillig# 3 "msg_357.c" 31.1Srillig 41.1Srillig// Test for message: hex escape '%.*s' mixes uppercase and lowercase digits [357] 51.1Srillig 61.1Srillig/* 71.1Srillig * In the format argument of the snprintb and snprintb_m functions, a bit 81.1Srillig * position or field width is written as an octal or hexadecimal escape 91.1Srillig * sequence. If the description that follows starts with hex digits (A-Fa-f), 101.1Srillig * these digits are still part of the escape sequence instead of the 111.1Srillig * description. 121.1Srillig * 131.1Srillig * Since the escape sequences are typically written in lowercase and the 141.1Srillig * descriptions are typically written in uppercase, a mixture of both cases 151.1Srillig * indicates a mismatch. 161.1Srillig */ 171.1Srillig 181.1Srillig/* lint1-extra-flags: -X 351 */ 191.1Srillig 201.1Srilligtypedef typeof(sizeof(0)) size_t; 211.1Srilligtypedef unsigned long long uint64_t; 221.1Srillig 231.1Srilligint snprintb(char*, size_t, const char*, uint64_t); 241.1Srillig 251.1Srilligvoid 261.1Srilligexamples(unsigned u32, uint64_t u64) 271.1Srillig{ 281.1Srillig char buf[64]; 291.1Srillig 301.1Srillig /* expect+5: warning: hex escape '\x0aB' mixes uppercase and lowercase digits [357] */ 311.1Srillig /* expect+4: warning: hex escape '\x0aB' has more than 2 digits [358] */ 321.1Srillig /* expect+3: warning: bit position '\x0aB' (171) in '\x0aBIT' out of range 1..32 [371] */ 331.1Srillig snprintb(buf, sizeof(buf), 341.1Srillig "\020\x0aBIT", 351.1Srillig u32); 361.1Srillig 371.1Srillig // This mismatch goes undetected as it has only 2 digits, does not mix 381.1Srillig // case and is in bounds. A spellchecker could mark the unknown word 391.1Srillig // 'ield' to give a hint. 401.1Srillig snprintb(buf, sizeof(buf), 411.1Srillig "\020\x1FIELD", 421.1Srillig u32); 431.1Srillig 441.1Srillig /* expect+5: warning: hex escape '\x0aB' mixes uppercase and lowercase digits [357] */ 451.1Srillig /* expect+4: warning: hex escape '\x0aB' has more than 2 digits [358] */ 461.1Srillig /* expect+3: warning: bit position '\x0aB' (171) in 'b\x0aBIT\0' out of range 0..63 [371] */ 471.1Srillig snprintb(buf, sizeof(buf), 481.1Srillig "\177\020b\x0aBIT\0", 491.1Srillig u64); 501.1Srillig} 51