From 027ad18a8ddeb622b43e83dcc5a326124799cd85 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Mon, 26 Aug 2024 08:41:45 +0200 Subject: [PATCH] Fix several format strings This fixes five performance issues reported by Codacy: %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. %u in format string (no. 1) requires 'unsigned int' but the argument type is 'signed int'. %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. Signed-off-by: Stefan Weil --- src/ccutil/unicharset.cpp | 2 +- src/classify/clusttool.cpp | 2 +- src/viewer/scrollview.cpp | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ccutil/unicharset.cpp b/src/ccutil/unicharset.cpp index c0aea1f3e6..b29ec3b7fe 100644 --- a/src/ccutil/unicharset.cpp +++ b/src/ccutil/unicharset.cpp @@ -824,7 +824,7 @@ bool UNICHARSET::load_via_fgets( stream >> std::setw(255) >> unichar >> std::hex >> properties >> std::dec; // stream.flags(std::ios::dec); if (stream.fail()) { - fprintf(stderr, "%s:%u failed\n", __FILE__, __LINE__); + fprintf(stderr, "%s:%d failed\n", __FILE__, __LINE__); return false; } auto position = stream.tellg(); diff --git a/src/classify/clusttool.cpp b/src/classify/clusttool.cpp index 543378d6b3..de8b1f5cb8 100644 --- a/src/classify/clusttool.cpp +++ b/src/classify/clusttool.cpp @@ -277,7 +277,7 @@ void WritePrototype(FILE *File, uint16_t N, PROTOTYPE *Proto) { fprintf(File, "insignificant "); } WriteProtoStyle(File, static_cast(Proto->Style)); - fprintf(File, "%6d\n\t", Proto->NumSamples); + fprintf(File, "%6u\n\t", Proto->NumSamples); WriteNFloats(File, N, &Proto->Mean[0]); fprintf(File, "\t"); diff --git a/src/viewer/scrollview.cpp b/src/viewer/scrollview.cpp index f5336c589a..73bd3c5fc2 100644 --- a/src/viewer/scrollview.cpp +++ b/src/viewer/scrollview.cpp @@ -307,7 +307,7 @@ void ScrollView::Initialize(const char *name, int x_pos, int y_pos, int x_size, // Set up an actual Window on the client side. char message[kMaxMsgSize]; snprintf(message, sizeof(message), - "w%u = luajava.newInstance('com.google.scrollview.ui" + "w%d = luajava.newInstance('com.google.scrollview.ui" ".SVWindow','%s',%u,%u,%u,%u,%u,%u,%u)\n", window_id_, window_name_, window_id_, x_pos, y_pos, x_size, y_size, x_canvas_size, y_canvas_size); @@ -393,7 +393,7 @@ void ScrollView::SendMsg(const char *format, ...) { va_end(args); char form[kMaxMsgSize]; - snprintf(form, sizeof(form), "w%u:%s\n", window_id_, message); + snprintf(form, sizeof(form), "w%d:%s\n", window_id_, message); stream_->Send(form); } @@ -532,7 +532,7 @@ void ScrollView::AlwaysOnTop(bool b) { // Adds a message entry to the message box. void ScrollView::AddMessage(const char *message) { char form[kMaxMsgSize]; - snprintf(form, sizeof(form), "w%u:%s", window_id_, message); + snprintf(form, sizeof(form), "w%d:%s", window_id_, message); char *esc = AddEscapeChars(form); SendMsg("addMessage(\"%s\")", esc);