Skip to content

Commit

Permalink
fixup! Audit and fix up format strings
Browse files Browse the repository at this point in the history
  • Loading branch information
bbarenblat committed Aug 3, 2022
1 parent 12a605f commit c02ce7a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/terminal/terminalframebuffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,12 @@ std::string Renditions::sgr( void ) const
} else if ( foreground_color > 37 ) { /* use 256-color set */
snprintf( col, sizeof( col ), ";38;5;%d", foreground_color - 30 );
} else { /* ANSI foreground color */
snprintf( col, sizeof( col ), ";%d", foreground_color );
// Unfortunately, some versions of GCC (notably including GCC 9.3) give
// -Wformat warnings when relying on [conv.prom] to promote
// foreground_color in calls to printf. Explicitly promote it to silence
// the warning.
int fg = foreground_color;
snprintf( col, sizeof( col ), ";%d", fg );
}
ret.append( col );
}
Expand All @@ -559,7 +564,9 @@ std::string Renditions::sgr( void ) const
} else if ( background_color > 47 ) { /* use 256-color set */
snprintf( col, sizeof( col ), ";48;5;%d", background_color - 40 );
} else { /* ANSI background color */
snprintf( col, sizeof( col ), ";%d", background_color );
// See comment above about explicit promotion; it applies here as well.
int bg = background_color;
snprintf( col, sizeof( col ), ";%d", bg );
}
ret.append( col );
}
Expand Down

0 comments on commit c02ce7a

Please sign in to comment.