diff --git a/.travis.yml b/.travis.yml index 8d239f8d..99677bd1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,7 @@ os: compiler: - clang - gcc -script: make mg_prefix cpp test ex +script: make mg_prefix test test++ ex matrix: include: - os: linux diff --git a/Makefile b/Makefile index c60d0c59..3ad9d6c6 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ CFLAGS += -DMG_ENABLE_OPENSSL=1 -I$(OPENSSLDIR)/include LDFLAGS ?= -L$(OPENSSLDIR)/lib -lssl -lcrypto endif -all: mg_prefix cpp test ex vc98 vc2017 linux infer fuzz +all: mg_prefix test test++ ex vc98 vc2017 linux linux++ infer fuzz ex: @for X in $(EXAMPLES); do $(MAKE) -C $$X $(EXAMPLE_TARGET); done @@ -35,8 +35,8 @@ mg_prefix: mongoose.c mongoose.h $(CLANG) mongoose.c $(CFLAGS) -c -o /tmp/x.o && nm /tmp/x.o | grep ' T' | grep -v 'mg_' ; test $$? = 1 # C++ build -cpp: CLANG = g++ -Wno-deprecated -cpp: unamalgamated +test++: CLANG = g++ -Wno-deprecated +test++: unamalgamated # Make sure we can build from an unamalgamated sources unamalgamated: $(SRCS) $(HDRS) Makefile @@ -70,9 +70,13 @@ vc2017: clean Makefile mongoose.c mongoose.h test/unit_test.c linux: CFLAGS += -DMG_ENABLE_IPV6=1 -fsanitize=address,undefined linux: clean Makefile mongoose.c mongoose.h test/unit_test.c - $(GCC) gcc mongoose.c test/unit_test.c $(CFLAGS) $(LDFLAGS) -o unit_test_gcc + $(GCC) $(CC) mongoose.c test/unit_test.c $(CFLAGS) $(LDFLAGS) -o unit_test_gcc $(GCC) ./unit_test_gcc +linux++: CC=g++ +linux++: CFLAGS += -Wno-missing-field-initializers +linux++: linux + mongoose.c: $(SRCS) Makefile (cat src/license.h; echo; echo '#include "mongoose.h"' ; (for F in src/private.h src/*.c ; do echo; echo '#ifdef MG_ENABLE_LINES'; echo "#line 1 \"$$F\""; echo '#endif'; cat $$F | sed -e 's,#include ".*,,'; done))> $@ @@ -80,6 +84,6 @@ mongoose.h: $(HDRS) Makefile (cat src/license.h src/version.h ; cat src/arch.h src/arch_*.h src/config.h src/str.h src/log.h src/timer.h src/util.h src/url.h src/iobuf.h src/base64.h src/md5.h src/sha1.h src/event.h src/net.h src/http.h src/tls.h src/ws.h src/sntp.h src/mqtt.h src/dns.h | sed -e 's,#include ".*,,' -e 's,^#pragma once,,')> $@ clean: EXAMPLE_TARGET = clean -clean: $(EXAMPLES) +clean: ex rm -rf $(PROG) *.o *.dSYM unit_test* ut fuzzer *.gcov *.gcno *.gcda *.obj *.exe *.ilk *.pdb slow-unit* _CL_* infer-out diff --git a/mongoose.c b/mongoose.c index 88c77a1d..a396f0ba 100644 --- a/mongoose.c +++ b/mongoose.c @@ -1648,7 +1648,8 @@ struct mqtt_message { static void mqtt_send_header(struct mg_connection *c, uint8_t cmd, uint8_t flags, uint32_t len) { - uint8_t buf[1 + sizeof(len)] = {(cmd << 4) | flags}, *vlen = &buf[1]; + uint8_t buf[1 + sizeof(len)], *vlen = &buf[1]; + buf[0] = (cmd << 4) | flags; do { *vlen = len % 0x80; len /= 0x80; @@ -2781,7 +2782,7 @@ struct mg_str mg_str(const char *s) { return str; } -struct mg_str mg_str_n(const char *s, int n) { +struct mg_str mg_str_n(const char *s, size_t n) { struct mg_str str = {s, n}; return str; } diff --git a/mongoose.h b/mongoose.h index 652cc71d..0a829230 100644 --- a/mongoose.h +++ b/mongoose.h @@ -360,7 +360,7 @@ struct mg_str { { NULL, 0 } struct mg_str mg_str(const char *s); -struct mg_str mg_str_n(const char *s, int n); +struct mg_str mg_str_n(const char *s, size_t n); int mg_lower(const char *s); int mg_ncasecmp(const char *s1, const char *s2, size_t len); int mg_casecmp(const char *s1, const char *s2); diff --git a/src/mqtt.c b/src/mqtt.c index e3a41ee4..4167a97c 100644 --- a/src/mqtt.c +++ b/src/mqtt.c @@ -43,7 +43,8 @@ struct mqtt_message { static void mqtt_send_header(struct mg_connection *c, uint8_t cmd, uint8_t flags, uint32_t len) { - uint8_t buf[1 + sizeof(len)] = {(cmd << 4) | flags}, *vlen = &buf[1]; + uint8_t buf[1 + sizeof(len)], *vlen = &buf[1]; + buf[0] = (cmd << 4) | flags; do { *vlen = len % 0x80; len /= 0x80; diff --git a/src/str.c b/src/str.c index 18440ff8..27f3786f 100644 --- a/src/str.c +++ b/src/str.c @@ -6,7 +6,7 @@ struct mg_str mg_str(const char *s) { return str; } -struct mg_str mg_str_n(const char *s, int n) { +struct mg_str mg_str_n(const char *s, size_t n) { struct mg_str str = {s, n}; return str; } diff --git a/src/str.h b/src/str.h index 5ee638b1..18074c5e 100644 --- a/src/str.h +++ b/src/str.h @@ -12,7 +12,7 @@ struct mg_str { { NULL, 0 } struct mg_str mg_str(const char *s); -struct mg_str mg_str_n(const char *s, int n); +struct mg_str mg_str_n(const char *s, size_t n); int mg_lower(const char *s); int mg_ncasecmp(const char *s1, const char *s2, size_t len); int mg_casecmp(const char *s1, const char *s2);