From 7382fd5eba48107a8190bd2d6232cc3b6e20d8fc Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Sun, 7 Jun 2015 16:52:44 +0200 Subject: Convert code base to strbuf_t There are probably a couple of places I missed. But this will only be a problem if we use a 64-bit bufsize_t at some point. Then, we'll get warnings from -Wshorten-64-to-32. --- src/chunk.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/chunk.h') diff --git a/src/chunk.h b/src/chunk.h index a246a9d..364918d 100644 --- a/src/chunk.h +++ b/src/chunk.h @@ -11,8 +11,8 @@ typedef struct { unsigned char *data; - int len; - int alloc; // also implies a NULL-terminated string + bufsize_t len; + bufsize_t alloc; // also implies a NULL-terminated string } cmark_chunk; static inline void cmark_chunk_free(cmark_chunk *c) @@ -51,10 +51,10 @@ static inline void cmark_chunk_trim(cmark_chunk *c) cmark_chunk_rtrim(c); } -static inline int cmark_chunk_strchr(cmark_chunk *ch, int c, int offset) +static inline bufsize_t cmark_chunk_strchr(cmark_chunk *ch, int c, bufsize_t offset) { const unsigned char *p = (unsigned char *)memchr(ch->data + offset, c, ch->len - offset); - return p ? (int)(p - ch->data) : ch->len; + return p ? (bufsize_t)(p - ch->data) : ch->len; } static inline const char *cmark_chunk_to_cstr(cmark_chunk *c) @@ -100,7 +100,7 @@ static inline cmark_chunk cmark_chunk_literal(const char *data) return c; } -static inline cmark_chunk cmark_chunk_dup(const cmark_chunk *ch, int pos, int len) +static inline cmark_chunk cmark_chunk_dup(const cmark_chunk *ch, bufsize_t pos, bufsize_t len) { cmark_chunk c = {ch->data + pos, len, 0}; return c; -- cgit v1.2.3 From 0641c5e4e9727ddde0d2be1aebe3fd7009d010f5 Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Sun, 7 Jun 2015 17:44:11 +0200 Subject: Helper to safely call strlen --- src/chunk.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/chunk.h') diff --git a/src/chunk.h b/src/chunk.h index 364918d..f23a02d 100644 --- a/src/chunk.h +++ b/src/chunk.h @@ -87,7 +87,7 @@ static inline void cmark_chunk_set_cstr(cmark_chunk *c, const char *str) c->data = NULL; c->alloc = 0; } else { - c->len = strlen(str); + c->len = cmark_strbuf_safe_strlen(str); c->data = (unsigned char *)malloc(c->len + 1); c->alloc = 1; memcpy(c->data, str, c->len + 1); @@ -96,7 +96,8 @@ static inline void cmark_chunk_set_cstr(cmark_chunk *c, const char *str) static inline cmark_chunk cmark_chunk_literal(const char *data) { - cmark_chunk c = {(unsigned char *)data, data ? strlen(data) : 0, 0}; + bufsize_t len = data ? cmark_strbuf_safe_strlen(data) : 0; + cmark_chunk c = {(unsigned char *)data, len, 0}; return c; } -- cgit v1.2.3