Skip to content
This repository was archived by the owner on Nov 4, 2023. It is now read-only.

Fix compiler errors introduced by newer compilers #10

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ test: capn-test
%-test.o: %-test.cpp *.h *.c *.inc
$(CXX) -g -Wall -Werror -I. $(GTEST_CFLAGS) -o $@ -c $<

capn-test: capn-test.o capn-stream-test.o compiler/test.capnp.o compiler/schema-test.o compiler/schema.capnp.o gtest-all-test.o
$(CXX) -g -Wall -Werror -I. -o $@ $^
capn-test: capn-test.o capn-stream-test.o compiler/test.capnp.o compiler/schema-test.o compiler/schema.capnp.o
$(CXX) -g -Wall -Werror -I. -lpthread -lgtest -o $@ $^
2 changes: 1 addition & 1 deletion capn-malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ capn_write_mem(struct capn *c, uint8_t *p, size_t sz, int packed)
{
struct capn_segment *seg;
struct capn_ptr root;
int i;
uint32_t i;
uint32_t headerlen;
size_t datasz;
uint32_t *header;
Expand Down
4 changes: 2 additions & 2 deletions capn-stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ int capn_deflate(struct capn_stream* s) {
continue;

default:
if (s->avail_out < 1 + sz)
if (s->avail_out < 1U + sz)
return CAPN_NEED_MORE;

*(s->next_out++) = hdr;
Expand Down Expand Up @@ -166,7 +166,7 @@ int capn_inflate(struct capn_stream* s) {
if (hdr & (1 << i))
sz++;
}
if (s->avail_in < 2 + sz)
if (s->avail_in < 2U + sz)
return CAPN_NEED_MORE;

s->next_in += 2;
Expand Down
14 changes: 5 additions & 9 deletions capn-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ TEST(WireFormat, SimpleRawDataStruct) {
EXPECT_EQ(UINT16_C(0), capn_read16(ptr, 8));
}

static const AlignedData<2> SUBSTRUCT_DEFAULT = {{0,0,0,0,1,0,0,0, 0,0,0,0,0,0,0,0}};
static const AlignedData<2> STRUCTLIST_ELEMENT_SUBSTRUCT_DEFAULT =
{{0,0,0,0,1,0,0,0, 0,0,0,0,0,0,0,0}};

static void setupStruct(struct capn *ctx) {
struct capn_ptr root = capn_root(ctx);
ASSERT_EQ(CAPN_PTR_LIST, root.type);
Expand Down Expand Up @@ -277,11 +273,11 @@ static void getSegments(struct capn *c, struct capn_segment **s, size_t num) {
ASSERT_EQ(num, c->segnum);

s[0] = c->seglist;
for (int i = 1; i < num; i++) {
for (size_t i = 1; i < num; i++) {
s[i] = s[i-1]->next;
}

for (int i = 0; i < num; i++) {
for (size_t i = 0; i < num; i++) {
EXPECT_EQ(s[i]->id, i);
}
}
Expand Down Expand Up @@ -318,7 +314,7 @@ TEST(WireFormat, StructRoundTrip_OneSegmentPerAllocation) {

struct capn ctx2;
memset(&ctx2, 0, sizeof(ctx2));
for (int i = 0; i < sizeof(segments)/sizeof(segments[0]); i++) {
for (size_t i = 0; i < sizeof(segments)/sizeof(segments[0]); i++) {
capn_append_segment(&ctx2, segments[i]);
}

Expand Down Expand Up @@ -374,7 +370,7 @@ TEST(WireFormat, StructRoundTrip_OneSegmentPerAllocation_NoTag) {

struct capn ctx2;
memset(&ctx2, 0, sizeof(ctx2));
for (int i = 0; i < sizeof(segments)/sizeof(segments[0]); i++) {
for (size_t i = 0; i < sizeof(segments)/sizeof(segments[0]); i++) {
capn_append_segment(&ctx2, segments[i]);
}

Expand Down Expand Up @@ -424,7 +420,7 @@ TEST(WireFormat, StructRoundTrip_MultipleSegmentsWithMultipleAllocations) {

struct capn ctx2;
memset(&ctx2, 0, sizeof(ctx2));
for (int i = 0; i < sizeof(segments)/sizeof(segments[0]); i++) {
for (size_t i = 0; i < sizeof(segments)/sizeof(segments[0]); i++) {
capn_append_segment(&ctx2, segments[i]);
}

Expand Down
16 changes: 9 additions & 7 deletions capn.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ static char *new_data(struct capn *c, int sz, struct capn_segment **ps) {

static struct capn_segment *lookup_segment(struct capn* c, struct capn_segment *s, uint32_t id) {
struct capn_tree **x;
struct capn_segment *y;
struct capn_segment *y = NULL;

if (s && s->id == id)
return s;
Expand All @@ -196,7 +196,6 @@ static struct capn_segment *lookup_segment(struct capn* c, struct capn_segment *

if (id < c->segnum) {
x = &c->segtree;
y = NULL;
while (*x) {
y = (struct capn_segment*) *x;
if (id == y->id) {
Expand All @@ -207,6 +206,9 @@ static struct capn_segment *lookup_segment(struct capn* c, struct capn_segment *
x = &y->hdr.link[1];
}
}
} else {
/* Otherwise `x` may be uninitialized */
return NULL;
}

s = c->lookup ? c->lookup(c->user, id) : NULL;
Expand All @@ -231,7 +233,7 @@ static struct capn_segment *lookup_segment(struct capn* c, struct capn_segment *

static uint64_t lookup_double(struct capn_segment **s, char **d, uint64_t val) {
uint64_t far, tag;
uint32_t off = (U32(val) >> 3) * 8;
size_t off = (U32(val) >> 3) * 8;
char *p;

if ((*s = lookup_segment((*s)->capn, *s, U32(val >> 32))) == NULL) {
Expand Down Expand Up @@ -266,7 +268,7 @@ static uint64_t lookup_double(struct capn_segment **s, char **d, uint64_t val) {
}

static uint64_t lookup_far(struct capn_segment **s, char **d, uint64_t val) {
uint32_t off = (U32(val) >> 3) * 8;
size_t off = (U32(val) >> 3) * 8;

if ((*s = lookup_segment((*s)->capn, *s, U32(val >> 32))) == NULL) {
return 0;
Expand Down Expand Up @@ -371,7 +373,7 @@ static capn_ptr read_ptr(struct capn_segment *s, char *d) {
e = d + ret.len * 8;
break;
case COMPOSITE_LIST:
if (d+8-s->data > s->len) {
if ((size_t)((d+8) - s->data) > s->len) {
goto err;
}

Expand All @@ -396,7 +398,7 @@ static capn_ptr read_ptr(struct capn_segment *s, char *d) {
goto err;
}

if (e - s->data > s->len)
if ((size_t)(e - s->data) > s->len)
goto err;

ret.data = d;
Expand Down Expand Up @@ -666,7 +668,7 @@ static int copy_ptr(struct capn_segment *seg, char *data, struct capn_ptr *t, st
struct capn_segment *cs = c->copylist;

/* need to allocate a struct copy */
if (!cs || cs->len + sizeof(*n) > cs->cap) {
if (!cs || cs->len + (int)sizeof(*n) > cs->cap) {
cs = c->create_local ? c->create_local(c->user, sizeof(*n)) : NULL;
if (!cs) {
/* can't allocate a copy structure */
Expand Down
6 changes: 3 additions & 3 deletions capn.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ struct capn_segment {
uint32_t id;
/* user settable */
char *data;
int len, cap;
size_t len, cap;
void *user;
};

Expand Down Expand Up @@ -261,9 +261,9 @@ void capn_reset_copy(struct capn *c);
*/
struct capn_stream {
const uint8_t *next_in;
int avail_in;
size_t avail_in;
uint8_t *next_out;
int avail_out;
size_t avail_out;
int zeros, raw;
};

Expand Down
6 changes: 3 additions & 3 deletions compiler/capnpc-c.c
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ static void define_struct(struct node *n) {
}

#if 0
Commenting out interfaces until the RPC protocol has been spec'd
/* Commenting out interfaces until the RPC protocol has been spec'd */
static int find_offset(struct str *v, int inc, uint64_t mask) {
int i, j;
union {uint64_t u; char c[8];} umask;
Expand Down Expand Up @@ -1216,7 +1216,7 @@ int main() {
fprintf(srcf, "static const capn_ptr capn_null = {CAPN_NULL};\n");

if (g_valseg.len > 8) {
fprintf(srcf, "static const uint8_t capn_buf[%d] = {", g_valseg.len-8);
fprintf(srcf, "static const uint8_t capn_buf[%lu] = {", g_valseg.len-8);
for (j = 8; j < g_valseg.len; j++) {
if (j > 8)
fprintf(srcf, ",");
Expand All @@ -1226,7 +1226,7 @@ int main() {
}
fprintf(srcf, "\n};\n");

fprintf(srcf, "static const struct capn_segment capn_seg = {{0},0,0,0,(char*)&capn_buf[0],%d,%d};\n",
fprintf(srcf, "static const struct capn_segment capn_seg = {{0},0,0,0,(char*)&capn_buf[0],%lu,%lu};\n",
g_valseg.len-8, g_valseg.len-8);
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/schema-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ TEST(Schema, ReadSimple) {

struct CodeGeneratorRequest req;
read_CodeGeneratorRequest(&req, root);
for (size_t i = 0; i < req.nodes.p.len; i++) {
for (int i = 0; i < req.nodes.p.len; i++) {
}
}

Loading