msg_357.c revision 1.3
11.3Srillig/* $NetBSD: msg_357.c,v 1.3 2024/11/05 06:23:04 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.3Srillig * sequence. If the description that follows a hexadecimal escape sequence 101.3Srillig * starts with hexadecimal digits (A-Fa-f), these digits are still part of the 111.3Srillig * escape sequence instead of the 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.2Srilligint 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.3Srillig // If the input value is restricted further, the unintended hexadecimal 451.3Srillig // escape sequence is detected, although with a less obvious message. 461.3Srillig /* expect+3: warning: conversion '\x1FIELD' is unreachable by input value [378] */ 471.3Srillig snprintb(buf, sizeof(buf), 481.3Srillig "\020\x1FIELD", 491.3Srillig u32 & 0xffff); 501.3Srillig 511.1Srillig /* expect+5: warning: hex escape '\x0aB' mixes uppercase and lowercase digits [357] */ 521.1Srillig /* expect+4: warning: hex escape '\x0aB' has more than 2 digits [358] */ 531.1Srillig /* expect+3: warning: bit position '\x0aB' (171) in 'b\x0aBIT\0' out of range 0..63 [371] */ 541.1Srillig snprintb(buf, sizeof(buf), 551.1Srillig "\177\020b\x0aBIT\0", 561.1Srillig u64); 571.1Srillig} 58