Fix a sign extension bug by using unsigned bytes

This commit is contained in:
Simon Gellis 2024-10-07 22:26:29 -04:00
parent 64f9d10b4c
commit 8de384fa91
3 changed files with 3 additions and 3 deletions

View File

@ -31,7 +31,7 @@ bool cmd_match_hex_number(CommandBuf *cmd, uint32_t *value) {
return true;
}
bool cmd_match_hex_bytes(CommandBuf *cmd, const uint32_t count, char *value) {
bool cmd_match_hex_bytes(CommandBuf *cmd, const uint32_t count, uint8_t *value) {
if (cmd->len < (count * 2)) return false;
for (size_t i = 0; i < count; ++i) {
char hi, lo;

View File

@ -15,6 +15,6 @@ bool cmd_match_str(CommandBuf *cmd, const char *str);
/* Try to consume a base-16 number, and return the value. */
bool cmd_match_hex_number(CommandBuf *cmd, uint32_t *value);
/* Try to consume a hex-encoded list of bytes, and return the value. */
bool cmd_match_hex_bytes(CommandBuf *cmd, const uint32_t count, char *value);
bool cmd_match_hex_bytes(CommandBuf *cmd, const uint32_t count, uint8_t *value);
#endif

View File

@ -160,7 +160,7 @@ int handle_command(RdbResponse *res, CommandBuf *cmd, VB *sim, bool *running) {
if (cmd_match_str(cmd, "P")) {
// write a register.
uint32_t reg_no;
char reg_bytes[4];
uint8_t reg_bytes[4];
if (!cmd_match_hex_number(cmd, &reg_no)) return -1;
if (!cmd_match_str(cmd, "=")) return -1;
if (!cmd_match_hex_bytes(cmd, 4, reg_bytes)) return -1;