always use "%s"-style format for printf()-style functions

`ncuses-6.3` added printf-style function attributes and now makes
it easier to catch cases when user input is used in palce of format
string when built with CFLAGS=-Werror=format-security:

    musikcube/cursespp/cursespp/curses_config.h:54:36:
     error: format not a string literal and no format arguments [-Werror=format-security]
       54 |     if (window && format) { wprintw(window, format, ##__VA_ARGS__); }
          |                             ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    musikcube/src/musikcube/app/window/TransportWindow.cpp:640:5: note: in expansion of macro 'checked_wprintw'
      640 |     checked_wprintw(c, shuffleLabel.c_str(

Let's wrap all the missing places with "%s" format.
This commit is contained in:
Sergei Trofimovich 2021-11-17 09:05:46 +00:00
parent 7b2b24a471
commit 1240720e27
6 changed files with 12 additions and 12 deletions

View File

@ -331,7 +331,7 @@ static size_t writePlayingFormat(
} }
ON(w, attr); ON(w, attr);
checked_wprintw(w, value.c_str()); checked_wprintw(w, "%s", value.c_str());
OFF(w, attr); OFF(w, attr);
remaining -= cols; remaining -= cols;
@ -623,7 +623,7 @@ void TransportWindow::Update(TimeMode timeMode) {
if (stopped && !this->buffering) { if (stopped && !this->buffering) {
ON(c, disabled); ON(c, disabled);
checked_wprintw(c, Strings.STOPPED.c_str()); checked_wprintw(c, "%s", Strings.STOPPED.c_str());
displayCache->Reset(); displayCache->Reset();
OFF(c, disabled); OFF(c, disabled);
} }
@ -637,7 +637,7 @@ void TransportWindow::Update(TimeMode timeMode) {
wmove(c, 0, shuffleOffset); wmove(c, 0, shuffleOffset);
Color const shuffleAttrs = this->playback.IsShuffled() ? gb : disabled; Color const shuffleAttrs = this->playback.IsShuffled() ? gb : disabled;
ON(c, shuffleAttrs); ON(c, shuffleAttrs);
checked_wprintw(c, shuffleLabel.c_str()); checked_wprintw(c, "%s", shuffleLabel.c_str());
OFF(c, shuffleAttrs); OFF(c, shuffleAttrs);
this->shufflePos.Set(shuffleOffset, (int) shuffleWidth); this->shufflePos.Set(shuffleOffset, (int) shuffleWidth);
@ -756,7 +756,7 @@ void TransportWindow::Update(TimeMode timeMode) {
wmove(c, 1, 0); /* move cursor to the second line */ wmove(c, 1, 0); /* move cursor to the second line */
ON(c, volumeAttrs); ON(c, volumeAttrs);
checked_wprintw(c, volume.c_str()); checked_wprintw(c, "%s", volume.c_str());
OFF(c, volumeAttrs); OFF(c, volumeAttrs);
if (replayGainEnabled) { if (replayGainEnabled) {
@ -778,7 +778,7 @@ void TransportWindow::Update(TimeMode timeMode) {
ON(c, repeatAttrs); ON(c, repeatAttrs);
this->repeatPos.Set(getcurx(c), (int) u8cols(repeatModeLabel)); this->repeatPos.Set(getcurx(c), (int) u8cols(repeatModeLabel));
checked_wprintw(c, repeatModeLabel.c_str()); checked_wprintw(c, "%s", repeatModeLabel.c_str());
OFF(c, repeatAttrs); OFF(c, repeatAttrs);
this->Invalidate(); this->Invalidate();

View File

@ -226,7 +226,7 @@ void DialogOverlay::Redraw() {
if (this->title.size()) { if (this->title.size()) {
wmove(c, currentY, currentX); wmove(c, currentY, currentX);
wattron(c, A_BOLD); wattron(c, A_BOLD);
checked_wprintw(c, text::Ellipsize(this->title, this->width - 4).c_str()); checked_wprintw(c, "%s", text::Ellipsize(this->title, this->width - 4).c_str());
wattroff(c, A_BOLD); wattroff(c, A_BOLD);
currentY += 2; currentY += 2;
} }
@ -234,7 +234,7 @@ void DialogOverlay::Redraw() {
if (this->message.size()) { if (this->message.size()) {
for (size_t i = 0; i < messageLines.size(); i++) { for (size_t i = 0; i < messageLines.size(); i++) {
wmove(c, currentY, currentX); wmove(c, currentY, currentX);
checked_wprintw(c, this->messageLines.at(i).c_str()); checked_wprintw(c, "%s", this->messageLines.at(i).c_str());
++currentY; ++currentY;
} }
} }

View File

@ -203,7 +203,7 @@ void InputOverlay::Redraw() {
if (this->title.size()) { if (this->title.size()) {
wmove(c, 0, 1); wmove(c, 0, 1);
wattron(c, A_BOLD); wattron(c, A_BOLD);
checked_wprintw(c, text::Align(this->title, text::AlignCenter, this->width - 4).c_str()); checked_wprintw(c, "%s", text::Align(this->title, text::AlignCenter, this->width - 4).c_str());
wattroff(c, A_BOLD); wattroff(c, A_BOLD);
} }
} }

View File

@ -328,7 +328,7 @@ void ListOverlay::UpdateContents() {
if (this->title.size()) { if (this->title.size()) {
wmove(c, currentY, currentX); wmove(c, currentY, currentX);
wattron(c, A_BOLD); wattron(c, A_BOLD);
checked_wprintw(c, text::Align(this->title, text::AlignCenter, this->width - 4).c_str()); checked_wprintw(c, "%s", text::Align(this->title, text::AlignCenter, this->width - 4).c_str());
wattroff(c, A_BOLD); wattroff(c, A_BOLD);
currentY += 2; currentY += 2;
} }

View File

@ -236,7 +236,7 @@ void ShortcutsWindow::OnRedraw() {
} }
wattron(c, keyAttrs); wattron(c, keyAttrs);
checked_wprintw(c, key.c_str()); checked_wprintw(c, "%s", key.c_str());
wattroff(c, keyAttrs); wattroff(c, keyAttrs);
remaining -= len; remaining -= len;
@ -252,7 +252,7 @@ void ShortcutsWindow::OnRedraw() {
len = remaining; len = remaining;
} }
checked_wprintw(c, value.c_str()); checked_wprintw(c, "%s", value.c_str());
remaining -= len; remaining -= len;
} }
} }

View File

@ -115,6 +115,6 @@ void ToastOverlay::OnRedraw() {
for (int i = 0; i < (int) this->titleLines.size(); i++) { for (int i = 0; i < (int) this->titleLines.size(); i++) {
wmove(c, i, 1); wmove(c, i, 1);
checked_wprintw(c, text::Ellipsize(this->titleLines[i], this->width - 4).c_str()); checked_wprintw(c, "%s", text::Ellipsize(this->titleLines[i], this->width - 4).c_str());
} }
} }