summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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);