Home | History | Annotate | Line # | Download | only in lint1
      1 /*	$NetBSD: msg_378.c,v 1.3 2024/08/31 06:57:32 rillig Exp $	*/
      2 # 3 "msg_378.c"
      3 
      4 // Test for message: conversion '%.*s' is unreachable by input value [378]
      5 
      6 /*
      7  * The typical use case of snprintb is to have a format that is specifically
      8  * tailored to a particular input value.  Often, a format is only used in a
      9  * single place.  Therefore, bits that are unreachable are redundant and may
     10  * hint at typos.
     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 example(unsigned u32, uint64_t u64)
     22 {
     23 	char buf[64];
     24 
     25 	/* expect+5: warning: conversion '\040bit32' is unreachable by input value [378] */
     26 	snprintb(buf, sizeof(buf),
     27 	    "\020"
     28 	    "\037bit31"
     29 	    "\040bit32",
     30 	    u32 >> 1);
     31 
     32 	/* expect+5: warning: conversion 'b\075bit61\0' is unreachable by input value [378] */
     33 	snprintb(buf, sizeof(buf),
     34 	    "\177\020"
     35 	    "b\074bit60\0"
     36 	    "b\075bit61\0",
     37 	    u64 >> 3);
     38 
     39 	/* expect+12: warning: conversion 'b\000bit0\0' is unreachable by input value [378] */
     40 	/* expect+11: warning: conversion 'b\011bit9\0' is unreachable by input value [378] */
     41 	/* expect+10: warning: conversion 'f\017\002bits15-16\0' is unreachable by input value [378] */
     42 	/* expect+9: warning: conversion 'f\050\030bits40-63\0' is unreachable by input value [378] */
     43 	snprintb(buf, sizeof(buf),
     44 	    "\177\020"
     45 	    "b\000bit0\0"
     46 	    "b\010bit8\0"
     47 	    "b\011bit9\0"
     48 	    "f\012\002bits10-11\0"
     49 	    "f\017\002bits15-16\0"
     50 	    "f\050\030bits40-63\0",
     51 	    (u32 & 0xaa55aa55) << 8);
     52 }
     53