diff --git a/README.md b/README.md index e5c0029..b4fd02d 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,8 @@ prior to invoking `make`. The following build variables can be configured: - `CPPFLAGS`: C pre-processor flags, such as externally defined compiler constants. - - `CFLAGS`: Flags to pass onto the C compiler (default: `-Os -Wall`). Note, `-Iinclude` will be added automatically. + - `CFLAGS`: Flags to pass onto the C compiler (default: `-Os -Wall -std=c99`). Note, `-Iinclude` will be added + automatically. - `LDFLAGS`: Linker flags (default is `-lm`). diff --git a/config.mk b/config.mk index 5eddf24..25954f3 100644 --- a/config.mk +++ b/config.mk @@ -21,7 +21,7 @@ CC ?= gcc CPPFLAGS += -I$(INC) # Base compiler options (if not defined externally...) -CFLAGS ?= -Os -Wall +CFLAGS ?= -Os -Wall -std=c99 # Extra warnings (not supported on all compilers) #CFLAGS += -Wextra @@ -31,7 +31,7 @@ LDFLAGS ?= -lm # cppcheck options for 'check' target CHECKOPTS ?= --enable=performance,warning,portability,style --language=c \ - --error-exitcode=1 $(CHECKEXTRA) + --error-exitcode=1 --std=c99 $(CHECKEXTRA) # Exhaustive checking for newer cppcheck #CHECKOPTS += --check-level=exhaustive diff --git a/src/xchange.c b/src/xchange.c index b30057d..c98ed55 100644 --- a/src/xchange.c +++ b/src/xchange.c @@ -395,7 +395,17 @@ void xZero(void *buf, XType type, int count) { * */ char *xStringCopyOf(const char *str) { - return str ? strdup(str) : NULL; + char *copy; + int n; + + if(str == NULL) return NULL; + + n = strlen(str) + 1; + copy = (char *) malloc(n); + x_check_alloc(copy); + + memcpy(copy, str, n); + return copy; } static int TokenMatch(char *a, char *b) { diff --git a/src/xlookup.c b/src/xlookup.c index 0144196..93bdba3 100644 --- a/src/xlookup.c +++ b/src/xlookup.c @@ -55,7 +55,7 @@ static XLookupEntry *xGetLookupEntryAsync(const XLookupTable *tab, const char *k static int xLookupPutAsync(XLookupTable *tab, const char *prefix, const XField *field, XField **oldValue) { XLookupPrivate *p = (XLookupPrivate *) tab->priv; - const char *id = prefix ? xGetAggregateID(prefix, field->name) : strdup(field->name); + const char *id = prefix ? xGetAggregateID(prefix, field->name) : xStringCopyOf(field->name); long hash = xGetHash(id); XLookupEntry *e = xGetLookupEntryAsync(tab, id, hash); int idx;