Fix a sign extension bug by using unsigned bytes
This commit is contained in:
parent
64f9d10b4c
commit
8de384fa91
2
cmdbuf.c
2
cmdbuf.c
|
@ -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;
|
||||
|
|
|
@ -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
|
2
server.c
2
server.c
|
@ -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, ®_no)) return -1;
|
||||
if (!cmd_match_str(cmd, "=")) return -1;
|
||||
if (!cmd_match_hex_bytes(cmd, 4, reg_bytes)) return -1;
|
||||
|
|
Loading…
Reference in New Issue