summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn-Mark Bell <jmb@netsurf-browser.org>2014-01-13 02:00:25 (GMT)
committer John-Mark Bell <jmb@netsurf-browser.org>2014-01-13 02:00:25 (GMT)
commit93c721d6edc90e6f06eff8701824aa0d9ed6da16 (patch)
treec4484450cc2d3828c39ba17765b9af83d4e0aae6
parent3687f28df9aba82eb1476261a66f12db3f5eb049 (diff)
downloadlibparserutils-93c721d6edc90e6f06eff8701824aa0d9ed6da16.tar.gz
libparserutils-93c721d6edc90e6f06eff8701824aa0d9ed6da16.tar.bz2
Replace use of abort() with assertions.
-rw-r--r--include/parserutils/input/inputstream.h5
-rw-r--r--src/charset/codecs/codec_8859.c3
-rw-r--r--src/charset/codecs/codec_ascii.c3
-rw-r--r--src/charset/codecs/codec_ext8.c3
-rw-r--r--src/charset/codecs/codec_utf16.c21
-rw-r--r--src/charset/codecs/codec_utf8.c19
-rw-r--r--src/input/inputstream.c3
7 files changed, 21 insertions, 36 deletions
diff --git a/include/parserutils/input/inputstream.h b/include/parserutils/input/inputstream.h
index eb33307..df35c0d 100644
--- a/include/parserutils/input/inputstream.h
+++ b/include/parserutils/input/inputstream.h
@@ -139,9 +139,6 @@ static inline parserutils_error parserutils_inputstream_peek(
#undef IS_ASCII
- if (off != utf8_len && error != PARSERUTILS_NEEDDATA)
- abort();
-
return parserutils_inputstream_peek_slow(stream, offset, ptr, length);
}
@@ -163,7 +160,7 @@ static inline void parserutils_inputstream_advance(
#endif
if (bytes > stream->utf8->length - stream->cursor)
- abort();
+ bytes = stream->utf8->length - stream->cursor;
if (stream->cursor == stream->utf8->length)
return;
diff --git a/src/charset/codecs/codec_8859.c b/src/charset/codecs/codec_8859.c
index 0ab4c32..fb8fbd3 100644
--- a/src/charset/codecs/codec_8859.c
+++ b/src/charset/codecs/codec_8859.c
@@ -258,8 +258,7 @@ parserutils_error charset_8859_codec_encode(parserutils_charset_codec *codec,
}
/* Insufficient output space */
- if (towritelen >= WRITE_BUFSIZE)
- abort();
+ assert(towritelen < WRITE_BUFSIZE);
c->write_len = towritelen;
diff --git a/src/charset/codecs/codec_ascii.c b/src/charset/codecs/codec_ascii.c
index 64991df..45db8bb 100644
--- a/src/charset/codecs/codec_ascii.c
+++ b/src/charset/codecs/codec_ascii.c
@@ -212,8 +212,7 @@ parserutils_error charset_ascii_codec_encode(parserutils_charset_codec *codec,
}
/* Insufficient output space */
- if (towritelen >= WRITE_BUFSIZE)
- abort();
+ assert(towritelen < WRITE_BUFSIZE);
c->write_len = towritelen;
diff --git a/src/charset/codecs/codec_ext8.c b/src/charset/codecs/codec_ext8.c
index eb9c898..bc98549 100644
--- a/src/charset/codecs/codec_ext8.c
+++ b/src/charset/codecs/codec_ext8.c
@@ -252,8 +252,7 @@ parserutils_error charset_ext8_codec_encode(parserutils_charset_codec *codec,
}
/* Insufficient output space */
- if (towritelen >= WRITE_BUFSIZE)
- abort();
+ assert(towritelen < WRITE_BUFSIZE);
c->write_len = towritelen;
diff --git a/src/charset/codecs/codec_utf16.c b/src/charset/codecs/codec_utf16.c
index 4a2d7ee..49b3492 100644
--- a/src/charset/codecs/codec_utf16.c
+++ b/src/charset/codecs/codec_utf16.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_utf16_codec_encode(parserutils_charset_codec *codec,
while (c->write_len > 0) {
error = parserutils_charset_utf16_from_ucs4(
pwrite[0], buf, &len);
- if (error != PARSERUTILS_OK)
- abort();
+ assert(error == PARSERUTILS_OK);
if (*destlen < len) {
/* Insufficient output buffer space */
@@ -210,13 +210,11 @@ parserutils_error charset_utf16_codec_encode(parserutils_charset_codec *codec,
error = parserutils_charset_utf16_from_ucs4(
towrite[0], buf, &len);
- if (error != PARSERUTILS_OK)
- abort();
+ assert(error == PARSERUTILS_OK);
if (*destlen < len) {
/* Insufficient output space */
- if (towritelen >= WRITE_BUFSIZE)
- abort();
+ assert(towritelen < WRITE_BUFSIZE);
c->write_len = towritelen;
@@ -246,6 +244,8 @@ parserutils_error charset_utf16_codec_encode(parserutils_charset_codec *codec,
*sourcelen -= 4;
}
+ (void) error;
+
return PARSERUTILS_OK;
}
@@ -350,8 +350,7 @@ parserutils_error charset_utf16_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)
@@ -449,8 +448,7 @@ parserutils_error charset_utf16_codec_read_char(charset_utf16_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';
@@ -482,8 +480,7 @@ parserutils_error charset_utf16_codec_read_char(charset_utf16_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';
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';
diff --git a/src/input/inputstream.c b/src/input/inputstream.c
index b2a1048..120ae88 100644
--- a/src/input/inputstream.c
+++ b/src/input/inputstream.c
@@ -412,8 +412,7 @@ parserutils_error parserutils_inputstream_refill_buffer(
stream->encsrc = 0;
}
- if (stream->mibenum == 0)
- abort();
+ assert(stream->mibenum != 0);
/* Strip any BOM, and update encoding as appropriate */
error = parserutils_inputstream_strip_bom(&stream->mibenum,