From c72abd8bbfe6bc80721c116c4d41f418b43c5c4f Mon Sep 17 00:00:00 2001 From: AnnaSnoeijs Date: Sat, 14 Jun 2025 23:02:26 +0200 Subject: [PATCH] Added attributes to code such that -Wformat-truncation=0 can be removed --- makefile | 2 +- ui_ncurses.c | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/makefile b/makefile index 707ac60..5d10e86 100644 --- a/makefile +++ b/makefile @@ -19,7 +19,7 @@ FLAGS += -Wall FLAGS += -Wextra FLAGS += -Werror # This flag is because of the compiler otherwise giving too much warning -FLAGS += -Wformat-truncation=0 +#FLAGS += -Wformat-truncation=0 # Compile flag for defining GITHASH to put at the end of the version string GITFLAG = -D'GITHASH=$(shell git rev-parse --short=1 HEAD)' diff --git a/ui_ncurses.c b/ui_ncurses.c index cdf0e7b..8da8914 100644 --- a/ui_ncurses.c +++ b/ui_ncurses.c @@ -71,6 +71,7 @@ void initBoard( const board_t board ){ keypad(stdscr, TRUE); nonl(); echo(); + __attribute__((assume(board.columns < 999))); for( columnsint_t column = 0; column < board.columns; column++ ){ char colnum[4]; snprintf( @@ -96,8 +97,10 @@ void initBoard( const board_t board ){ } for( rowsint_t row = 0; row < board.rows; row++ ){ char rownum[4]; + const int intToPrint = board.rows - row + FIRST_NUMBER - 1; + __attribute__((assume(intToPrint <= 256))); snprintf( - rownum, sizeof(rownum), "%2d", board.rows - row + FIRST_NUMBER - 1 + rownum, sizeof(rownum), "%2d", intToPrint ); mvaddstr( BOARD_Y + BOARD_DY * ( row + 1 ), @@ -215,8 +218,13 @@ columnsint_t askColumn( if( board.player ) addstr( "p1" ); else addstr( "p0" ); refresh(); - for(; board.height[ column ] >= board.rows; ) - column += ( column < board.columns - 1 ); + for(; board.height[ column ] >= board.rows; ){ + column++; + if( column == board.columns ){ + getch(); + return QUITCOLUMN; + } + } for(;;){ int ch = mvgetch( BOARD_Y + BOARD_DY * ( board.rows - board.height[ column ] ),