Fix GCC array bounds warning when accessing g_usrvars

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6258 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
anders_k 2012-09-06 22:43:31 +00:00
parent 667a2c8cae
commit c6fdb4436d
5 changed files with 18 additions and 8 deletions

View file

@ -18,7 +18,15 @@
#include "fileform.h"
extern NSIS_STRING g_usrvars[1];
#ifdef __GNUC__
// GCC warns about array bounds when accessing g_usrvarssection[2] because it is only [1] at compile time,
// the other part of this hack is in util.c where g_usrvarsstart is initialized.
extern const NSIS_STRING*const g_usrvarsstart;
#define g_usrvars ( (NSIS_STRING*) (g_usrvarsstart) )
#else
extern NSIS_STRING g_usrvarssection[1];
#define g_usrvars g_usrvarssection
#endif
#define state_command_line g_usrvars[20]
#define state_install_directory g_usrvars[21]

View file

@ -42,12 +42,15 @@ TCHAR g_log_file[1024];
// nsis then removes the "DISCARDABLE" style from section (for safe)
#ifdef _MSC_VER
# pragma bss_seg(NSIS_VARS_SECTION)
NSIS_STRING g_usrvars[1];
NSIS_STRING g_usrvarssection[1];
# pragma bss_seg()
# pragma comment(linker, "/section:" NSIS_VARS_SECTION ",rwd")
#else
# ifdef __GNUC__
NSIS_STRING g_usrvars[1] __attribute__((section (NSIS_VARS_SECTION)));
// GCC does not treat g_usrvarssection as a bss section so we keep the size as small as possible.
// NSIS_STRING g_usrvarssection[31] is required to remove this hack but that really bloats the exehead.
char g_usrvarssection[1] __attribute__((section (NSIS_VARS_SECTION)));
const NSIS_STRING*const g_usrvarsstart = (const NSIS_STRING*const) g_usrvarssection;
# else
# error Unknown compiler. You must implement the seperate PE section yourself.
# endif