Home | History | Annotate | Line # | Download | only in lint1
msg_230.c revision 1.8
      1 /*	$NetBSD: msg_230.c,v 1.8 2021/08/28 15:25:10 rillig Exp $	*/
      2 # 3 "msg_230.c"
      3 
      4 // Test for message: nonportable character comparison, op %s [230]
      5 
      6 /* lint1-flags: -S -g -p -w */
      7 /* lint1-only-if: schar */
      8 
      9 /*
     10  * C11 6.2.5p15 defines that 'char' has the same range, representation, and
     11  * behavior as either 'signed char' or 'unsigned char'.
     12  *
     13  * The portable range of 'char' is from 0 to 127 since all lint platforms
     14  * define CHAR_SIZE to be 8.
     15  *
     16  * See msg_162.c, which covers 'signed char' and 'unsigned char'.
     17  */
     18 
     19 void
     20 compare_plain_char(char c)
     21 {
     22 	/* expect+1: warning: nonportable character comparison, op == [230] */
     23 	if (c == -129)
     24 		return;
     25 	/* expect+1: warning: nonportable character comparison, op == [230] */
     26 	if (c == -128)
     27 		return;
     28 	/* expect+1: warning: nonportable character comparison, op == [230] */
     29 	if (c == -1)
     30 		return;
     31 	if (c == 0)
     32 		return;
     33 	if (c == 127)
     34 		return;
     35 	/* expect+1: warning: nonportable character comparison, op == [230] */
     36 	if (c == 128)
     37 		return;
     38 	/* expect+1: warning: nonportable character comparison, op == [230] */
     39 	if (c == 255)
     40 		return;
     41 	/* expect+1: warning: nonportable character comparison, op == [230] */
     42 	if (c == 256)
     43 		return;
     44 }
     45 
     46 void
     47 compare_plain_char_yoda(char c)
     48 {
     49 	/* expect+1: warning: nonportable character comparison, op == [230] */
     50 	if (-129 == c)
     51 		return;
     52 	/* expect+1: warning: nonportable character comparison, op == [230] */
     53 	if (-128 == c)
     54 		return;
     55 	/* expect+1: warning: nonportable character comparison, op == [230] */
     56 	if (-1 == c)
     57 		return;
     58 	if (0 == c)
     59 		return;
     60 	if (127 == c)
     61 		return;
     62 	/* expect+1: warning: nonportable character comparison, op == [230] */
     63 	if (128 == c)
     64 		return;
     65 	/* expect+1: warning: nonportable character comparison, op == [230] */
     66 	if (255 == c)
     67 		return;
     68 	/* expect+1: warning: nonportable character comparison, op == [230] */
     69 	if (256 == c)
     70 		return;
     71 }
     72 
     73 void
     74 compare_lt(char c)
     75 {
     76 
     77 	/* expect+1: warning: nonportable character comparison, op > [230] */
     78 	if (c > -2)
     79 		return;
     80 	/* expect+1: warning: nonportable character comparison, op >= [230] */
     81 	if (c >= -1)
     82 		return;
     83 
     84 	/*
     85 	 * XXX: The following two comparisons have the same effect, yet lint
     86 	 * only warns about one of them.
     87 	 */
     88 	/* expect+1: warning: nonportable character comparison, op > [230] */
     89 	if (c > -1)
     90 		return;
     91 	/*
     92 	 * On platforms where char is unsigned, lint warns that the
     93 	 * comparison always evaluates to true; see msg_230_uchar.c.
     94 	 */
     95 	if (c >= 0)
     96 		return;
     97 
     98 	/*
     99 	 * XXX: The following two comparisons have the same effect, yet lint
    100 	 * only warns about one of them.
    101 	 */
    102 	if (c > 127)
    103 		return;
    104 	/* expect+1: warning: nonportable character comparison, op >= [230] */
    105 	if (c >= 128)
    106 		return;
    107 
    108 	/* expect+1: warning: nonportable character comparison, op > [230] */
    109 	if (c > 128)
    110 		return;
    111 	/* expect+1: warning: nonportable character comparison, op >= [230] */
    112 	if (c >= 129)
    113 		return;
    114 }
    115