summaryrefslogtreecommitdiff
path: root/xmlstring.c
diff options
context:
space:
mode:
Diffstat (limited to 'xmlstring.c')
-rw-r--r--xmlstring.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/xmlstring.c b/xmlstring.c
index af4e5c8..db94432 100644
--- a/xmlstring.c
+++ b/xmlstring.c
@@ -92,8 +92,10 @@ xmlCharStrndup(const char *cur, int len) {
xmlErrMemory(NULL, NULL);
return(NULL);
}
- for (i = 0;i < len;i++)
+ for (i = 0;i < len;i++) {
ret[i] = (xmlChar) cur[i];
+ if (ret[i] == 0) return(ret);
+ }
ret[len] = 0;
return(ret);
}
@@ -478,6 +480,8 @@ xmlStrncatNew(const xmlChar *str1, const xmlChar *str2, int len) {
int size;
xmlChar *ret;
+ if (len < 0)
+ len = xmlStrlen(str2);
if ((str2 == NULL) || (len == 0))
return(xmlStrdup(str1));
if (str1 == NULL)
@@ -743,7 +747,8 @@ xmlGetUTF8Char(const unsigned char *utf, int *len) {
return(c);
error:
- *len = 0;
+ if (len != NULL)
+ *len = 0;
return(-1);
}
@@ -766,6 +771,8 @@ xmlCheckUTF8(const unsigned char *utf)
int ix;
unsigned char c;
+ if (utf == NULL)
+ return(0);
/*
* utf is a string of 1, 2, 3 or 4 bytes. The valid strings
* are as follows (in "bit format"):
@@ -804,10 +811,10 @@ xmlCheckUTF8(const unsigned char *utf)
* @len: the number of characters in the array
*
* storage size of an UTF8 string
+ * the behaviour is not garanteed if the input string is not UTF-8
*
* Returns the storage size of
* the first 'len' characters of ARRAY
- *
*/
int
@@ -815,6 +822,9 @@ xmlUTF8Strsize(const xmlChar *utf, int len) {
const xmlChar *ptr=utf;
xmlChar ch;
+ if (utf == NULL)
+ return(0);
+
if (len <= 0)
return(0);
@@ -822,8 +832,10 @@ xmlUTF8Strsize(const xmlChar *utf, int len) {
if ( !*ptr )
break;
if ( (ch = *ptr++) & 0x80)
- while ( (ch<<=1) & 0x80 )
+ while ((ch<<=1) & 0x80 ) {
ptr++;
+ if (*ptr == 0) break;
+ }
}
return (ptr - utf);
}
@@ -867,7 +879,7 @@ xmlUTF8Strndup(const xmlChar *utf, int len) {
*
* Returns a pointer to the UTF8 character or NULL
*/
-xmlChar *
+const xmlChar *
xmlUTF8Strpos(const xmlChar *utf, int pos) {
xmlChar ch;