From fd99b1e9065868483b5cbaf303a3cdd59417d013 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Mon, 23 May 2005 22:27:37 +0000 Subject: [project @ 2005-05-23 22:27:37 by jmb] Tighten up entry conditions svn path=/import/netsurf/; revision=1735 --- utils/utf8.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'utils') diff --git a/utils/utf8.c b/utils/utf8.c index 2676e8881..b2a219ced 100644 --- a/utils/utf8.c +++ b/utils/utf8.c @@ -84,7 +84,7 @@ size_t utf8_from_ucs4(size_t c, char *s) { size_t l = 0; - if (c > 0x7FFFFFFF) + if (c > 0x7FFFFFFF || s == NULL) assert(0); else if (c < 0x80) { *s = (char)c; @@ -139,6 +139,9 @@ size_t utf8_length(const char *s) { const char *__s = s; int l = 0; + + assert(__s != NULL); + while (*__s != '\0') { if ((*__s & 0x80) == 0x00) __s += 1; @@ -169,6 +172,8 @@ size_t utf8_length(const char *s) */ size_t utf8_prev(const char *s, size_t o) { + assert(s != NULL); + while (o != 0 && !(((s[--o] & 0x80) == 0x00) || ((s[o] & 0xC0) == 0xC0))) /* do nothing */; @@ -186,6 +191,8 @@ size_t utf8_prev(const char *s, size_t o) */ size_t utf8_next(const char *s, size_t l, size_t o) { + assert(s != NULL); + while (o != l && !(((s[++o] & 0x80) == 0x00) || ((s[o] & 0xC0) == 0xC0))) /* do nothing */; -- cgit v1.2.3