From cdc5e2cec5de1eb29ea3a42148c0b1302e97877f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Thu, 21 Feb 2019 15:22:47 +0100 Subject: Fix c++ compile warnings. --- strbuf.c | 2 +- strbuf.h | 2 +- vcal.c | 15 +++++++++++---- vcal.h | 6 +++--- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/strbuf.c b/strbuf.c index f17de211..54960a54 100644 --- a/strbuf.c +++ b/strbuf.c @@ -87,7 +87,7 @@ int strbuf_cmp(strbuf* a, strbuf* b) { return strncmp(a->mem, b->mem, a->len); } -int strbuf_c(strbuf* a, char* b) { +int strbuf_c(strbuf* a, const char* b) { if (a == NULL || a->alloc == 0) { ERR("a not allocated"); return -1; diff --git a/strbuf.h b/strbuf.h index c531734e..de4cc29b 100644 --- a/strbuf.h +++ b/strbuf.h @@ -40,7 +40,7 @@ int strbuf_realloc(strbuf* str, size_t len); FREE_F(strbuf); int strbuf_cmp(strbuf* a, strbuf* b); -int strbuf_c(strbuf* a, char* b); +int strbuf_c(strbuf* a, const char* b); /* * Copy contents from src to dest. diff --git a/vcal.c b/vcal.c index 7f674dac..2f736892 100644 --- a/vcal.c +++ b/vcal.c @@ -41,11 +41,11 @@ INIT_F(vcomponent) { return 0; } -INIT_F(vcomponent, char* type) { +INIT_F(vcomponent, const char* type) { return INIT(vcomponent, self, type, NULL); } -INIT_F(vcomponent, char* type, char* filename) { +INIT_F(vcomponent, const char* type, const char* filename) { INIT(TRIE(content_line), &self->clines); INIT(VECT(vcomponent), &self->components); @@ -83,8 +83,15 @@ content_line* RESOLVE(content_line) return dest; } -content_line* get_property (vcomponent* ev, char* key) { - return GET(TRIE(content_line))(&ev->clines, key); +content_line* get_property (vcomponent* ev, const char* key) { + size_t len = strlen(key) + 1; + char* cpy = (char*) (calloc(sizeof(*cpy), len)); + strncpy (cpy, key, len); + + content_line* ret = GET(TRIE(content_line))(&ev->clines, cpy); + + free (cpy); + return ret; } FREE_F(vcomponent) { diff --git a/vcal.h b/vcal.h index 1c96c4c6..95811a7b 100644 --- a/vcal.h +++ b/vcal.h @@ -96,11 +96,11 @@ struct s_vcomponent { #define FCHILD(v) GET(VECT(vcomponent))(&(v)->components, 0) INIT_F(vcomponent); -INIT_F(vcomponent, char* type); -INIT_F(vcomponent, char* type, char* filename); +INIT_F(vcomponent, const char* type); +INIT_F(vcomponent, const char* type, const char* filename); FREE_F(vcomponent); -content_line* get_property (vcomponent* ev, char* key); +content_line* get_property (vcomponent* ev, const char* key); int add_content_line (vcomponent* ev, content_line* c); -- cgit v1.2.3