Skip to content

Commit

Permalink
misc: fix char-subscripts warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
perigoso authored and dragonmux committed Aug 14, 2023
1 parent 14f2882 commit d5c3fb3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
15 changes: 8 additions & 7 deletions src/gdb_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -596,16 +596,16 @@ static void handle_v_packet(char *packet, const size_t plen)
} else
gdb_putpacketz("E01");

} else if (!strncmp(packet, "vKill;", 6)) {
} else if (!strncmp(packet, "vKill;", 6U)) {
/* Kill the target - we don't actually care about the PID that follows "vKill;" */
handle_kill_target();
gdb_putpacketz("OK");

} else if (!strncmp(packet, "vRun", 4)) {
} else if (!strncmp(packet, "vRun", 4U)) {
/* Parse command line for get_cmdline semihosting call */
char cmdline[83];
char *pcmdline = cmdline;
char *tok = packet + 4;
char *tok = packet + 4U;
if (*tok == ';')
++tok;
cmdline[0] = '\0';
Expand All @@ -618,14 +618,15 @@ static void handle_v_packet(char *packet, const size_t plen)
tok++;
continue;
}
if (isxdigit(tok[0]) && isxdigit(tok[1])) {
unhexify(pcmdline, tok, 2);
/* isxdigit expects int, to handle EOF */
if (isxdigit((int8_t)tok[0U]) && isxdigit((int8_t)tok[1U])) {
unhexify(pcmdline, tok, 2U);
if ((*pcmdline == ' ') || (*pcmdline == '\\')) {
pcmdline[1] = *pcmdline;
pcmdline[1U] = *pcmdline;
*pcmdline++ = '\\';
}
pcmdline++;
tok += 2;
tok += 2U;
pcmdline[0] = '\0';
continue;
}
Expand Down
20 changes: 11 additions & 9 deletions src/morse.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
#include "morse.h"

/* Morse code patterns and lengths */
static const struct {
typedef struct {
uint16_t code;
uint8_t bits;
} morse_letter[] = {
} morse_char_s;

static const morse_char_s morse_char_lut[] = {
{0b0000000000011101, 8}, // 'A' .-
{0b0000000101010111, 12}, // 'B' -...
{0b0000010111010111, 14}, // 'C' -.-.
Expand Down Expand Up @@ -79,20 +81,20 @@ bool morse_update(void)
return false;

if (!bits) {
char c = morse_msg[msg_index++];
if (!c) {
char morse_char = morse_msg[msg_index++];
if (!morse_char) {
if (morse_repeat) {
c = morse_msg[0];
morse_char = morse_msg[0];
msg_index = 1U;
} else {
msg_index = SIZE_MAX;
return false;
}
}
if (c >= 'A' && c <= 'Z') {
c -= 'A';
code = morse_letter[c].code;
bits = morse_letter[c].bits;
if (morse_char >= 'A' && morse_char <= 'Z') {
const uint8_t morse_char_index = (uint8_t)morse_char - 'A';
code = morse_char_lut[morse_char_index].code;
bits = morse_char_lut[morse_char_index].bits;
} else {
code = 0U;
bits = 4U;
Expand Down

0 comments on commit d5c3fb3

Please sign in to comment.