summaryrefslogtreecommitdiff
path: root/encoding.c
diff options
context:
space:
mode:
authorMike Hommey <mh@glandium.org>2004-11-11 12:53:54 +0000
committerMike Hommey <mh@glandium.org>2004-11-11 12:53:54 +0000
commitf51dd67f3a3f472af0620391eb588eeca4533689 (patch)
tree9184c396c489196608427d5fa35814e86a1e479f /encoding.c
parent9705f1a5e858108d21a0128556f42b25d16833cd (diff)
downloadlibxml2-f51dd67f3a3f472af0620391eb588eeca4533689.tar.gz
Load /tmp/tmp.n9GTkp/libxml2-2.6.16 intoupstream/2.6.16
packages/libxml2/branches/upstream/current.
Diffstat (limited to 'encoding.c')
-rw-r--r--encoding.c65
1 files changed, 44 insertions, 21 deletions
diff --git a/encoding.c b/encoding.c
index e05c375..6483322 100644
--- a/encoding.c
+++ b/encoding.c
@@ -125,7 +125,7 @@ asciiToUTF8(unsigned char* out, int *outlen,
}
*outlen = out - outstart;
*inlen = processed - base;
- return(0);
+ return(*outlen);
}
#ifdef LIBXML_OUTPUT_ENABLED
@@ -155,6 +155,7 @@ UTF8Toascii(unsigned char* out, int *outlen,
unsigned int c, d;
int trailing;
+ if ((out == NULL) || (outlen == NULL) || (inlen == NULL)) return(-1);
if (in == NULL) {
/*
* initialization nothing to do
@@ -209,7 +210,7 @@ UTF8Toascii(unsigned char* out, int *outlen,
}
*outlen = out - outstart;
*inlen = processed - instart;
- return(0);
+ return(*outlen);
}
#endif /* LIBXML_OUTPUT_ENABLED */
@@ -232,10 +233,14 @@ isolat1ToUTF8(unsigned char* out, int *outlen,
const unsigned char* in, int *inlen) {
unsigned char* outstart = out;
const unsigned char* base = in;
- unsigned char* outend = out + *outlen;
+ unsigned char* outend;
const unsigned char* inend;
const unsigned char* instop;
+ if ((out == NULL) || (in == NULL) || (outlen == NULL) || (inlen == NULL))
+ return(-1);
+
+ outend = out + *outlen;
inend = in + (*inlen);
instop = inend;
@@ -255,7 +260,7 @@ isolat1ToUTF8(unsigned char* out, int *outlen,
}
*outlen = out - outstart;
*inlen = in - base;
- return(0);
+ return(*outlen);
}
/**
@@ -291,7 +296,7 @@ UTF8ToUTF8(unsigned char* out, int *outlen,
*outlen = len;
*inlenb = len;
- return(0);
+ return(*outlen);
}
@@ -322,6 +327,7 @@ UTF8Toisolat1(unsigned char* out, int *outlen,
unsigned int c, d;
int trailing;
+ if ((out == NULL) || (outlen == NULL) || (inlen == NULL)) return(-1);
if (in == NULL) {
/*
* initialization nothing to do
@@ -381,7 +387,7 @@ UTF8Toisolat1(unsigned char* out, int *outlen,
}
*outlen = out - outstart;
*inlen = processed - instart;
- return(0);
+ return(*outlen);
}
#endif /* LIBXML_OUTPUT_ENABLED */
@@ -470,7 +476,7 @@ UTF16LEToUTF8(unsigned char* out, int *outlen,
}
*outlen = out - outstart;
*inlenb = processed - inb;
- return(0);
+ return(*outlen);
}
#ifdef LIBXML_OUTPUT_ENABLED
@@ -503,6 +509,7 @@ UTF8ToUTF16LE(unsigned char* outb, int *outlen,
unsigned short tmp1, tmp2;
/* UTF16LE encoding has no BOM */
+ if ((out == NULL) || (outlen == NULL) || (inlen == NULL)) return(-1);
if (in == NULL) {
*outlen = 0;
*inlen = 0;
@@ -578,7 +585,7 @@ UTF8ToUTF16LE(unsigned char* outb, int *outlen,
}
*outlen = (out - outstart) * 2;
*inlen = processed - instart;
- return(0);
+ return(*outlen);
}
/**
@@ -710,7 +717,7 @@ UTF16BEToUTF8(unsigned char* out, int *outlen,
}
*outlen = out - outstart;
*inlenb = processed - inb;
- return(0);
+ return(*outlen);
}
#ifdef LIBXML_OUTPUT_ENABLED
@@ -743,6 +750,7 @@ UTF8ToUTF16BE(unsigned char* outb, int *outlen,
unsigned short tmp1, tmp2;
/* UTF-16BE has no BOM */
+ if ((outb == NULL) || (outlen == NULL) || (inlen == NULL)) return(-1);
if (in == NULL) {
*outlen = 0;
*inlen = 0;
@@ -815,7 +823,7 @@ UTF8ToUTF16BE(unsigned char* outb, int *outlen,
}
*outlen = (out - outstart) * 2;
*inlen = processed - instart;
- return(0);
+ return(*outlen);
}
#endif /* LIBXML_OUTPUT_ENABLED */
@@ -839,6 +847,8 @@ UTF8ToUTF16BE(unsigned char* outb, int *outlen,
xmlCharEncoding
xmlDetectCharEncoding(const unsigned char* in, int len)
{
+ if (in == NULL)
+ return(XML_CHAR_ENCODING_NONE);
if (len >= 4) {
if ((in[0] == 0x00) && (in[1] == 0x00) &&
(in[2] == 0x00) && (in[3] == 0x3C))
@@ -1653,15 +1663,19 @@ xmlFindCharEncodingHandler(const char *name) {
* The value of @outlen after return is the number of ocetes consumed.
*/
static int
-xmlIconvWrapper(iconv_t cd,
- unsigned char *out, int *outlen,
- const unsigned char *in, int *inlen) {
-
- size_t icv_inlen = *inlen, icv_outlen = *outlen;
+xmlIconvWrapper(iconv_t cd, unsigned char *out, int *outlen,
+ const unsigned char *in, int *inlen) {
+ size_t icv_inlen, icv_outlen;
const char *icv_in = (const char *) in;
char *icv_out = (char *) out;
int ret;
+ if ((out == NULL) || (outlen == NULL) || (inlen == NULL) || (in == NULL)) {
+ if (outlen != NULL) *outlen = 0;
+ return(-1);
+ }
+ icv_inlen = *inlen;
+ icv_outlen = *outlen;
ret = iconv(cd, (char **) &icv_in, &icv_inlen, &icv_out, &icv_outlen);
if (in != NULL) {
*inlen -= icv_inlen;
@@ -2154,7 +2168,7 @@ xmlByteConsumed(xmlParserCtxtPtr ctxt) {
written = 32000;
ret = xmlIconvWrapper(handler->iconv_out, &convbuf[0],
&written, cur, &toconv);
- if (ret == -1) {
+ if (ret < 0) {
if (written > 0)
ret = -2;
else
@@ -2203,6 +2217,9 @@ UTF8ToISO8859x(unsigned char* out, int *outlen,
const unsigned char* inend;
const unsigned char* instart = in;
+ if ((out == NULL) || (outlen == NULL) || (inlen == NULL) ||
+ (xlattable == NULL))
+ return(-1);
if (in == NULL) {
/*
* initialization nothing to do
@@ -2290,7 +2307,7 @@ UTF8ToISO8859x(unsigned char* out, int *outlen,
}
*outlen = out - outstart;
*inlen = in - instart;
- return(0);
+ return(*outlen);
}
/**
@@ -2311,12 +2328,18 @@ ISO8859xToUTF8(unsigned char* out, int *outlen,
const unsigned char* in, int *inlen,
unsigned short const *unicodetable) {
unsigned char* outstart = out;
- unsigned char* outend = out + *outlen;
+ unsigned char* outend;
const unsigned char* instart = in;
- const unsigned char* inend = in + *inlen;
+ const unsigned char* inend;
const unsigned char* instop = inend;
- unsigned int c = *in;
+ unsigned int c;
+ if ((out == NULL) || (outlen == NULL) || (inlen == NULL) ||
+ (in == NULL) || (xlattable == NULL))
+ return(-1);
+ outend = out + *outlen;
+ inend = in + *inlen;
+ c = *in;
while (in < inend && out < outend - 1) {
if (c >= 0x80) {
c = unicodetable [c - 0x80];
@@ -2350,7 +2373,7 @@ ISO8859xToUTF8(unsigned char* out, int *outlen,
}
*outlen = out - outstart;
*inlen = in - instart;
- return (0);
+ return (*outlen);
}