summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Sanders <vince@netsurf-browser.org>2014-01-24 13:56:40 +0000
committerVincent Sanders <vince@netsurf-browser.org>2014-01-24 13:56:40 +0000
commitec446872606a65cf59e6bbbded464110353d9c59 (patch)
tree8fd4a6a80694e8b0dfd461f22862f5ba322e356f
parentfdaf91e209471f4acae867f07666a2625a668f80 (diff)
downloadlibdom-ec446872606a65cf59e6bbbded464110353d9c59.tar.gz
libdom-ec446872606a65cf59e6bbbded464110353d9c59.tar.bz2
make core string handling functions cope with NULL dom_string being passed
-rw-r--r--src/core/string.c19
1 files changed, 17 insertions, 2 deletions
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);