msg_342.c revision 1.4
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> */ 12extern const unsigned short *_ctype_tab_; 13extern const short *_tolower_tab_; 14extern const short *_toupper_tab_; 15int isalnum(int); 16int isalpha(int); 17int isblank(int); 18int iscntrl(int); 19int isdigit(int); 20int isgraph(int); 21int islower(int); 22int isprint(int); 23int ispunct(int); 24int isspace(int); 25int isupper(int); 26int isxdigit(int); 27int tolower(int); 28int toupper(int); 29 30int is_other(int); 31int to_other(int); 32 33void sink(int); 34 35void 36cover_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 72void 73function_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 */ 97void 98function_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. */ 108void 109function_call_int(int c) 110{ 111 112 isspace(c); 113} 114 115void 116macro_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