1 /* $NetBSD: msg_342.c,v 1.4 2022/06/17 18:54:53 rillig Exp $ */ 2 # 3 "msg_342.c" 3 4 // Test for message: argument to '%s' must be cast to 'unsigned char', not to '%s' [342] 5 6 /* 7 * Ensure that the functions from <ctype.h> are called with the correct 8 * argument. 9 */ 10 11 /* NetBSD 9.99.81, <ctype.h> */ 12 extern const unsigned short *_ctype_tab_; 13 extern const short *_tolower_tab_; 14 extern const short *_toupper_tab_; 15 int isalnum(int); 16 int isalpha(int); 17 int isblank(int); 18 int iscntrl(int); 19 int isdigit(int); 20 int isgraph(int); 21 int islower(int); 22 int isprint(int); 23 int ispunct(int); 24 int isspace(int); 25 int isupper(int); 26 int isxdigit(int); 27 int tolower(int); 28 int toupper(int); 29 30 int is_other(int); 31 int to_other(int); 32 33 void sink(int); 34 35 void 36 cover_is_ctype_function(char c) 37 { 38 /* expect+1: warning: argument to 'isalnum' must be 'unsigned char' or EOF, not 'char' [341] */ 39 isalnum(c); 40 /* expect+1: warning: argument to 'isalpha' must be 'unsigned char' or EOF, not 'char' [341] */ 41 isalpha(c); 42 /* expect+1: warning: argument to 'isblank' must be 'unsigned char' or EOF, not 'char' [341] */ 43 isblank(c); 44 /* expect+1: warning: argument to 'iscntrl' must be 'unsigned char' or EOF, not 'char' [341] */ 45 iscntrl(c); 46 /* expect+1: warning: argument to 'isdigit' must be 'unsigned char' or EOF, not 'char' [341] */ 47 isdigit(c); 48 /* expect+1: warning: argument to 'isgraph' must be 'unsigned char' or EOF, not 'char' [341] */ 49 isgraph(c); 50 /* expect+1: warning: argument to 'islower' must be 'unsigned char' or EOF, not 'char' [341] */ 51 islower(c); 52 /* expect+1: warning: argument to 'isprint' must be 'unsigned char' or EOF, not 'char' [341] */ 53 isprint(c); 54 /* expect+1: warning: argument to 'ispunct' must be 'unsigned char' or EOF, not 'char' [341] */ 55 ispunct(c); 56 /* expect+1: warning: argument to 'isspace' must be 'unsigned char' or EOF, not 'char' [341] */ 57 isspace(c); 58 /* expect+1: warning: argument to 'isupper' must be 'unsigned char' or EOF, not 'char' [341] */ 59 isupper(c); 60 /* expect+1: warning: argument to 'isxdigit' must be 'unsigned char' or EOF, not 'char' [341] */ 61 isxdigit(c); 62 /* expect+1: warning: argument to 'tolower' must be 'unsigned char' or EOF, not 'char' [341] */ 63 tolower(c); 64 /* expect+1: warning: argument to 'toupper' must be 'unsigned char' or EOF, not 'char' [341] */ 65 toupper(c); 66 67 /* Functions with similar names are not checked. */ 68 is_other(c); 69 to_other(c); 70 } 71 72 void 73 function_call_char(char c) 74 { 75 76 /* expect+1: warning: argument to 'isspace' must be 'unsigned char' or EOF, not 'char' [341] */ 77 (isspace)(c); 78 79 /* This is the only allowed form. */ 80 isspace((unsigned char)c); 81 82 /* The cast to 'int' is redundant, it doesn't hurt though. */ 83 isspace((int)(unsigned char)c); 84 85 /* expect+1: warning: argument to 'isspace' must be cast to 'unsigned char', not to 'int' [342] */ 86 isspace((int)c); 87 88 /* expect+1: warning: argument to 'isspace' must be cast to 'unsigned char', not to 'unsigned int' [342] */ 89 isspace((unsigned int)c); 90 } 91 92 /* 93 * If the expression starts with type 'unsigned char', it can be cast to any 94 * other type. Chances are low enough that the cast is to 'char', which would 95 * be the only bad type. 96 */ 97 void 98 function_call_unsigned_char(unsigned char c) 99 { 100 101 (isspace)(c); 102 isspace((unsigned char)c); 103 isspace((int)c); 104 isspace((unsigned int)c); 105 } 106 107 /* When used in a loop of fgetc, the type is already 'int'. That's fine. */ 108 void 109 function_call_int(int c) 110 { 111 112 isspace(c); 113 } 114 115 void 116 macro_invocation_NetBSD(char c) 117 { 118 119 /* expect+1: warning: argument to 'function from <ctype.h>' must be 'unsigned char' or EOF, not 'char' [341] */ 120 sink(((int)((_ctype_tab_ + 1)[(c)] & 0x0040))); 121 122 /* This is the only allowed form. */ 123 sink(((int)((_ctype_tab_ + 1)[((unsigned char)c)] & 0x0040))); 124 125 /* expect+1: warning: argument to 'function from <ctype.h>' must be cast to 'unsigned char', not to 'int' [342] */ 126 sink(((int)((_ctype_tab_ + 1)[((int)c)] & 0x0040))); 127 128 /* expect+1: warning: argument to 'function from <ctype.h>' must be cast to 'unsigned char', not to 'unsigned int' [342] */ 129 sink(((int)((_ctype_tab_ + 1)[((unsigned int)c)] & 0x0040))); 130 } 131