summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Dolan <mu@netsoc.tcd.ie>2012-09-17 22:04:32 +0100
committerStephen Dolan <mu@netsoc.tcd.ie>2012-09-17 22:04:58 +0100
commitcbdeddbab8cd1206a04cab33fab50d1c9b55eaf7 (patch)
tree18efa91608ff811c53f0097c334b38e0e74d9dfd
parenteab9c4e587e33ed5e506c5fdc9e3094987220074 (diff)
Make the code compile with warnings-as-errors.
-Wextra found a bona-fide bug: signed/unsigned comparison in a stack overflow check.
-rw-r--r--c/Makefile2
-rw-r--r--c/builtin.c2
-rw-r--r--c/execute.c4
-rw-r--r--c/forkable_stack.h3
-rw-r--r--c/gen_utf8_tables.py2
-rw-r--r--c/jv.c2
6 files changed, 7 insertions, 8 deletions
diff --git a/c/Makefile b/c/Makefile
index c80642dc..ddd49aea 100644
--- a/c/Makefile
+++ b/c/Makefile
@@ -1,4 +1,4 @@
-CC=gcc -Wall -std=gnu99 -ggdb -Wno-unused-function
+CC=gcc -Werror -Wextra -Wall -Wno-unused-parameter -std=gnu99 -ggdb -Wno-unused-function
.PHONY: all clean
all: parsertest
diff --git a/c/builtin.c b/c/builtin.c
index ddac58f9..86951890 100644
--- a/c/builtin.c
+++ b/c/builtin.c
@@ -190,7 +190,7 @@ static bytecoded_builtin bytecoded_builtins[] = {
block builtins_bind(block b) {
- for (int i=0; i<sizeof(bytecoded_builtins)/sizeof(bytecoded_builtins[0]); i++) {
+ for (unsigned i=0; i<sizeof(bytecoded_builtins)/sizeof(bytecoded_builtins[0]); i++) {
b = block_bind(bytecoded_builtins[i](), b, OP_IS_CALL_PSEUDO);
}
return gen_cbinding(&builtins, b);
diff --git a/c/execute.c b/c/execute.c
index eba2f1df..6b0948c5 100644
--- a/c/execute.c
+++ b/c/execute.c
@@ -332,10 +332,9 @@ jv jq_next() {
int idx = jv_number_value(stack_pop().value);
stackval container = stack_pop();
- int is_array, keep_going;
+ int keep_going;
jv key, value;
if (jv_get_kind(container.value) == JV_KIND_ARRAY) {
- is_array = 1;
if (opcode == EACH) idx = 0;
else idx = idx + 1;
keep_going = idx < jv_array_length(jv_copy(container.value));
@@ -344,7 +343,6 @@ jv jq_next() {
value = jv_array_get(jv_copy(container.value), idx);
}
} else if (jv_get_kind(container.value) == JV_KIND_OBJECT) {
- is_array = 0;
if (opcode == EACH) idx = jv_object_iter(container.value);
else idx = jv_object_iter_next(container.value, idx);
keep_going = jv_object_iter_valid(container.value, idx);
diff --git a/c/forkable_stack.h b/c/forkable_stack.h
index 3128a6ca..d485d227 100644
--- a/c/forkable_stack.h
+++ b/c/forkable_stack.h
@@ -53,7 +53,8 @@ static void forkable_stack_free(struct forkable_stack* s) {
s->stk = 0;
}
-static void* forkable_stack_push(struct forkable_stack* s, size_t size) {
+static void* forkable_stack_push(struct forkable_stack* s, size_t sz_size) {
+ int size = (int)sz_size;
forkable_stack_check(s);
int curr = s->pos < s->savedlimit ? s->pos : s->savedlimit;
if (curr - size < 0) {
diff --git a/c/gen_utf8_tables.py b/c/gen_utf8_tables.py
index 9d8dc3c0..2179222d 100644
--- a/c/gen_utf8_tables.py
+++ b/c/gen_utf8_tables.py
@@ -5,7 +5,7 @@ mask = lambda n: (1 << n) - 1
def print_table(type, name, t):
assert len(t) == 256
- print "const static",type, name+"[]", "="
+ print "static const",type, name+"[]", "="
first = True
for i in range(0,len(t),16):
print (" {" if i == 0 else " ") +\
diff --git a/c/jv.c b/c/jv.c
index 51070636..2d91366b 100644
--- a/c/jv.c
+++ b/c/jv.c
@@ -387,8 +387,8 @@ static uint32_t jvp_string_length(jvp_string* s) {
}
static uint32_t jvp_string_remaining_space(jvp_string* s) {
+ assert(s->alloc_length >= jvp_string_length(s));
uint32_t r = s->alloc_length - jvp_string_length(s);
- assert(r >= 0);
return r;
}