mirror of
https://github.com/curl/curl.git
synced 2026-04-11 12:01:42 +08:00
clang-tidy: enable bugprone-signed-char-misuse, fix fallouts
Examples:
```
lib/vtls/openssl.c:2585:18: warning: 'signed char' to 'int' conversion; consider casting to 'unsigned char' first. [bugprone-signed-char-misuse]
2585 | msg_type = *(const char *)buf;
lib/vtls/openssl.c:2593:18: warning: 'signed char' to 'int' conversion; consider casting to 'unsigned char' first. [bugprone-signed-char-misuse]
2593 | msg_type = *(const char *)buf;
tests/server/mqttd.c:514:10: warning: comparison between 'signed char' and 'unsigned char' [bugprone-signed-char-misuse]
514 | if(passwd_flag == (char)(conn_flags & passwd_flag)) {
tests/server/tftpd.c:362:13: warning: 'signed char' to 'int' conversion; consider casting to 'unsigned char' first. [bugprone-signed-char-misuse]
362 | c = test->rptr[0];
tests/server/tftpd.c:454:9: warning: 'signed char' to 'int' conversion; consider casting to 'unsigned char' first. [bugprone-signed-char-misuse]
454 | c = *p++; /* pick up a character */
src/tool_urlglob.c:272:46: warning: 'signed char' to 'int' conversion; consider casting to 'unsigned char' first. [bugprone-signed-char-misuse]
272 | pat->c.ascii.letter = pat->c.ascii.min = min_c;
src/tool_urlglob.c:273:24: warning: 'signed char' to 'int' conversion; consider casting to 'unsigned char' first. [bugprone-signed-char-misuse]
273 | pat->c.ascii.max = max_c;
tests/libtest/cli_h2_pausing.c:164:23: warning: suspicious usage of 'sizeof()' on an expression of pointer type [bugprone-sizeof-expression]
164 | memset(&resolve, 0, sizeof(resolve));
tests/libtest/cli_upload_pausing.c:158:23: warning: suspicious usage of 'sizeof()' on an expression of pointer type [bugprone-sizeof-expression]
158 | memset(&resolve, 0, sizeof(resolve));
tests/libtest/first.c:86:15: warning: 'signed char' to 'int' conversion; consider casting to 'unsigned char' first. [bugprone-signed-char-misuse]
86 | coptopt = arg[optpos];
```
Also:
- tests/server/mqttd: drop a redundant and a wrongly signed cast.
Ref: https://clang.llvm.org/extra/clang-tidy/checks/bugprone/signed-char-misuse.html
Closes #20654
This commit is contained in:
parent
86772a76c7
commit
ac46392f44
@ -13,6 +13,7 @@ Checks:
|
||||
- -clang-diagnostic-nullability-extension
|
||||
- bugprone-macro-parentheses
|
||||
- bugprone-redundant-branch-condition
|
||||
- bugprone-signed-char-misuse
|
||||
- bugprone-suspicious-realloc-usage
|
||||
- misc-const-correctness
|
||||
- misc-header-include-cycle
|
||||
|
||||
@ -70,7 +70,7 @@ static int inet_pton4(const char *src, unsigned char *dst)
|
||||
octets = 0;
|
||||
tp = tmp;
|
||||
*tp = 0;
|
||||
while((ch = *src++) != '\0') {
|
||||
while((ch = (unsigned char)*src++) != '\0') {
|
||||
if(ISDIGIT(ch)) {
|
||||
unsigned int val = (*tp * 10) + (ch - '0');
|
||||
|
||||
@ -129,7 +129,7 @@ static int inet_pton6(const char *src, unsigned char *dst)
|
||||
curtok = src;
|
||||
saw_xdigit = 0;
|
||||
val = 0;
|
||||
while((ch = *src++) != '\0') {
|
||||
while((ch = (unsigned char)*src++) != '\0') {
|
||||
if(ISXDIGIT(ch)) {
|
||||
val <<= 4;
|
||||
val |= curlx_hexval(ch);
|
||||
|
||||
@ -464,7 +464,7 @@ static size_t encoder_qp_read(char *buffer, size_t size, bool ateof,
|
||||
while(st->bufbeg < st->bufend) {
|
||||
size_t len = 1;
|
||||
size_t consumed = 1;
|
||||
int i = st->buf[st->bufbeg];
|
||||
int i = (unsigned char)st->buf[st->bufbeg];
|
||||
buf[0] = (char)i;
|
||||
buf[1] = aschex[(i >> 4) & 0xF];
|
||||
buf[2] = aschex[i & 0xF];
|
||||
|
||||
@ -2592,18 +2592,20 @@ static void ossl_trace(int direction, int ssl_ver, int content_type,
|
||||
|
||||
if(content_type == SSL3_RT_CHANGE_CIPHER_SPEC) {
|
||||
if(len) {
|
||||
msg_type = *(const char *)buf;
|
||||
msg_type = *(const unsigned char *)buf;
|
||||
msg_name = "Change cipher spec";
|
||||
}
|
||||
}
|
||||
else if(content_type == SSL3_RT_ALERT) {
|
||||
if(len >= 2) {
|
||||
msg_type = (((const char *)buf)[0] << 8) + ((const char *)buf)[1];
|
||||
msg_type =
|
||||
(((const unsigned char *)buf)[0] << 8) +
|
||||
((const unsigned char *)buf)[1];
|
||||
msg_name = SSL_alert_desc_string_long(msg_type);
|
||||
}
|
||||
}
|
||||
else if(len) {
|
||||
msg_type = *(const char *)buf;
|
||||
msg_type = *(const unsigned char *)buf;
|
||||
msg_name = ssl_msg_type(ssl_ver, msg_type);
|
||||
}
|
||||
|
||||
|
||||
@ -269,8 +269,8 @@ static CURLcode glob_range(struct URLGlob *glob, const char **patternp,
|
||||
|
||||
/* if there was a ":[num]" thing, use that as step or else use 1 */
|
||||
pat->c.ascii.step = step;
|
||||
pat->c.ascii.letter = pat->c.ascii.min = min_c;
|
||||
pat->c.ascii.max = max_c;
|
||||
pat->c.ascii.letter = pat->c.ascii.min = (unsigned char)min_c;
|
||||
pat->c.ascii.max = (unsigned char)max_c;
|
||||
|
||||
if(multiply(amount, (((pat->c.ascii.max - pat->c.ascii.min) /
|
||||
pat->c.ascii.step) + 1)))
|
||||
|
||||
@ -83,7 +83,7 @@ int cgetopt(int argc, const char * const argv[], const char *optstring)
|
||||
}
|
||||
else {
|
||||
const char *opt = strchr(optstring, arg[optpos]);
|
||||
coptopt = arg[optpos];
|
||||
coptopt = (unsigned char)arg[optpos];
|
||||
if(!opt) {
|
||||
if(!arg[++optpos]) {
|
||||
coptind++;
|
||||
|
||||
@ -503,7 +503,7 @@ static curl_socket_t mqttit(curl_socket_t fd)
|
||||
conn_flags = buffer[7];
|
||||
|
||||
start_usr = client_id_offset + payload_len;
|
||||
if(usr_flag == (unsigned char)(conn_flags & usr_flag)) {
|
||||
if(usr_flag == (conn_flags & usr_flag)) {
|
||||
logmsg("User flag is present in CONN flag");
|
||||
payload_len += (size_t)(buffer[start_usr] << 8) |
|
||||
buffer[start_usr + 1];
|
||||
@ -511,7 +511,7 @@ static curl_socket_t mqttit(curl_socket_t fd)
|
||||
}
|
||||
|
||||
start_passwd = client_id_offset + payload_len;
|
||||
if(passwd_flag == (char)(conn_flags & passwd_flag)) {
|
||||
if(passwd_flag == (conn_flags & passwd_flag)) {
|
||||
logmsg("Password flag is present in CONN flags");
|
||||
payload_len += (size_t)(buffer[start_passwd] << 8) |
|
||||
buffer[start_passwd + 1];
|
||||
|
||||
@ -359,7 +359,7 @@ static void read_ahead(struct testcase *test,
|
||||
}
|
||||
else {
|
||||
if(test->rcount) {
|
||||
c = test->rptr[0];
|
||||
c = (unsigned char)test->rptr[0];
|
||||
test->rptr++;
|
||||
test->rcount--;
|
||||
}
|
||||
@ -451,7 +451,7 @@ static ssize_t write_behind(struct testcase *test, int convert)
|
||||
p = writebuf;
|
||||
ct = count;
|
||||
while(ct--) { /* loop over the buffer */
|
||||
c = *p++; /* pick up a character */
|
||||
c = (unsigned char)*p++; /* pick up a character */
|
||||
if(prevchar == '\r') { /* if prev char was cr */
|
||||
if(c == '\n') /* if have cr,lf then just */
|
||||
curl_lseek(test->ofile, -1, SEEK_CUR); /* smash lf on top of the cr */
|
||||
|
||||
Loading…
Reference in New Issue
Block a user