Never pass a signed char to ctype macros like isdigit()

Bug: None
Change-Id: I451bb2c1f175a77aefbc8363009bf35a769fe941
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/264442
Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#37037}
This commit is contained in:
Niels Möller
2022-05-30 12:57:41 +02:00
committed by WebRTC LUCI CQ
parent c85e473740
commit e66b83f8ad
13 changed files with 11 additions and 16 deletions

View File

@ -10,7 +10,6 @@
#include "examples/peerconnection/server/data_socket.h"
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

View File

@ -286,7 +286,7 @@ int main(int argc, char* argv[]) {
/* Packet loss test */
if (!strcmp("-PL", argv[i])) {
if (isdigit(*argv[i + 1])) {
if (isdigit(static_cast<unsigned char>(*argv[i + 1]))) {
packetLossPercent = atoi(argv[i + 1]);
if ((packetLossPercent < 0) | (packetLossPercent > 100)) {
printf("\nInvalid packet loss perentage \n");

View File

@ -22,7 +22,6 @@
#endif
#endif
#include <ctype.h>
#include <math.h>
/* include API */

View File

@ -62,7 +62,9 @@ int16_t PCMFile::ChooseFile(std::string* file_name,
int16_t n = 0;
// Removing trailing spaces.
while ((isspace(tmp_name[n]) || iscntrl(tmp_name[n])) && (tmp_name[n] != 0) &&
while ((isspace(static_cast<unsigned char>(tmp_name[n])) ||
iscntrl(static_cast<unsigned char>(tmp_name[n]))) &&
(static_cast<unsigned char>(tmp_name[n]) != 0) &&
(n < MAX_FILE_NAME_LENGTH_BYTE)) {
n++;
}
@ -73,7 +75,9 @@ int16_t PCMFile::ChooseFile(std::string* file_name,
// Removing trailing spaces.
n = (int16_t)(strlen(tmp_name) - 1);
if (n >= 0) {
while ((isspace(tmp_name[n]) || iscntrl(tmp_name[n])) && (n >= 0)) {
while ((isspace(static_cast<unsigned char>(tmp_name[n])) ||
iscntrl(static_cast<unsigned char>(tmp_name[n]))) &&
(n >= 0)) {
n--;
}
}

View File

@ -10,7 +10,6 @@
#include "TwoWayCommunication.h"
#include <ctype.h>
#include <stdio.h>
#include <string.h>

View File

@ -10,7 +10,6 @@
#include "modules/audio_coding/test/iSACTest.h"
#include <ctype.h>
#include <stdio.h>
#include <string.h>

View File

@ -11,7 +11,6 @@
#include "modules/desktop_capture/win/full_screen_win_application_handler.h"
#include <algorithm>
#include <cwctype>
#include <memory>
#include <string>
#include <vector>

View File

@ -10,7 +10,6 @@
#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
#include <ctype.h>
#include <string.h>
#include <type_traits>

View File

@ -92,7 +92,7 @@ static bool GetServiceTypeAndHostnameFromUri(const std::string& in_str,
static bool ParsePort(const std::string& in_str, int* port) {
// Make sure port only contains digits. FromString doesn't check this.
for (const char& c : in_str) {
if (!std::isdigit(c)) {
if (!std::isdigit(static_cast<unsigned char>(c))) {
return false;
}
}

View File

@ -77,7 +77,7 @@ bool IsRtpProtocol(absl::string_view protocol) {
return false;
}
// RTP must be at the beginning of a string or not preceded by alpha
if (pos == 0 || !isalpha(protocol[pos - 1])) {
if (pos == 0 || !isalpha(static_cast<unsigned char>(protocol[pos - 1]))) {
return true;
}
return false;

View File

@ -10,7 +10,6 @@
#include "pc/rtc_stats_collector.h"
#include <ctype.h>
#include <stddef.h>
#include <stdint.h>

View File

@ -24,7 +24,7 @@ absl::optional<signed_type> ParseSigned(absl::string_view str, int base) {
if (str.empty())
return absl::nullopt;
if (isdigit(str[0]) || str[0] == '-') {
if (isdigit(static_cast<unsigned char>(str[0])) || str[0] == '-') {
std::string str_str = std::string(str);
char* end = nullptr;
errno = 0;
@ -42,7 +42,7 @@ absl::optional<unsigned_type> ParseUnsigned(absl::string_view str, int base) {
if (str.empty())
return absl::nullopt;
if (isdigit(str[0]) || str[0] == '-') {
if (isdigit(static_cast<unsigned char>(str[0])) || str[0] == '-') {
std::string str_str = std::string(str);
// Explicitly discard negative values. std::strtoull parsing causes unsigned
// wraparound. We cannot just reject values that start with -, though, since

View File

@ -11,8 +11,6 @@
#ifndef RTC_BASE_STRING_UTILS_H_
#define RTC_BASE_STRING_UTILS_H_
#include <ctype.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>