Fix #1298 - shadowing struct mg_str constructor

This commit is contained in:
Sergey Lyubka 2021-07-15 02:18:32 +01:00
parent 80fcba91c8
commit 77fae5c562
5 changed files with 9 additions and 4 deletions

View File

@ -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

View File

@ -3282,7 +3282,7 @@ void mg_http_serve_ssi(struct mg_connection *c, const char *root,
#include <stdlib.h>
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;
}

View File

@ -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);

View File

@ -1,7 +1,7 @@
#include "str.h"
#include <stdlib.h>
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;
}

View File

@ -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);