mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 13:53:55 -07:00
Merge pull request #1690 from Doridian/fix/x_to_buffer
Fix wrong length calcuation in *_to_buffer utilities
This commit is contained in:
commit
1048bf3d9b
1 changed files with 6 additions and 5 deletions
|
@ -164,7 +164,7 @@ void ascii_to_buffer(uint8_t *buf, const uint8_t *hex_data, const size_t hex_len
|
|||
size_t i = 0;
|
||||
for (i = 0; i < max_len; ++i, tmp++) {
|
||||
char c = hex_data[i];
|
||||
snprintf(tmp, hex_max_len - (tmp - tmp_base), "%c", ((c < 32) || (c == 127)) ? '.' : c);
|
||||
*tmp = ((c < 32) || (c == 127)) ? '.' : c;
|
||||
}
|
||||
|
||||
size_t m = (min_str_len > i) ? min_str_len : 0;
|
||||
|
@ -172,7 +172,7 @@ void ascii_to_buffer(uint8_t *buf, const uint8_t *hex_data, const size_t hex_len
|
|||
m = hex_max_len;
|
||||
|
||||
for (; i < m; i++, tmp++)
|
||||
snprintf(tmp, hex_max_len - (tmp - tmp_base), " ");
|
||||
*tmp = ' ';
|
||||
|
||||
// remove last space
|
||||
*tmp = '\0';
|
||||
|
@ -187,13 +187,14 @@ void hex_to_buffer(uint8_t *buf, const uint8_t *hex_data, const size_t hex_len,
|
|||
char *tmp = tmp_base;
|
||||
|
||||
size_t max_len = (hex_len > hex_max_len) ? hex_max_len : hex_len;
|
||||
size_t str_max_len = hex_max_len * (2 + spaces_between);
|
||||
|
||||
size_t i;
|
||||
for (i = 0; i < max_len; ++i, tmp += 2 + spaces_between) {
|
||||
snprintf(tmp, hex_max_len - (tmp - tmp_base), (uppercase) ? "%02X" : "%02x", (unsigned int) hex_data[i]);
|
||||
snprintf(tmp, str_max_len - (tmp - tmp_base), (uppercase) ? "%02X" : "%02x", (unsigned int) hex_data[i]);
|
||||
|
||||
for (size_t j = 0; j < spaces_between; j++)
|
||||
snprintf(tmp + 2 + j, hex_max_len - ((tmp + 2 + j) - tmp_base), " ");
|
||||
*(tmp + 2 + j) = ' ';
|
||||
}
|
||||
|
||||
i *= (2 + spaces_between);
|
||||
|
@ -203,7 +204,7 @@ void hex_to_buffer(uint8_t *buf, const uint8_t *hex_data, const size_t hex_len,
|
|||
m = hex_max_len;
|
||||
|
||||
for (; i < m; i++, tmp++)
|
||||
snprintf(tmp, hex_max_len - (tmp - tmp_base), " ");
|
||||
*tmp = ' ';
|
||||
|
||||
// remove last space
|
||||
*tmp = '\0';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue