diff options
author | John-Mark Bell <jmb@netsurf-browser.org> | 2014-01-13 02:00:25 +0000 |
---|---|---|
committer | John-Mark Bell <jmb@netsurf-browser.org> | 2014-01-13 02:00:25 +0000 |
commit | 93c721d6edc90e6f06eff8701824aa0d9ed6da16 (patch) | |
tree | c4484450cc2d3828c39ba17765b9af83d4e0aae6 /src/charset/codecs/codec_utf8.c | |
parent | 3687f28df9aba82eb1476261a66f12db3f5eb049 (diff) | |
download | libparserutils-93c721d6edc90e6f06eff8701824aa0d9ed6da16.tar.gz libparserutils-93c721d6edc90e6f06eff8701824aa0d9ed6da16.tar.bz2 |
Replace use of abort() with assertions.
Diffstat (limited to 'src/charset/codecs/codec_utf8.c')
-rw-r--r-- | src/charset/codecs/codec_utf8.c | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/src/charset/codecs/codec_utf8.c b/src/charset/codecs/codec_utf8.c index 4016ebc..6117fe6 100644 --- a/src/charset/codecs/codec_utf8.c +++ b/src/charset/codecs/codec_utf8.c @@ -5,6 +5,7 @@ * Copyright 2007 John-Mark Bell <jmb@netsurf-browser.org> */ +#include <assert.h> #include <stdlib.h> #include <string.h> @@ -176,8 +177,7 @@ parserutils_error charset_utf8_codec_encode(parserutils_charset_codec *codec, UTF8_FROM_UCS4(pwrite[0], dest, destlen, error); if (error != PARSERUTILS_OK) { uint32_t len; - if (error != PARSERUTILS_NOMEM) - abort(); + assert(error == PARSERUTILS_NOMEM); /* Insufficient output buffer space */ for (len = 0; len < c->write_len; len++) { @@ -203,12 +203,10 @@ parserutils_error charset_utf8_codec_encode(parserutils_charset_codec *codec, UTF8_FROM_UCS4(towrite[0], dest, destlen, error); if (error != PARSERUTILS_OK) { uint32_t len; - if (error != PARSERUTILS_NOMEM) - abort(); + assert(error == PARSERUTILS_NOMEM); /* Insufficient output space */ - if (towritelen >= WRITE_BUFSIZE) - abort(); + assert(towritelen < WRITE_BUFSIZE); c->write_len = towritelen; @@ -337,8 +335,7 @@ parserutils_error charset_utf8_codec_decode(parserutils_charset_codec *codec, /* Failed to resolve an incomplete character and * ran out of buffer space. No recovery strategy * possible, so explode everywhere. */ - if ((orig_l + ol) - l == 0) - abort(); + assert((orig_l + ol) - l != 0); /* Report memory exhaustion case from above */ if (error != PARSERUTILS_OK) @@ -441,8 +438,7 @@ parserutils_error charset_utf8_codec_read_char(charset_utf8_codec *c, return error; } else if (error == PARSERUTILS_NEEDDATA) { /* Incomplete input sequence */ - if (*sourcelen >= INVAL_BUFSIZE) - abort(); + assert(*sourcelen < INVAL_BUFSIZE); memmove(c->inval_buf, *source, *sourcelen); c->inval_buf[*sourcelen] = '\0'; @@ -480,8 +476,7 @@ parserutils_error charset_utf8_codec_read_char(charset_utf8_codec *c, if (error != PARSERUTILS_OK) { if (error == PARSERUTILS_NEEDDATA) { /* Need more data to be sure */ - if (*sourcelen > INVAL_BUFSIZE) - abort(); + assert(*sourcelen < INVAL_BUFSIZE); memmove(c->inval_buf, *source, *sourcelen); c->inval_buf[*sourcelen] = '\0'; |