Skip to content

Commit

Permalink
Merge branch 'fix/log_buffer' into 'master'
Browse files Browse the repository at this point in the history
fix(log): Fixed incorrect argument type in hexdump log functions

Closes IDFGH-12312

See merge request espressif/esp-idf!29550
  • Loading branch information
0xjakob committed Mar 12, 2024
2 parents 08d1460 + 6317789 commit a88dd2b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
25 changes: 25 additions & 0 deletions components/log/host_test/log_test/main/log_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,31 @@ TEST_CASE("log buffer")
CHECK(regex_search(fix.get_print_buffer_string(), buffer_regex));
}

TEST_CASE("log bytes > 127")
{
PrintFixture fix(ESP_LOG_INFO);
const uint8_t buffer[] = {
0xff, 0x80,
};
ESP_LOG_BUFFER_HEX(TEST_TAG, buffer, sizeof(buffer));
const std::regex buffer_regex("I \\([0-9]*\\) test: ff 80", std::regex::ECMAScript);
CHECK(regex_search(fix.get_print_buffer_string(), buffer_regex));
}

TEST_CASE("log buffer dump")
{
PrintFixture fix(ESP_LOG_INFO);
const uint8_t buffer[] = {
0x00, 0x00, 0x00, 0x00, 0x05, 0x06, 0x07, 0x08,
0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8
};
ESP_LOG_BUFFER_HEXDUMP(TEST_TAG, buffer, sizeof(buffer), ESP_LOG_INFO);
const std::regex buffer_regex("I \\([0-9]*\\) test: 0x[0-9a-f]+\\s+"
"00 00 00 00 05 06 07 08 ff fe fd fc fb fa f9 f8 "
"\\s+|[\\.]{16}|", std::regex::ECMAScript);
CHECK(regex_search(fix.get_print_buffer_string(), buffer_regex));
}

TEST_CASE("rom printf")
{
PutcFixture fix;
Expand Down
6 changes: 3 additions & 3 deletions components/log/log_buffers.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void esp_log_buffer_hex_internal(const char *tag, const void *buffer, uint16_t b
}

for (int i = 0; i < bytes_cur_line; i ++) {
sprintf(hex_buffer + 3 * i, "%02x ", ptr_line[i]);
sprintf(hex_buffer + 3 * i, "%02x ", (unsigned char) ptr_line[i]);
}
ESP_LOG_LEVEL(log_level, tag, "%s", hex_buffer);
buffer += bytes_cur_line;
Expand Down Expand Up @@ -101,7 +101,7 @@ void esp_log_buffer_hexdump_internal(const char *tag, const void *buffer, uint16
const char *ptr_line;
//format: field[length]
// ADDR[10]+" "+DATA_HEX[8*3]+" "+DATA_HEX[8*3]+" |"+DATA_CHAR[8]+"|"
char hd_buffer[10 + 3 + BYTES_PER_LINE * 3 + 3 + BYTES_PER_LINE + 1 + 1];
char hd_buffer[2 + sizeof(void *) * 2 + 3 + BYTES_PER_LINE * 3 + 1 + 3 + BYTES_PER_LINE + 1 + 1];
char *ptr_hd;
int bytes_cur_line;

Expand All @@ -126,7 +126,7 @@ void esp_log_buffer_hexdump_internal(const char *tag, const void *buffer, uint16
ptr_hd += sprintf(ptr_hd, " ");
}
if (i < bytes_cur_line) {
ptr_hd += sprintf(ptr_hd, " %02x", ptr_line[i]);
ptr_hd += sprintf(ptr_hd, " %02x", (unsigned char) ptr_line[i]);
} else {
ptr_hd += sprintf(ptr_hd, " ");
}
Expand Down

0 comments on commit a88dd2b

Please sign in to comment.