diff --git a/Makefile.am b/Makefile.am index 32df79d..781ee67 100644 --- a/Makefile.am +++ b/Makefile.am @@ -3,3 +3,5 @@ ACLOCAL_AMFLAGS=-I m4 SUBDIRS=src test EXTRA_DIST=autogen.mk test: check + + diff --git a/src/Makefile.am b/src/Makefile.am index f86d4f8..fd9a2de 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -3,4 +3,10 @@ includedir=$(prefix)/include/blobpack/ lib_LTLIBRARIES=libblobpack.la include_HEADERS=blobpack.h blob.h blob_field.h blob_json.h utils.h libblobpack_la_SOURCES=blob.c blob_field.c blob_json.c blob_ujson.c ujsondec.c ujsonenc.c utils.c -libblobpack_la_CFLAGS=$(CODE_COVERAGE_CFLAGS) -std=gnu99 -Wall -Werror +libblobpack_la_CFLAGS=$(CODE_COVERAGE_CFLAGS) -std=gnu99 -Wall -Werror -Wno-format-y2k -W -Wstrict-prototypes -Wmissing-prototypes \ +-Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch \ +-Wshadow -Wcast-align -Wchar-subscripts -Winline \ +-Wnested-externs -Wredundant-decls -Wmissing-field-initializers -Wextra \ +-Wformat=2 -Wno-format-nonliteral -Wpointer-arith -Wno-missing-braces \ +-Wno-unused-parameter -Wno-unused-variable -Wno-inline + diff --git a/src/Makefile.in b/src/Makefile.in index 9ac0bb6..0534dc2 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -323,7 +323,13 @@ top_srcdir = @top_srcdir@ lib_LTLIBRARIES = libblobpack.la include_HEADERS = blobpack.h blob.h blob_field.h blob_json.h utils.h libblobpack_la_SOURCES = blob.c blob_field.c blob_json.c blob_ujson.c ujsondec.c ujsonenc.c utils.c -libblobpack_la_CFLAGS = $(CODE_COVERAGE_CFLAGS) -std=gnu99 -Wall -Werror +libblobpack_la_CFLAGS = $(CODE_COVERAGE_CFLAGS) -std=gnu99 -Wall -Werror -Wno-format-y2k -W -Wstrict-prototypes -Wmissing-prototypes \ +-Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch \ +-Wshadow -Wcast-align -Wchar-subscripts -Winline \ +-Wnested-externs -Wredundant-decls -Wmissing-field-initializers -Wextra \ +-Wformat=2 -Wno-format-nonliteral -Wpointer-arith -Wno-missing-braces \ +-Wno-unused-parameter -Wno-unused-variable -Wno-inline + all: all-am .SUFFIXES: diff --git a/src/blob_json.c b/src/blob_json.c index f67a4db..c60c5b6 100644 --- a/src/blob_json.c +++ b/src/blob_json.c @@ -129,7 +129,7 @@ static bool blob_puts(struct strbuf *s, const char *c, int len) static void add_separator(struct strbuf *s) { - static char indent_chars[17] = "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"; + char indent_chars[17] = "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"; int indent; char *start; @@ -348,12 +348,12 @@ static void _blob_field_dump_json(const struct blob_field *self, int indent){ } void blob_field_dump_json(const struct blob_field *self){ - assert(self); + if(!self) return; _blob_field_dump_json(self, 0); } void blob_field_dump_json_pretty(const struct blob_field *self){ - assert(self); + if(!self) return; _blob_field_dump_json(self, 1); } diff --git a/src/blob_ujson.c b/src/blob_ujson.c index d06a0df..a42e230 100644 --- a/src/blob_ujson.c +++ b/src/blob_ujson.c @@ -200,12 +200,13 @@ bool blob_put_json_from_file(struct blob *self, const char *file){ lseek(fd, SEEK_SET, 0); char *buffer = malloc(file_size + 1); // allocate on stack memset(buffer, 0, file_size + 1); - if(file_size != read(fd, buffer, file_size)){ + int ret = 0; + if((ret = read(fd, buffer, file_size)) > 0 && (size_t)ret != file_size){ close(fd); return false; } close(fd); - int ret = blob_put_json(self, buffer); + ret = blob_put_json(self, buffer); free(buffer); return ret; } diff --git a/test/Makefile.am b/test/Makefile.am index f656eeb..c323094 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,15 +1,21 @@ @CODE_COVERAGE_RULES@ check_PROGRAMS=random read-write json parse +AM_CFLAGS=$(CODE_COVERAGE_CFLAGS) -Wall -Werror -fPIC -Wno-format-y2k -W -Wstrict-prototypes -Wmissing-prototypes \ +-Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch \ +-Wshadow -Wcast-align -Wchar-subscripts -Winline \ +-Wnested-externs -Wredundant-decls -Wmissing-field-initializers -Wextra \ +-Wformat=2 -Wno-format-nonliteral -Wpointer-arith -Wno-missing-braces \ +-Wno-unused-parameter -Wno-unused-variable -Wno-inline -I../src/ -std=c99 -D_GNU_SOURCE random_SOURCES=random.c -random_CFLAGS=$(CODE_COVERAGE_CFLAGS) -I../src/ -std=c99 +random_CFLAGS=$(AM_CFLAGS) random_LDFLAGS=$(CODE_COVERAGE_LDFLAGS) -L../src/.libs/ -lblobpack -lm read_write_SOURCES=read-write.c -read_write_CFLAGS=$(CODE_COVERAGE_CFLAGS) -I../src/ -D_GNU_SOURCE -std=c99 +read_write_CFLAGS=$(AM_CFLAGS) read_write_LDFLAGS=$(CODE_COVERAGE_LDFLAGS) -L../src/.libs/ -lblobpack -lm json_SOURCES=json.c -json_CFLAGS=$(CODE_COVERAGE_CFLAGS) -I../src/ -D_GNU_SOURCE -std=c99 +json_CFLAGS=$(AM_CFLAGS) json_LDFLAGS=$(CODE_COVERAGE_LDFLAGS) -L../src/.libs/ -lblobpack -lm parse_SOURCES=parse.c -parse_CFLAGS=$(CODE_COVERAGE_CFLAGS) -I../src/ -D_GNU_SOURCE -std=c99 +parse_CFLAGS=$(AM_CFLAGS) parse_LDFLAGS=$(CODE_COVERAGE_LDFLAGS) -L../src/.libs/ -lblobpack -lm TESTS=$(check_PROGRAMS) diff --git a/test/Makefile.in b/test/Makefile.in index f212a52..6c5bf07 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -510,17 +510,24 @@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ +AM_CFLAGS = $(CODE_COVERAGE_CFLAGS) -Wall -Werror -fPIC -Wno-format-y2k -W -Wstrict-prototypes -Wmissing-prototypes \ +-Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch \ +-Wshadow -Wcast-align -Wchar-subscripts -Winline \ +-Wnested-externs -Wredundant-decls -Wmissing-field-initializers -Wextra \ +-Wformat=2 -Wno-format-nonliteral -Wpointer-arith -Wno-missing-braces \ +-Wno-unused-parameter -Wno-unused-variable -Wno-inline -I../src/ -std=c99 -D_GNU_SOURCE + random_SOURCES = random.c -random_CFLAGS = $(CODE_COVERAGE_CFLAGS) -I../src/ -std=c99 +random_CFLAGS = $(AM_CFLAGS) random_LDFLAGS = $(CODE_COVERAGE_LDFLAGS) -L../src/.libs/ -lblobpack -lm read_write_SOURCES = read-write.c -read_write_CFLAGS = $(CODE_COVERAGE_CFLAGS) -I../src/ -D_GNU_SOURCE -std=c99 +read_write_CFLAGS = $(AM_CFLAGS) read_write_LDFLAGS = $(CODE_COVERAGE_LDFLAGS) -L../src/.libs/ -lblobpack -lm json_SOURCES = json.c -json_CFLAGS = $(CODE_COVERAGE_CFLAGS) -I../src/ -D_GNU_SOURCE -std=c99 +json_CFLAGS = $(AM_CFLAGS) json_LDFLAGS = $(CODE_COVERAGE_LDFLAGS) -L../src/.libs/ -lblobpack -lm parse_SOURCES = parse.c -parse_CFLAGS = $(CODE_COVERAGE_CFLAGS) -I../src/ -D_GNU_SOURCE -std=c99 +parse_CFLAGS = $(AM_CFLAGS) parse_LDFLAGS = $(CODE_COVERAGE_LDFLAGS) -L../src/.libs/ -lblobpack -lm TESTS = $(check_PROGRAMS) all: all-am diff --git a/test/json.c b/test/json.c index 4bc4cf3..3b1d1fa 100644 --- a/test/json.c +++ b/test/json.c @@ -4,7 +4,7 @@ #include #include -int main(){ +int main(void){ struct blob blob; blob_init(&blob, 0, 0); @@ -33,7 +33,7 @@ int main(){ blob_put_int(&blob, 5000000000lu); blob_close_array(&blob, o); - struct blob_field *out[8]; + const struct blob_field *out[8]; TEST(blob_field_parse(blob_head(&blob), "isifssta", out, 8)); char *json = blob_to_json(&blob); diff --git a/test/parse.c b/test/parse.c index 4f3f58f..09efd30 100644 --- a/test/parse.c +++ b/test/parse.c @@ -4,7 +4,7 @@ #include #include -int main(){ +int main(void){ struct blob blob; blob_init(&blob, 0, 0); @@ -13,7 +13,7 @@ int main(){ blob_put_int(&blob, -13); blob_put_real(&blob, M_PI); - struct blob_field *out[4]; + const struct blob_field *out[4]; blob_dump_json(&blob); diff --git a/test/random.c b/test/random.c index 5828b1b..c9e5a6a 100644 --- a/test/random.c +++ b/test/random.c @@ -1,4 +1,7 @@ #include "blobpack.h" +#include +#include +#include enum { FIELD_STRING, diff --git a/test/read-write.c b/test/read-write.c index e7136e6..df4196c 100644 --- a/test/read-write.c +++ b/test/read-write.c @@ -4,7 +4,7 @@ #include #include -int main(){ +int main(void){ struct blob blob; blob_init(&blob, 0, 0); char data_in[] = {1, 2, 3, 4, 5, 6, 7}; @@ -50,8 +50,8 @@ int main(){ blob_dump(&blob); - struct blob_field *root = blob_head(&blob); - struct blob_field *child = blob_field_first_child(root); + const struct blob_field *root = blob_head(&blob); + const struct blob_field *child = blob_field_first_child(root); TEST(blob_field_get_bool(child) == true); TEST(strcmp(blob_field_get_string(child = blob_field_next_child(root, child)), "foo") == 0); @@ -76,7 +76,7 @@ int main(){ // iterate over the list child = blob_field_next_child(root, child); - struct blob_field *list = child; + const struct blob_field *list = child; child = blob_field_first_child(child); TEST(strcmp(blob_field_get_string(child), "one") == 0);