Skip to content

Commit

Permalink
Fix printing of byte sequences
Browse files Browse the repository at this point in the history
  • Loading branch information
Rot127 committed Jun 26, 2024
1 parent b15e539 commit 450e9aa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion suite/cstest/src/test_case.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ TestInput *test_input_clone(TestInput *test_input)
}
ti->arch = cs_strdup(test_input->arch);
ti->bytes = cs_mem_calloc(sizeof(uint8_t), test_input->bytes_count);
ti->bytes_count = test_input->bytes_count;
memcpy(ti->bytes, test_input->bytes, test_input->bytes_count);
return ti;
}

char *test_input_stringify(const TestInput *test_input, const char *postfix)
{
size_t msg_len = 256;
size_t msg_len = 1024;
char *msg = cs_mem_calloc(sizeof(char), msg_len);
char *byte_seq =
byte_seq_to_str(test_input->bytes, test_input->bytes_count);
Expand Down
8 changes: 4 additions & 4 deletions utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ void append_to_str(char *str, size_t str_size, const char *src) {
/// form: 0xXX,0xXX...
char *byte_seq_to_str(uint8_t *bytes, size_t len)
{
size_t byte_format_len = strlen("0xXX,");
size_t str_len = (len * byte_format_len) + 1;
char *s = calloc(sizeof(char), str_len);
char single_byte[8] = { 0 };
char *s = calloc(sizeof(char), 256);
for (size_t i = 0; i < len; ++i) {
cs_snprintf(s + (byte_format_len * i), len, "0x%" PRIx8 "%s",
cs_snprintf(single_byte, sizeof(single_byte), "0x%02" PRIx8 "%s",
bytes[i], i < len - 1 ? "," : "");
append_to_str(s, 256, single_byte);
}
return s;
}

0 comments on commit 450e9aa

Please sign in to comment.