Home | History | Annotate | Line # | Download | only in lint1
      1  1.5  rillig /*	$NetBSD: msg_341.c,v 1.5 2025/01/28 20:21:59 rillig Exp $	*/
      2  1.1  rillig # 3 "msg_341.c"
      3  1.1  rillig 
      4  1.1  rillig // Test for message: argument to '%s' must be 'unsigned char' or EOF, not '%s' [341]
      5  1.1  rillig 
      6  1.1  rillig /*
      7  1.1  rillig  * Ensure that the functions from <ctype.h> are called with the correct
      8  1.1  rillig  * argument.
      9  1.1  rillig  */
     10  1.1  rillig 
     11  1.3  rillig /* lint1-extra-flags: -X 351 */
     12  1.3  rillig 
     13  1.1  rillig /* NetBSD 9.99.81, <ctype.h> */
     14  1.1  rillig extern const unsigned short *_ctype_tab_;
     15  1.1  rillig extern const short *_tolower_tab_;
     16  1.1  rillig extern const short *_toupper_tab_;
     17  1.1  rillig int isspace(int);
     18  1.1  rillig 
     19  1.1  rillig void sink(int);
     20  1.1  rillig 
     21  1.1  rillig void
     22  1.1  rillig function_call_char(char c)
     23  1.1  rillig {
     24  1.1  rillig 
     25  1.2  rillig 	/* expect+1: warning: argument to 'isspace' must be 'unsigned char' or EOF, not 'char' [341] */
     26  1.1  rillig 	(isspace)(c);
     27  1.1  rillig 
     28  1.1  rillig 	/* This is the only allowed form. */
     29  1.1  rillig 	isspace((unsigned char)c);
     30  1.1  rillig 
     31  1.1  rillig 	/* The cast to 'int' is redundant, it doesn't hurt though. */
     32  1.1  rillig 	isspace((int)(unsigned char)c);
     33  1.1  rillig 
     34  1.2  rillig 	/* expect+1: warning: argument to 'isspace' must be cast to 'unsigned char', not to 'int' [342] */
     35  1.1  rillig 	isspace((int)c);
     36  1.1  rillig 
     37  1.2  rillig 	/* expect+1: warning: argument to 'isspace' must be cast to 'unsigned char', not to 'unsigned int' [342] */
     38  1.1  rillig 	isspace((unsigned int)c);
     39  1.1  rillig }
     40  1.1  rillig 
     41  1.1  rillig /*
     42  1.1  rillig  * If the expression starts with type 'unsigned char', it can be cast to any
     43  1.1  rillig  * other type.  Chances are low enough that the cast is to 'char', which would
     44  1.1  rillig  * be the only bad type.
     45  1.1  rillig  */
     46  1.1  rillig void
     47  1.1  rillig function_call_unsigned_char(unsigned char c)
     48  1.1  rillig {
     49  1.1  rillig 
     50  1.1  rillig 	(isspace)(c);
     51  1.1  rillig 	isspace((unsigned char)c);
     52  1.1  rillig 	isspace((int)c);
     53  1.1  rillig 	isspace((unsigned int)c);
     54  1.1  rillig }
     55  1.1  rillig 
     56  1.1  rillig /* When used in a loop of fgetc, the type is already 'int'.  That's fine. */
     57  1.1  rillig void
     58  1.1  rillig function_call_int(int c)
     59  1.1  rillig {
     60  1.1  rillig 
     61  1.1  rillig 	isspace(c);
     62  1.1  rillig }
     63  1.1  rillig 
     64  1.1  rillig void
     65  1.4  rillig macro_invocation_NetBSD(char c, signed char sc)
     66  1.1  rillig {
     67  1.1  rillig 
     68  1.2  rillig 	/* expect+1: warning: argument to 'function from <ctype.h>' must be 'unsigned char' or EOF, not 'char' [341] */
     69  1.1  rillig 	sink(((int)((_ctype_tab_ + 1)[(c)] & 0x0040)));
     70  1.1  rillig 
     71  1.1  rillig 	/* This is the only allowed form. */
     72  1.1  rillig 	sink(((int)((_ctype_tab_ + 1)[((unsigned char)c)] & 0x0040)));
     73  1.1  rillig 
     74  1.2  rillig 	/* expect+1: warning: argument to 'function from <ctype.h>' must be cast to 'unsigned char', not to 'int' [342] */
     75  1.1  rillig 	sink(((int)((_ctype_tab_ + 1)[((int)c)] & 0x0040)));
     76  1.1  rillig 
     77  1.2  rillig 	/* expect+1: warning: argument to 'function from <ctype.h>' must be cast to 'unsigned char', not to 'unsigned int' [342] */
     78  1.1  rillig 	sink(((int)((_ctype_tab_ + 1)[((unsigned int)c)] & 0x0040)));
     79  1.4  rillig 
     80  1.5  rillig 	// See platform_ilp32_int.c.
     81  1.5  rillig 	// See platform_ilp32_long.c.
     82  1.5  rillig 	// See platform_lp64.c.
     83  1.4  rillig 
     84  1.4  rillig 	/* expect+1: warning: argument to 'function from <ctype.h>' must be 'unsigned char' or EOF, not 'signed char' [341] */
     85  1.4  rillig 	sink(((int)((_ctype_tab_ + 1)[sc])));
     86  1.1  rillig }
     87