Skip to content

Commit 33f6dc2

Browse files
committed
Fix compiler warnings (-Wformat-truncation=)
gcc warnings: src/viewer/scrollview.cpp:404:31: warning: ‘%s’ directive output may be truncated writing up to 4095 bytes into a region of size between 4084 and 4093 [-Wformat-truncation=] src/viewer/scrollview.cpp:572:31: warning: ‘%s’ directive output may be truncated writing up to 4095 bytes into a region of size between 4084 and 4093 [-Wformat-truncation=] Signed-off-by: Stefan Weil <[email protected]>
1 parent 2a355ea commit 33f6dc2

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/viewer/scrollview.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -394,14 +394,14 @@ void ScrollView::SendMsg(const char* format, ...) {
394394
if (!points_->empty)
395395
SendPolygon();
396396
va_list args;
397-
char message[kMaxMsgSize];
397+
char message[kMaxMsgSize - 4];
398398

399399
va_start(args, format); // variable list
400-
vsnprintf(message, kMaxMsgSize, format, args);
400+
vsnprintf(message, sizeof(message), format, args);
401401
va_end(args);
402402

403403
char form[kMaxMsgSize];
404-
snprintf(form, kMaxMsgSize, "w%u:%s\n", window_id_, message);
404+
snprintf(form, sizeof(form), "w%u:%s\n", window_id_, message);
405405

406406
stream_->Send(form);
407407
}
@@ -562,14 +562,14 @@ void ScrollView::AlwaysOnTop(bool b) {
562562
// Adds a message entry to the message box.
563563
void ScrollView::AddMessage(const char* format, ...) {
564564
va_list args;
565-
char message[kMaxMsgSize];
566-
char form[kMaxMsgSize];
565+
char message[kMaxMsgSize - 4];
567566

568567
va_start(args, format); // variable list
569-
vsnprintf(message, kMaxMsgSize, format, args);
568+
vsnprintf(message, sizeof(message), format, args);
570569
va_end(args);
571570

572-
snprintf(form, kMaxMsgSize, "w%u:%s", window_id_, message);
571+
char form[kMaxMsgSize];
572+
snprintf(form, sizeof(form), "w%u:%s", window_id_, message);
573573

574574
char* esc = AddEscapeChars(form);
575575
SendMsg("addMessage(\"%s\")", esc);

0 commit comments

Comments
 (0)