From 77fae5c562b831c4f92038d3691264ec6c38a237 Mon Sep 17 00:00:00 2001 From: Sergey Lyubka Date: Thu, 15 Jul 2021 02:18:32 +0100 Subject: [PATCH] Fix #1298 - shadowing struct mg_str constructor --- Makefile | 3 +-- mongoose.c | 2 +- mongoose.h | 3 +++ src/str.c | 2 +- src/str.h | 3 +++ 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 9d4f7fde..081dfa49 100644 --- a/Makefile +++ b/Makefile @@ -50,7 +50,6 @@ test++: test # Make sure we can build from an unamalgamated sources unamalgamated: $(SRCS) $(HDRS) Makefile $(CLANG) src/*.c test/unit_test.c $(CFLAGS) $(LDFLAGS) -g -o unit_test - fuzz: mongoose.c mongoose.h Makefile test/fuzz.c $(CLANG) mongoose.c test/fuzz.c $(CFLAGS) -DMG_ENABLE_LINES -DMG_ENABLE_LOG=0 -fsanitize=fuzzer,signed-integer-overflow,address $(LDFLAGS) -g -o fuzzer $(DEBUGGER) ./fuzzer @@ -96,7 +95,7 @@ linux: Makefile mongoose.c mongoose.h test/unit_test.c $(GCC) ./unit_test_gcc linux++: CC = g++ -linux++: WARN += -Wno-shadow # Ignore "hides constructor for 'struct mg_str'" +linux++: WARN += -Wno-missing-field-initializers linux++: linux linux-libs: CFLAGS += -fPIC diff --git a/mongoose.c b/mongoose.c index e33f6f0e..4f450716 100644 --- a/mongoose.c +++ b/mongoose.c @@ -3282,7 +3282,7 @@ void mg_http_serve_ssi(struct mg_connection *c, const char *root, #include -struct mg_str mg_str(const char *s) { +struct mg_str mg_str_s(const char *s) { struct mg_str str = {s, s == NULL ? 0 : strlen(s)}; return str; } diff --git a/mongoose.h b/mongoose.h index 3f6cb64e..adc4981c 100644 --- a/mongoose.h +++ b/mongoose.h @@ -459,6 +459,9 @@ struct mg_str { #define MG_NULL_STR \ { NULL, 0 } +// Using macro to avoid shadowing C++ struct constructor, see #1298 +#define mg_str(s) mg_str_s(s) + struct mg_str mg_str(const char *s); struct mg_str mg_str_n(const char *s, size_t n); int mg_lower(const char *s); diff --git a/src/str.c b/src/str.c index eb84cfdf..4f95c80c 100644 --- a/src/str.c +++ b/src/str.c @@ -1,7 +1,7 @@ #include "str.h" #include -struct mg_str mg_str(const char *s) { +struct mg_str mg_str_s(const char *s) { struct mg_str str = {s, s == NULL ? 0 : strlen(s)}; return str; } diff --git a/src/str.h b/src/str.h index 18074c5e..3d9633bf 100644 --- a/src/str.h +++ b/src/str.h @@ -11,6 +11,9 @@ struct mg_str { #define MG_NULL_STR \ { NULL, 0 } +// Using macro to avoid shadowing C++ struct constructor, see #1298 +#define mg_str(s) mg_str_s(s) + struct mg_str mg_str(const char *s); struct mg_str mg_str_n(const char *s, size_t n); int mg_lower(const char *s);