misc: Correct various -Wunterminated-string-initialization warnings

-Wunterminates-string-initialization will complain if we try to shove
a "string" into a fixed array that is too small.  Sometimes this is
intentional; when you are merely using "string" as a standin for
"non-terminated sequence of bytes".  In these cases we need to mark
the "string" as "not actually a string" with an attribute.  Applies to
GCC >=8, but this warning isn't pulled in by -Wextra until GCC >= 15.

Change-Id: Ib94410a22f4587940b16cf03d539fbadc3373686
This commit is contained in:
Solomon Peachy 2025-04-21 16:38:02 -04:00
parent c65050571e
commit 180753ce0a
6 changed files with 57 additions and 49 deletions

View file

@ -184,7 +184,7 @@ void D_Display (void)
boolean viewactive = false, isborder = false; boolean viewactive = false, isborder = false;
if (nodrawers) // for comparative timing / profiling if (nodrawers) // for comparative timing / profiling
return; return;
// save the current screen if about to wipe // save the current screen if about to wipe
if ((wipe = gamestate != wipegamestate)) if ((wipe = gamestate != wipegamestate))
@ -737,7 +737,7 @@ void D_DoomMainSetup(void)
{ {
// These are the lumps that will be checked in IWAD, // These are the lumps that will be checked in IWAD,
// if any one is not present, execution will be aborted. // if any one is not present, execution will be aborted.
const char name[23][8]= const char name[23][9] =
{ {
"e2m1","e2m2","e2m3","e2m4","e2m5","e2m6","e2m7","e2m8","e2m9", "e2m1","e2m2","e2m3","e2m4","e2m5","e2m6","e2m7","e2m8","e2m9",
"e3m1","e3m3","e3m3","e3m4","e3m5","e3m6","e3m7","e3m8","e3m9", "e3m1","e3m3","e3m3","e3m4","e3m5","e3m6","e3m7","e3m8","e3m9",

View file

@ -199,7 +199,7 @@ void init_memory (void)
static struct { static struct {
enum story story_id; enum story story_id;
zword release; zword release;
zbyte serial[6]; zbyte serial[6] __NONSTRING;
} records[] = { } records[] = {
{ SHERLOCK, 21, "871214" }, { SHERLOCK, 21, "871214" },
{ SHERLOCK, 26, "880127" }, { SHERLOCK, 26, "880127" },
@ -426,7 +426,7 @@ static void free_undo (int count)
void reset_memory (void) void reset_memory (void)
{ {
if (story_fp != -1) if (story_fp != -1)
fclose (story_fp); fclose (story_fp);
story_fp = -1; story_fp = -1;

View file

@ -29,7 +29,7 @@ struct svar
int len; int len;
union union
{ {
char key_[4]; char _key[4] __NONSTRING;
un32 key; un32 key;
} k; } k;
void *ptr; void *ptr;
@ -39,10 +39,10 @@ static int ver;
static int sramblock, iramblock, vramblock; static int sramblock, iramblock, vramblock;
static int hramofs, hiofs, palofs, oamofs, wavofs; static int hramofs, hiofs, palofs, oamofs, wavofs;
struct svar svars[] = struct svar svars[] =
{ {
I4("GbSs", &ver), I4("GbSs", &ver),
I2("PC ", &PC), I2("PC ", &PC),
I2("SP ", &SP), I2("SP ", &SP),
I2("HL ", &HL), I2("HL ", &HL),
@ -57,7 +57,7 @@ struct svar svars[] =
I2("BC ", &BC), I2("BC ", &BC),
I2("DE ", &DE), I2("DE ", &DE),
I2("AF ", &AF), I2("AF ", &AF),
#endif #endif
I4("IME ", &cpu.ime), I4("IME ", &cpu.ime),
I4("ima ", &cpu.ima), I4("ima ", &cpu.ima),
I4("spd ", &cpu.speed), I4("spd ", &cpu.speed),
@ -66,17 +66,17 @@ struct svar svars[] =
I4("tim ", &cpu.tim), I4("tim ", &cpu.tim),
I4("lcdc", &cpu.lcdc), I4("lcdc", &cpu.lcdc),
I4("snd ", &cpu.snd), I4("snd ", &cpu.snd),
I1("ints", &hw.ilines), I1("ints", &hw.ilines),
I1("pad ", &hw.pad), I1("pad ", &hw.pad),
I4("cgb ", &hw.cgb), I4("cgb ", &hw.cgb),
I4("mbcm", &mbc.model), I4("mbcm", &mbc.model),
I4("romb", &mbc.rombank), I4("romb", &mbc.rombank),
I4("ramb", &mbc.rambank), I4("ramb", &mbc.rambank),
I4("enab", &mbc.enableram), I4("enab", &mbc.enableram),
I4("batt", &mbc.batt), I4("batt", &mbc.batt),
I4("rtcR", &rtc.sel), I4("rtcR", &rtc.sel),
I4("rtcL", &rtc.latch), I4("rtcL", &rtc.latch),
I4("rtcC", &rtc.carry), I4("rtcC", &rtc.carry),
@ -113,26 +113,26 @@ struct svar svars[] =
I4("S4ec", &snd.ch[3].enlen), I4("S4ec", &snd.ch[3].enlen),
I4("hdma", &hw.hdma), I4("hdma", &hw.hdma),
I4("sram", &sramblock), I4("sram", &sramblock),
I4("iram", &iramblock), I4("iram", &iramblock),
I4("vram", &vramblock), I4("vram", &vramblock),
I4("hi ", &hiofs), I4("hi ", &hiofs),
I4("pal ", &palofs), I4("pal ", &palofs),
I4("oam ", &oamofs), I4("oam ", &oamofs),
/* NOSAVE is a special code to prevent the rest of the table /* NOSAVE is a special code to prevent the rest of the table
* from being saved, used to support old stuff for backwards * from being saved, used to support old stuff for backwards
* compatibility... */ * compatibility... */
NOSAVE, NOSAVE,
/* the following are obsolete as of 0x104 */ /* the following are obsolete as of 0x104 */
I4("hram", &hramofs), I4("hram", &hramofs),
/* I4("gba ", &hw.gba), */ /* I4("gba ", &hw.gba), */
/* I4("S1sf", &snd.ch[0].swfreq), */ /* I4("S1sf", &snd.ch[0].swfreq), */
I4("wav ", &wavofs), I4("wav ", &wavofs),
R(P1), R(SB), R(SC), R(P1), R(SB), R(SC),
R(DIV), R(TIMA), R(TMA), R(TAC), R(DIV), R(TIMA), R(TMA), R(TAC),
R(IE), R(IF), R(IE), R(IF),
@ -155,7 +155,7 @@ struct svar svars[] =
I1("DMA3", &R_HDMA3), I1("DMA3", &R_HDMA3),
I1("DMA4", &R_HDMA4), I1("DMA4", &R_HDMA4),
I1("DMA5", &R_HDMA5), I1("DMA5", &R_HDMA5),
END END
}; };
@ -174,9 +174,9 @@ void loadstate(int fd)
ver = hramofs = hiofs = palofs = oamofs = wavofs = 0; ver = hramofs = hiofs = palofs = oamofs = wavofs = 0;
base_offset = lseek(fd, 0, SEEK_CUR); base_offset = lseek(fd, 0, SEEK_CUR);
read(fd,buf, 4096); read(fd,buf, 4096);
for (j = 0; header[j][0]; j++) for (j = 0; header[j][0]; j++)
{ {
for (i = 0; svars[i].ptr; i++) for (i = 0; svars[i].ptr; i++)
@ -203,23 +203,23 @@ void loadstate(int fd)
/* obsolete as of version 0x104 */ /* obsolete as of version 0x104 */
if (hramofs) memcpy(ram.hi+128, buf+hramofs, 127); if (hramofs) memcpy(ram.hi+128, buf+hramofs, 127);
if (wavofs) memcpy(ram.hi+48, buf+wavofs, 16); if (wavofs) memcpy(ram.hi+48, buf+wavofs, 16);
if (hiofs) memcpy(ram.hi, buf+hiofs, sizeof ram.hi); if (hiofs) memcpy(ram.hi, buf+hiofs, sizeof ram.hi);
if (palofs) memcpy(lcd.pal, buf+palofs, sizeof lcd.pal); if (palofs) memcpy(lcd.pal, buf+palofs, sizeof lcd.pal);
if (oamofs) memcpy(lcd.oam.mem, buf+oamofs, sizeof lcd.oam); if (oamofs) memcpy(lcd.oam.mem, buf+oamofs, sizeof lcd.oam);
lseek(fd, base_offset + (iramblock << 12), SEEK_SET); lseek(fd, base_offset + (iramblock << 12), SEEK_SET);
read(fd,ram.ibank, 4096*irl); read(fd,ram.ibank, 4096*irl);
lseek(fd, base_offset + (vramblock << 12), SEEK_SET); lseek(fd, base_offset + (vramblock << 12), SEEK_SET);
read(fd,lcd.vbank, 4096*vrl); read(fd,lcd.vbank, 4096*vrl);
lseek(fd, base_offset + (sramblock << 12), SEEK_SET); lseek(fd, base_offset + (sramblock << 12), SEEK_SET);
read(fd,ram.sbank, 4096*srl); read(fd,ram.sbank, 4096*srl);
vram_dirty(); vram_dirty();
pal_dirty(); pal_dirty();
sound_dirty(); sound_dirty();
mem_updatemap(); mem_updatemap();
} }
void savestate(int fd) void savestate(int fd)
@ -269,13 +269,13 @@ void savestate(int fd)
/* (we'll seek relative to that from now on) */ /* (we'll seek relative to that from now on) */
base_offset = lseek(fd, 0, SEEK_CUR); base_offset = lseek(fd, 0, SEEK_CUR);
write(fd,buf, 4096); write(fd,buf, 4096);
lseek(fd, base_offset + (iramblock << 12), SEEK_SET); lseek(fd, base_offset + (iramblock << 12), SEEK_SET);
write(fd,ram.ibank, 4096*irl); write(fd,ram.ibank, 4096*irl);
lseek(fd, base_offset + (vramblock << 12), SEEK_SET); lseek(fd, base_offset + (vramblock << 12), SEEK_SET);
write(fd,lcd.vbank, 4096*vrl); write(fd,lcd.vbank, 4096*vrl);
lseek(fd, base_offset + (sramblock << 12), SEEK_SET); lseek(fd, base_offset + (sramblock << 12), SEEK_SET);
write(fd,ram.sbank, 4096*srl); write(fd,ram.sbank, 4096*srl);
} }

View file

@ -56,15 +56,12 @@
/*************************************************************************** /***************************************************************************
* TODO: Implement a merge sort for files larger than the buffer * TODO: Implement a merge sort for files larger than the buffer
****************************************************************************/ ****************************************************************************/
size_t buf_size; size_t buf_size;
static char *filename; static char *filename;
static int num_entries; static int num_entries;
static char **pointers; static char **pointers;
static char *stringbuffer; static char *stringbuffer;
static char crlf[2] = "\r\n"; static char crlf[2] __NONSTRING = "\r\n";
static int bomsize; static int bomsize;
/* Compare function for sorting backwards */ /* Compare function for sorting backwards */

View file

@ -120,7 +120,7 @@ static const char default_game[9][9] =
#define MARK_SIZE 1 /* Mark width and height */ #define MARK_SIZE 1 /* Mark width and height */
#elif (LCD_HEIGHT==110) && (LCD_WIDTH==138) \ #elif (LCD_HEIGHT==110) && (LCD_WIDTH==138) \
|| (LCD_HEIGHT==128) && (LCD_WIDTH==128) || (LCD_HEIGHT==128) && (LCD_WIDTH==128)
/* iPod Mini - 138x110, 9 cells @ 10x10 with 14 border lines */ /* iPod Mini - 138x110, 9 cells @ 10x10 with 14 border lines */
/* iriver H10 5-6GB - 128x128, 9 cells @ 10x10 with 14 border lines */ /* iriver H10 5-6GB - 128x128, 9 cells @ 10x10 with 14 border lines */
#define MARK_OFFS 1 /* Pixels between border and mark */ #define MARK_OFFS 1 /* Pixels between border and mark */
@ -326,7 +326,7 @@ static void default_state(struct sudoku_state_t* state)
for (c=0;c<9;c++) { for (c=0;c<9;c++) {
state->startboard[r][c]=default_game[r][c]; state->startboard[r][c]=default_game[r][c];
state->currentboard[r][c]=default_game[r][c]; state->currentboard[r][c]=default_game[r][c];
#ifdef SUDOKU_BUTTON_POSSIBLE #ifdef SUDOKU_BUTTON_POSSIBLE
state->possiblevals[r][c]=0; state->possiblevals[r][c]=0;
#endif #endif
} }
@ -349,7 +349,7 @@ static void clear_state(struct sudoku_state_t* state)
for (c=0;c<9;c++) { for (c=0;c<9;c++) {
state->startboard[r][c]='0'; state->startboard[r][c]='0';
state->currentboard[r][c]='0'; state->currentboard[r][c]='0';
#ifdef SUDOKU_BUTTON_POSSIBLE #ifdef SUDOKU_BUTTON_POSSIBLE
state->possiblevals[r][c]=0; state->possiblevals[r][c]=0;
#endif #endif
} }
@ -382,7 +382,7 @@ static bool check_status(struct sudoku_state_t* state)
} }
} }
/* Second, check the row */ /* Second, check the row */
for (cell=0;cell<9;cell++) { for (cell=0;cell<9;cell++) {
check[cell]=0; check[cell]=0;
} }
@ -460,7 +460,7 @@ static bool load_sudoku(struct sudoku_state_t* state, char* filename)
break; break;
case '\n': case '\n':
if (valid) { if (valid) {
r++; r++;
valid=0; valid=0;
} }
c = 0; c = 0;
@ -527,11 +527,11 @@ static bool save_sudoku(struct sudoku_state_t* state)
int i; int i;
#ifdef SUDOKU_BUTTON_POSSIBLE #ifdef SUDOKU_BUTTON_POSSIBLE
int x; int x;
char line[41]="...|...|... ; \r\n"; char line[41] __NONSTRING ="...|...|... ; \r\n";
#else #else
char line[13]="...|...|...\r\n"; char line[13] __NONSTRING = "...|...|...\r\n";
#endif #endif
char sep[13]="-----------\r\n"; char sep[13]__NONSTRING = "-----------\r\n";
rb->splash(0, "Saving..."); rb->splash(0, "Saving...");
@ -630,7 +630,7 @@ static void update_cell(struct sudoku_state_t* state, int r, int c)
} }
static void display_board(struct sudoku_state_t* state) static void display_board(struct sudoku_state_t* state)
{ {
int r,c; int r,c;
#ifdef SUDOKU_BUTTON_POSSIBLE #ifdef SUDOKU_BUTTON_POSSIBLE
@ -666,7 +666,7 @@ static void display_board(struct sudoku_state_t* state)
for (r=0;r<9;r++) { for (r=0;r<9;r++) {
rb->lcd_hline(XOFS,XOFS+BOARD_WIDTH-1,YOFS+cellypos[r]-1); rb->lcd_hline(XOFS,XOFS+BOARD_WIDTH-1,YOFS+cellypos[r]-1);
rb->lcd_vline(XOFS+cellxpos[r]-1,YOFS,YOFS+BOARD_HEIGHT-1); rb->lcd_vline(XOFS+cellxpos[r]-1,YOFS,YOFS+BOARD_HEIGHT-1);
if ((r % 3)==0) { if ((r % 3)==0) {
rb->lcd_hline(XOFS,XOFS+BOARD_WIDTH-1,YOFS+cellypos[r]-2); rb->lcd_hline(XOFS,XOFS+BOARD_WIDTH-1,YOFS+cellypos[r]-2);
rb->lcd_vline(XOFS+cellxpos[r]-2,YOFS,YOFS+BOARD_HEIGHT-1); rb->lcd_vline(XOFS+cellxpos[r]-2,YOFS,YOFS+BOARD_HEIGHT-1);
} }
@ -1021,7 +1021,7 @@ static void move_cursor(struct sudoku_state_t* state, int newx, int newy)
/* Redraw current and old cells */ /* Redraw current and old cells */
update_cell(state,oldx,oldy); update_cell(state,oldx,oldy);
update_cell(state,newx,newy); update_cell(state,newx,newy);
} }
/* plugin entry point */ /* plugin entry point */
@ -1036,7 +1036,7 @@ enum plugin_status plugin_start(const void* parameter)
int rc = PLUGIN_OK; int rc = PLUGIN_OK;
long ticks; long ticks;
struct sudoku_state_t state; struct sudoku_state_t state;
#if defined(HAVE_LCD_COLOR) || defined(SUDOKU_BUTTON_POSSIBLE) #if defined(HAVE_LCD_COLOR) || defined(SUDOKU_BUTTON_POSSIBLE)
configfile_load(cfg_filename, disk_config, configfile_load(cfg_filename, disk_config,
sizeof(disk_config) / sizeof(disk_config[0]), sizeof(disk_config) / sizeof(disk_config[0]),
@ -1065,7 +1065,7 @@ enum plugin_status plugin_start(const void* parameter)
} }
} }
display_board(&state); display_board(&state);
/* The main game loop */ /* The main game loop */
@ -1111,7 +1111,7 @@ enum plugin_status plugin_start(const void* parameter)
/* Increment digit */ /* Increment digit */
ticks=*rb->current_tick; ticks=*rb->current_tick;
if (state.editmode) { if (state.editmode) {
if (state.startboard[state.y][state.x]=='9') { if (state.startboard[state.y][state.x]=='9') {
state.startboard[state.y][state.x]='0'; state.startboard[state.y][state.x]='0';
state.currentboard[state.y][state.x]='0'; state.currentboard[state.y][state.x]='0';
} else { } else {
@ -1120,7 +1120,7 @@ enum plugin_status plugin_start(const void* parameter)
} }
} else { } else {
if (state.startboard[state.y][state.x]=='0') { if (state.startboard[state.y][state.x]=='0') {
if (state.currentboard[state.y][state.x]=='9') { if (state.currentboard[state.y][state.x]=='9') {
state.currentboard[state.y][state.x]='0'; state.currentboard[state.y][state.x]='0';
} else { } else {
state.currentboard[state.y][state.x]++; state.currentboard[state.y][state.x]++;
@ -1141,7 +1141,7 @@ enum plugin_status plugin_start(const void* parameter)
/* Decrement digit */ /* Decrement digit */
ticks=*rb->current_tick; ticks=*rb->current_tick;
if (state.editmode) { if (state.editmode) {
if (state.startboard[state.y][state.x]=='0') { if (state.startboard[state.y][state.x]=='0') {
state.startboard[state.y][state.x]='9'; state.startboard[state.y][state.x]='9';
state.currentboard[state.y][state.x]='9'; state.currentboard[state.y][state.x]='9';
} else { } else {
@ -1150,7 +1150,7 @@ enum plugin_status plugin_start(const void* parameter)
} }
} else { } else {
if (state.startboard[state.y][state.x]=='0') { if (state.startboard[state.y][state.x]=='0') {
if (state.currentboard[state.y][state.x]=='0') { if (state.currentboard[state.y][state.x]=='0') {
state.currentboard[state.y][state.x]='9'; state.currentboard[state.y][state.x]='9';
} else { } else {
state.currentboard[state.y][state.x]--; state.currentboard[state.y][state.x]--;
@ -1186,7 +1186,7 @@ enum plugin_status plugin_start(const void* parameter)
} }
} }
break; break;
/* move cursor right */ /* move cursor right */
case SUDOKU_BUTTON_RIGHT: case SUDOKU_BUTTON_RIGHT:
case (SUDOKU_BUTTON_RIGHT | BUTTON_REPEAT): case (SUDOKU_BUTTON_RIGHT | BUTTON_REPEAT):
@ -1219,7 +1219,7 @@ enum plugin_status plugin_start(const void* parameter)
case (SUDOKU_BUTTON_UP | BUTTON_REPEAT): case (SUDOKU_BUTTON_UP | BUTTON_REPEAT):
if (state.y==0) { if (state.y==0) {
move_cursor(&state,state.x,8); move_cursor(&state,state.x,8);
} else { } else {
move_cursor(&state,state.x,state.y-1); move_cursor(&state,state.x,state.y-1);
} }
break; break;
@ -1231,7 +1231,7 @@ enum plugin_status plugin_start(const void* parameter)
case (SUDOKU_BUTTON_DOWN | BUTTON_REPEAT): case (SUDOKU_BUTTON_DOWN | BUTTON_REPEAT):
if (state.y==8) { if (state.y==8) {
move_cursor(&state,state.x,0); move_cursor(&state,state.x,0);
} else { } else {
move_cursor(&state,state.x,state.y+1); move_cursor(&state,state.x,state.y+1);
} }
break; break;

View file

@ -1070,6 +1070,17 @@ Lyre prototype 1 */
#define ROCKBOX_STRICT_ALIGN 1 #define ROCKBOX_STRICT_ALIGN 1
#endif #endif
/* -Wunterminates-string-initialization will complain if we try to shove
a "string" into an array that is too small. Sometimes this actually
intentional, where you are merely using "string" as a standin for
"non-terminated sequence of bytes" -- in which case we need to mark
the "string" as "not actually a string" with an attribute. Applies to
GCC >=8, but this warning isn't pulled in by -Wextra until >= 15.
*/
#if __GNUC__ >= 8
#define __NONSTRING __attribute__((__nonstring__))
#endif
/* /*
* These macros are for switching on unified syntax in inline assembly. * These macros are for switching on unified syntax in inline assembly.
* Older versions of GCC emit assembly in divided syntax with no option * Older versions of GCC emit assembly in divided syntax with no option