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