Skip to content

Commit d1a2f4b

Browse files
UCS/LOG: Fix PR comments
1 parent c1d7826 commit d1a2f4b

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

src/ucs/debug/log.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ ucs_log_print_multi_line(const char *short_file, int line,
310310
const char *line_end = first_line_end;
311311
char prefix[UCS_LOG_MULTILINE_PREFIX_SIZE];
312312
char output[UCS_LOG_MULTILINE_OUTPUT_SIZE];
313+
size_t remaining_space;
313314
int ret;
314315

315316
/* Format the log prefix once */
@@ -321,12 +322,12 @@ ucs_log_print_multi_line(const char *short_file, int line,
321322
ret = snprintf(prefix, sizeof(prefix), UCS_LOG_FMT,
322323
UCS_LOG_ARG(short_file, line, level, comp_conf, tv));
323324
}
324-
ucs_assert((ret >= 0) && ((size_t)ret < sizeof(prefix)));
325+
ucs_assertv((ret >= 0) && ((size_t)ret < sizeof(prefix)), "ret=%d", ret);
325326

326327
/* Append line by line */
327328
ucs_assert(line_end != NULL);
328329
do {
329-
size_t remaining_space = sizeof(output) - output_len;
330+
remaining_space = sizeof(output) - output_len;
330331

331332
ret = snprintf(output + output_len, remaining_space, "%s%.*s\n", prefix,
332333
(int)(line_end - line_start), line_start);
@@ -335,7 +336,7 @@ ucs_log_print_multi_line(const char *short_file, int line,
335336
if ((size_t)ret >= remaining_space) {
336337
if (output_len == 0) {
337338
/* A single line overflowed the output buffer, should never happen */
338-
ucs_fatal("log line is too long");
339+
ucs_fatal("log line is too long: %d", ret);
339340
}
340341

341342
/* Terminate the string at the previous position */

test/gtest/ucs/test_log.cc

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,8 @@ class log_test_multiline : public log_test {
391391
unsigned marker_num = 0;
392392
size_t start = first_newline + 1; /* Skip filename */
393393
size_t end;
394-
while (marker_num < m_num_lines &&
395-
(end = log_contents.find('\n', start)) != std::string::npos) {
394+
while ((marker_num < m_num_lines) &&
395+
((end = log_contents.find('\n', start)) != std::string::npos)) {
396396
std::string line = log_contents.substr(start, end - start);
397397
std::string marker = "multiline_" + ucs::to_string(marker_num);
398398

@@ -432,21 +432,18 @@ UCS_TEST_F(log_test_multiline, multiline_format) {
432432

433433
UCS_TEST_F(log_test_multiline, multiline_long) {
434434
/* Log a multiline message that exceeds the output buffer size */
435-
m_num_lines = 25;
435+
m_num_lines = 0;
436436

437-
std::string padding;
438-
padding.assign(128, 'X');
437+
std::string padding = " ";
438+
padding.append(128, 'X');
439439

440440
std::string message;
441-
for (unsigned i = 0; i < m_num_lines; i++) {
442-
if (i > 0) {
443-
message += "\n";
444-
}
445-
message += "multiline_" + ucs::to_string(i) + " " + padding;
441+
while (message.size() <= 2 * UCS_LOG_MULTILINE_OUTPUT_SIZE + 1) {
442+
message += "multiline_" + ucs::to_string(m_num_lines) + padding + "\n";
443+
m_num_lines++;
446444
}
447445

448-
ASSERT_GT(message.size(),
449-
static_cast<size_t>(UCS_LOG_MULTILINE_OUTPUT_SIZE));
446+
message.pop_back(); /* Remove the trailing newline */
450447

451448
ucs_info("%s", message.c_str());
452449
}

0 commit comments

Comments
 (0)