From 43fe317dbe81545685807423784e945bc1ae2a74 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Thu, 3 Apr 2014 16:28:29 -0500 Subject: [PATCH] Use flexible array members for structs that end with var-sized arrays - Since Clang++, G++, and VC++ all support this extension (even though it's technically officially only part of C99), use it. It lets Clang's array- bounds checker know that these are meant to be accessed out of their so-called "bounds". --- src/r_plane.cpp | 4 ++-- src/r_plane.h | 2 +- src/stringtable.cpp | 6 +++--- src/textures/textures.h | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/r_plane.cpp b/src/r_plane.cpp index 143b302e9..6572c1f0b 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -558,8 +558,8 @@ static visplane_t *new_visplane (unsigned hash) if (check == NULL) { - check = (visplane_t *)M_Malloc (sizeof(*check) + sizeof(*check->top)*(MAXWIDTH*2)); - memset(check, 0, sizeof(*check) + sizeof(*check->top)*(MAXWIDTH*2)); + check = (visplane_t *)M_Malloc (sizeof(*check) + 3 + sizeof(*check->top)*(MAXWIDTH*2)); + memset(check, 0, sizeof(*check) + 3 + sizeof(*check->top)*(MAXWIDTH*2)); check->bottom = check->top + MAXWIDTH+2; } else if (NULL == (freetail = freetail->next)) diff --git a/src/r_plane.h b/src/r_plane.h index 7ad711bcc..231fa3ad4 100644 --- a/src/r_plane.h +++ b/src/r_plane.h @@ -63,7 +63,7 @@ struct visplane_s unsigned short *bottom; // [RH] bottom and top arrays are dynamically unsigned short pad; // allocated immediately after the - unsigned short top[3]; // visplane. + unsigned short top[]; // visplane. }; typedef struct visplane_s visplane_t; diff --git a/src/stringtable.cpp b/src/stringtable.cpp index f575dca17..47cf00fae 100644 --- a/src/stringtable.cpp +++ b/src/stringtable.cpp @@ -55,7 +55,7 @@ struct FStringTable::StringEntry StringEntry *Next; char *Name; BYTE PassNum; - char String[2]; + char String[]; }; FStringTable::FStringTable () @@ -283,7 +283,7 @@ void FStringTable::LoadLanguage (int lumpnum, DWORD code, bool exactMatch, int p } if (entry == NULL || cmpval > 0) { - entry = (StringEntry *)M_Malloc (sizeof(*entry) + strText.Len() + strName.Len()); + entry = (StringEntry *)M_Malloc (sizeof(*entry) + strText.Len() + strName.Len() + 2); entry->Next = *pentry; *pentry = entry; strcpy (entry->String, strText.GetChars()); @@ -409,7 +409,7 @@ void FStringTable::SetString (const char *name, const char *newString) size_t namelen = strlen (name); // Create a new string entry - StringEntry *entry = (StringEntry *)M_Malloc (sizeof(*entry) + newlen + namelen); + StringEntry *entry = (StringEntry *)M_Malloc (sizeof(*entry) + newlen + namelen + 2); strcpy (entry->String, newString); strcpy (entry->Name = entry->String + newlen + 1, name); entry->PassNum = 0; diff --git a/src/textures/textures.h b/src/textures/textures.h index 837c62689..da5f559ae 100644 --- a/src/textures/textures.h +++ b/src/textures/textures.h @@ -119,7 +119,7 @@ struct patch_t SWORD height; SWORD leftoffset; // pixels to the left of origin SWORD topoffset; // pixels below the origin - DWORD columnofs[8]; // only [width] used + DWORD columnofs[]; // only [width] used // the [0] is &columnofs[width] };