From ec446872606a65cf59e6bbbded464110353d9c59 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Fri, 24 Jan 2014 13:56:40 +0000 Subject: make core string handling functions cope with NULL dom_string being passed --- src/core/string.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/core/string.c') diff --git a/src/core/string.c b/src/core/string.c index 3c2037f..d4c5cdf 100644 --- a/src/core/string.c +++ b/src/core/string.c @@ -602,11 +602,18 @@ dom_exception dom_string_concat(dom_string *s1, dom_string *s2, dom_exception dom_string_substr(dom_string *str, uint32_t i1, uint32_t i2, dom_string **result) { - const uint8_t *s = (const uint8_t *) dom_string_data(str); - size_t slen = dom_string_byte_length(str); + const uint8_t *s; + size_t slen; uint32_t b1, b2; parserutils_error err; + /* target string is NULL equivalent to empty. */ + if (str == NULL) + str = (dom_string *)&empty_string; + + s = (const uint8_t *) dom_string_data(str); + slen = dom_string_byte_length(str); + /* Initialise the byte index of the start to 0 */ b1 = 0; /* Make the end a character offset from the start */ @@ -663,6 +670,10 @@ dom_exception dom_string_insert(dom_string *target, uint32_t ins = 0; parserutils_error err; + /* target string is NULL equivalent to empty. */ + if (target == NULL) + target = (dom_string *)&empty_string; + t = (const uint8_t *) dom_string_data(target); tlen = dom_string_byte_length(target); s = (const uint8_t *) dom_string_data(source); @@ -752,6 +763,10 @@ dom_exception dom_string_replace(dom_string *target, uint32_t b1, b2; parserutils_error err; + /* target string is NULL equivalent to empty. */ + if (target == NULL) + target = (dom_string *)&empty_string; + t = (const uint8_t *) dom_string_data(target); tlen = dom_string_byte_length(target); s = (const uint8_t *) dom_string_data(source); -- cgit v1.2.3