Skip to content

Commit

Permalink
Enforce C99 standard.
Browse files Browse the repository at this point in the history
  • Loading branch information
attipaci committed Sep 17, 2024
1 parent bae058f commit dcee53a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`).

Expand Down
4 changes: 2 additions & 2 deletions config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 11 additions & 1 deletion src/xchange.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/xlookup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit dcee53a

Please sign in to comment.