From 1fc46997ebb8933951c13a9afc99e66c932c4b52 Mon Sep 17 00:00:00 2001 From: Slava Monich Date: Thu, 15 Oct 2015 17:20:52 +0300 Subject: [PATCH] [app] Fixed gcc 4.8 warning "iteration 1u invokes undefined behavior" --- app/stubs/libexpat.c | 22 +++++++++++----------- app/stubs/libmagic.c | 22 +++++++++++----------- app/stubs/libudev.c | 22 +++++++++++----------- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/app/stubs/libexpat.c b/app/stubs/libexpat.c index 2b2b9c6..df23067 100644 --- a/app/stubs/libexpat.c +++ b/app/stubs/libexpat.c @@ -70,6 +70,16 @@ (XML_Parser parser, const char* s, int len, int isFinal), \ (parser, s, len, isFinal), XML_STATUS_ERROR) +#define EXPAT_NUM_FUNCTIONS (sizeof(expat_names)/sizeof(expat_names[0])) +#define EXPAT_NO_HANDLE ((void*)-1) +#define EXPAT_SO "/usr/lib/libexpat.so.1" + +static const char* expat_names[] = { + "XML_ParserCreate", + #define FN_NAME(type,name,params,args,fail) #name, + EXPAT_FUNCTIONS(FN_NAME) +}; + static struct { void* handle; union { @@ -78,20 +88,10 @@ static struct { #define FN_POINTER(type,name,params,args,fail) type (* name) params; EXPAT_FUNCTIONS(FN_POINTER) } expat; - void* entry[1]; + void* entry[EXPAT_NUM_FUNCTIONS]; } fn; } expat; -static const char* expat_names[] = { - "XML_ParserCreate", - #define FN_NAME(type,name,params,args,fail) #name, - EXPAT_FUNCTIONS(FN_NAME) -}; - -#define EXPAT_NUM_FUNCTIONS (sizeof(expat_names)/sizeof(expat_names[0])) -#define EXPAT_NO_HANDLE ((void*)-1) -#define EXPAT_SO "/usr/lib/libexpat.so.1" - /* XML_ParserCreate() is the special function where we load the library */ XML_Parser XML_ParserCreate( diff --git a/app/stubs/libmagic.c b/app/stubs/libmagic.c index 53d6b60..c8e6e97 100644 --- a/app/stubs/libmagic.c +++ b/app/stubs/libmagic.c @@ -43,6 +43,16 @@ f(const char*, magic_file, \ (magic_t cookie, const char* path), (cookie, path), NULL) +#define MAGIC_NUM_FUNCTIONS (sizeof(magic_names)/sizeof(magic_names[0])) +#define MAGIC_NO_HANDLE ((void*)-1) +#define MAGIC_SO "/usr/lib/libmagic.so.1" + +static const char* magic_names[] = { + "magic_open", + #define FN_NAME(type,name,params,args,fail) #name, + MAGIC_FUNCTIONS(FN_NAME) +}; + static struct { void* handle; union { @@ -51,20 +61,10 @@ static struct { #define FN_POINTER(type,name,params,args,fail) type (* name) params; MAGIC_FUNCTIONS(FN_POINTER) } magic; - void* entry[1]; + void* entry[MAGIC_NUM_FUNCTIONS]; } fn; } magic; -static const char* magic_names[] = { - "magic_open", - #define FN_NAME(type,name,params,args,fail) #name, - MAGIC_FUNCTIONS(FN_NAME) -}; - -#define MAGIC_NUM_FUNCTIONS (sizeof(magic_names)/sizeof(magic_names[0])) -#define MAGIC_NO_HANDLE ((void*)-1) -#define MAGIC_SO "/usr/lib/libmagic.so.1" - /* magic_open() is the special function where we load the library */ magic_t magic_open(int flags) { diff --git a/app/stubs/libudev.c b/app/stubs/libudev.c index 87f20cb..def75bb 100644 --- a/app/stubs/libudev.c +++ b/app/stubs/libudev.c @@ -76,6 +76,16 @@ (struct udev_device* dev), \ (dev)) +#define LIBUDEV_NUM_FUNCTIONS (sizeof(libudev_names)/sizeof(libudev_names[0])) +#define LIBUDEV_NO_HANDLE ((void*)-1) +#define LIBUDEV_SO "/usr/lib/libudev.so.1" + +static const char* libudev_names[] = { + "udev_new", + #define FN_NAME(ret,name,params,args) #name, + LIBUDEV_FUNCTIONS(FN_NAME) +}; + static struct { void* handle; union { @@ -84,20 +94,10 @@ static struct { #define FN_POINTER(ret,name,params,args) ret (* name) params; LIBUDEV_FUNCTIONS(FN_POINTER) } udev; - void* entry[1]; + void* entry[LIBUDEV_NUM_FUNCTIONS]; } fn; } libudev; -static const char* libudev_names[] = { - "udev_new", - #define FN_NAME(ret,name,params,args) #name, - LIBUDEV_FUNCTIONS(FN_NAME) -}; - -#define LIBUDEV_NUM_FUNCTIONS (sizeof(libudev_names)/sizeof(libudev_names[0])) -#define LIBUDEV_NO_HANDLE ((void*)-1) -#define LIBUDEV_SO "/usr/lib/libudev.so.1" - /* udev_new() is the special function where we load the library */ struct udev* udev_new()