[PATCH 4/4] reftable: avoid non portable compile time pointer to function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



While GNU compilers (and even MSVC) allow as an extension setting
at compile time the address of a dynamic function into a static
variables, it trigger C4232[1] with a warning for portability.

Avoid it by resolving at runtime the address that will be used
on each case, and not relying on the pointer initialization
to be honour at compile time.

[1] https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-4-c4232

Signed-off-by: Carlo Marcelo Arenas Belón <carenas@xxxxxxxxx>
---
 reftable/publicbasics.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/reftable/publicbasics.c b/reftable/publicbasics.c
index bd0a02d3f6..b5767bccc5 100644
--- a/reftable/publicbasics.c
+++ b/reftable/publicbasics.c
@@ -11,23 +11,32 @@ license that can be found in the LICENSE file or at
 #include "basics.h"
 #include "system.h"
 
-static void *(*reftable_malloc_ptr)(size_t sz) = &malloc;
-static void *(*reftable_realloc_ptr)(void *, size_t) = &realloc;
-static void (*reftable_free_ptr)(void *) = &free;
+static void *(*reftable_malloc_ptr)(size_t sz);
+static void *(*reftable_realloc_ptr)(void *, size_t);
+static void (*reftable_free_ptr)(void *);
 
 void *reftable_malloc(size_t sz)
 {
-	return (*reftable_malloc_ptr)(sz);
+	if (reftable_malloc_ptr)
+		return reftable_malloc_ptr(sz);
+	else
+		return malloc(sz);
 }
 
 void *reftable_realloc(void *p, size_t sz)
 {
-	return (*reftable_realloc_ptr)(p, sz);
+	if (reftable_realloc_ptr)
+		return reftable_realloc_ptr(p, sz);
+	else
+		return realloc(p, sz);
 }
 
 void reftable_free(void *p)
 {
-	reftable_free_ptr(p);
+	if (reftable_free_ptr)
+		reftable_free_ptr(p);
+	else
+		free(p);
 }
 
 void *reftable_calloc(size_t sz)
-- 
2.33.0.955.gee03ddbf0e




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux