Fix build issue on MSYS2 and Cygwin

The is* macros on MSYS2 (native) and Cygwin are implemented as table
lookups and expect values representable as 'unsigned char'. Passing a
signed char can lead to negative array indices and compile-time
errors (-Werror=char-subscripts).

Add explicit casts to 'unsigned char' to all affected is* calls, as
recommended by the ISALPHA(3) manual page.

Example error message on Cygwin:

../src/helper/log.c: In function ‘find_nonprint_char’:
../src/helper/log.c:525:33: error: array subscript has type ‘char’ [-Werror=char-subscripts]
  525 |                 if (!isprint(buf[i]))

Change-Id: I9c7a5cc1085e15fed0f3f974ec943abad44e68a0
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: https://review.openocd.org/c/openocd/+/9478
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
This commit is contained in:
Marc Schink
2026-02-26 05:56:57 -08:00
committed by Antonio Borneo
parent a22e4331e7
commit 232cd0b0f1
6 changed files with 12 additions and 8 deletions
+1 -1
View File
@@ -526,7 +526,7 @@ void log_socket_error(const char *socket_desc)
const char *find_nonprint_char(const char *buf, unsigned int buf_len)
{
for (unsigned int i = 0; i < buf_len; i++) {
if (!isprint(buf[i]))
if (!isprint((unsigned char)buf[i]))
return buf + i;
}
return NULL;
+1 -1
View File
@@ -970,7 +970,7 @@ COMMAND_HANDLER(adapter_gpio_config_handler)
while (i < CMD_ARGC) {
LOG_DEBUG("Processing %s", CMD_ARGV[i]);
if (isdigit(*CMD_ARGV[i])) {
if (isdigit((unsigned char)*CMD_ARGV[i])) {
COMMAND_PARSE_NUMBER(uint, CMD_ARGV[i], gpio_config->gpio_num);
++i;
continue;
+2 -1
View File
@@ -82,7 +82,8 @@ static int efinix_read_bit_file(struct raw_bit_file *bit_file, const char *filen
return ERROR_PLD_FILE_LOAD_FAILED;
}
if (!isxdigit(buffer[0]) || !isxdigit(buffer[1])) {
if (!isxdigit((unsigned char)buffer[0]) ||
!isxdigit((unsigned char)buffer[1])) {
fclose(input_file);
free(bit_file->data);
bit_file->data = NULL;
+2 -1
View File
@@ -57,7 +57,8 @@ static int gatemate_read_cfg_line(struct gatemate_bit_file *bit_file, const char
} else if (line_buffer[idx] == 0) {
break;
} else if (idx + 1 < nread) {
if (isxdigit(line_buffer[idx]) && isxdigit(line_buffer[idx + 1])) {
if (isxdigit((unsigned char)line_buffer[idx]) &&
isxdigit((unsigned char)line_buffer[idx + 1])) {
uint8_t byte;
unhexify(&byte, line_buffer + idx, 2);
int retval = gatemate_add_byte_to_bitfile(bit_file, byte);
+5 -3
View File
@@ -602,7 +602,8 @@ static void telnet_auto_complete(struct connection *connection)
/* user command position in the line, ignore leading spaces */
size_t usr_cmd_pos = seq_start;
while ((usr_cmd_pos < t_con->line_cursor) && isspace(t_con->line[usr_cmd_pos]))
while ((usr_cmd_pos < t_con->line_cursor) &&
isspace((unsigned char)t_con->line[usr_cmd_pos]))
usr_cmd_pos++;
/* check user command length */
@@ -616,9 +617,10 @@ static void telnet_auto_complete(struct connection *connection)
* because info commands does not tolerate multiple spaces */
size_t optimized_spaces = 0;
char query[usr_cmd_len + 1];
for (size_t i = 0; i < usr_cmd_len; i++) {
if ((i < usr_cmd_len - 1) && isspace(t_con->line[usr_cmd_pos + i])
&& isspace(t_con->line[usr_cmd_pos + i + 1])) {
if ((i < usr_cmd_len - 1) && isspace((unsigned char)t_con->line[usr_cmd_pos + i])
&& isspace((unsigned char)t_con->line[usr_cmd_pos + i + 1])) {
optimized_spaces++;
continue;
}
+1 -1
View File
@@ -4380,7 +4380,7 @@ static bool parse_csr_address(const char *reg_address_str, unsigned int *reg_add
{
*reg_addr = -1;
/* skip initial spaces */
while (isspace(reg_address_str[0]))
while (isspace((unsigned char)reg_address_str[0]))
++reg_address_str;
/* try to detect if string starts with 0x or 0X */
bool is_hex_address = strncmp(reg_address_str, "0x", 2) == 0 ||