clang-tidy: enable `bugprone-signed-char-misuse`, fix fallouts
No binary (build failed)
—
(log yok)
| @@ -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 */ | |