1
0
Fork 0
forked from len0rd/rockbox

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

@ -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" },

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;

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

@ -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...");

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