r13780 jmb - /trunk/libdom/bindings/hubbub/parser.c

netsurf at semichrome.net netsurf at semichrome.net
Fri Mar 30 22:20:06 BST 2012


Author: jmb
Date: Fri Mar 30 16:20:06 2012
New Revision: 13780

URL: http://source.netsurf-browser.org?rev=13780&view=rev
Log:
Replace strndup with our own implementation

Modified:
    trunk/libdom/bindings/hubbub/parser.c

Modified: trunk/libdom/bindings/hubbub/parser.c
URL: http://source.netsurf-browser.org/trunk/libdom/bindings/hubbub/parser.c?rev=13780&r1=13779&r2=13780&view=diff
==============================================================================
--- trunk/libdom/bindings/hubbub/parser.c (original)
+++ trunk/libdom/bindings/hubbub/parser.c Fri Mar 30 16:20:06 2012
@@ -334,6 +334,23 @@
 	return HUBBUB_OK;
 }
 
+static char *parser_strndup(const char *s, size_t n)
+{
+	size_t len;
+	char *s2;
+
+	for (len = 0; len != n && s[len] != '\0'; len++)
+		continue;
+
+	s2 = malloc(len + 1);
+	if (s2 == NULL)
+		return NULL;
+
+	memcpy(s2, s, len);
+	s2[len] = '\0';
+	return s2;
+}
+
 static hubbub_error create_doctype(void *parser, const hubbub_doctype *doctype,
 		void **result)
 {
@@ -344,7 +361,7 @@
 
 	*result = NULL;
 
-	qname = strndup((const char *) doctype->name.ptr, 
+	qname = parser_strndup((const char *) doctype->name.ptr, 
 			(size_t) doctype->name.len);
 	if (qname == NULL) {
 		dom_parser->msg(DOM_MSG_CRITICAL, dom_parser->mctx,
@@ -353,7 +370,8 @@
 	}
 
 	if (doctype->public_missing == false) {
-		public_id = strndup((const char *) doctype->public_id.ptr, 
+		public_id = parser_strndup(
+				(const char *) doctype->public_id.ptr, 
 				(size_t) doctype->public_id.len);
 	} else {
 		public_id = strdup("");
@@ -365,7 +383,8 @@
 	}
 
 	if (doctype->system_missing == false) {
-		system_id = strndup((const char *) doctype->system_id.ptr,
+		system_id = parser_strndup(
+				(const char *) doctype->system_id.ptr,
 				(size_t) doctype->system_id.len);
 	} else {
 		system_id = strdup("");




More information about the netsurf-commits mailing list