summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Wellnhofer <wellnhofer@aevum.de>2022-09-01 01:18:30 +0200
committerNick Wellnhofer <wellnhofer@aevum.de>2022-09-01 02:33:57 +0200
commitad338ca737c4df5a4d1c28f8ee18b878572f2964 (patch)
tree99eb6d5585da39fc9d55cd0837209f8721c47452
parentaeb69fd3575a33eb2ffded18a444d8945bcbd741 (diff)
downloadlibxml2-ad338ca737c4df5a4d1c28f8ee18b878572f2964.tar.gz
Remove explicit integer casts
Remove explicit integer casts as final operation - in assignments - when passing arguments - when returning values Remove casts - to the same type - from certain range-bound values The main motivation is that these explicit casts don't change the result of operations and only render UBSan's implicit-conversion checks useless. Removing these casts allows UBSan to detect cases where truncation or sign-changes occur unexpectedly. Document some explicit casts as truncating and add a few missing ones.
-rw-r--r--HTMLparser.c15
-rw-r--r--HTMLtree.c2
-rw-r--r--SAX2.c10
-rw-r--r--buf.c8
-rw-r--r--c14n.c2
-rw-r--r--dict.c6
-rw-r--r--encoding.c22
-rw-r--r--globals.c4
-rw-r--r--hash.c6
-rw-r--r--parser.c4
-rw-r--r--parserInternals.c22
-rw-r--r--pattern.c4
-rw-r--r--tree.c2
-rw-r--r--valid.c2
-rw-r--r--xmlIO.c12
-rw-r--r--xmlreader.c2
-rw-r--r--xmlsave.c2
-rw-r--r--xmlwriter.c2
-rw-r--r--xpath.c70
-rw-r--r--xpointer.c14
20 files changed, 101 insertions, 110 deletions
diff --git a/HTMLparser.c b/HTMLparser.c
index f29138ac..fd71aee8 100644
--- a/HTMLparser.c
+++ b/HTMLparser.c
@@ -274,8 +274,6 @@ htmlNodeInfoPop(htmlParserCtxtPtr ctxt)
*
* Clean macros, not dependent of an ASCII context, expect UTF-8 encoding
*
- * CURRENT Returns the current char value, with the full decoding of
- * UTF-8 if we are using this mode. It returns an int.
* NEXT Skip to the next character, this does the proper decoding
* in UTF-8 mode. It also pop-up unfinished entities on the fly.
* NEXTL(l) Skip the current unicode character of l xmlChars long.
@@ -301,14 +299,11 @@ htmlNodeInfoPop(htmlParserCtxtPtr ctxt)
(ctxt->input->end - ctxt->input->cur < INPUT_CHUNK)) \
xmlParserInputGrow(ctxt->input, INPUT_CHUNK)
-#define CURRENT ((int) (*ctxt->input->cur))
-
#define SKIP_BLANKS htmlSkipBlankChars(ctxt)
/* Imported from XML */
-/* #define CUR (ctxt->token ? ctxt->token : (int) (*ctxt->input->cur)) */
-#define CUR ((int) (*ctxt->input->cur))
+#define CUR (*ctxt->input->cur)
#define NEXT xmlNextChar(ctxt)
#define RAW (ctxt->token ? -1 : (*ctxt->input->cur))
@@ -422,7 +417,7 @@ htmlCurrentChar(xmlParserCtxtPtr ctxt, int *len) {
* a compatible encoding for the ASCII set, since
* HTML constructs only use < 128 chars
*/
- if ((int) *ctxt->input->cur < 0x80) {
+ if (*ctxt->input->cur < 0x80) {
*len = 1;
if ((*ctxt->input->cur == 0) &&
(ctxt->input->cur < ctxt->input->end)) {
@@ -430,7 +425,7 @@ htmlCurrentChar(xmlParserCtxtPtr ctxt, int *len) {
"Char 0x%X out of allowed range\n", 0);
return(' ');
}
- return((int) *ctxt->input->cur);
+ return(*ctxt->input->cur);
}
/*
@@ -537,7 +532,7 @@ htmlCurrentChar(xmlParserCtxtPtr ctxt, int *len) {
}
/* 1-byte code */
*len = 1;
- return((int) *ctxt->input->cur);
+ return(*ctxt->input->cur);
}
encoding_error:
@@ -574,7 +569,7 @@ encoding_error:
(ctxt->input->buf->encoder == NULL))
xmlSwitchEncoding(ctxt, XML_CHAR_ENCODING_8859_1);
*len = 1;
- return((int) *ctxt->input->cur);
+ return(*ctxt->input->cur);
}
/**
diff --git a/HTMLtree.c b/HTMLtree.c
index f83c66d2..b442dd01 100644
--- a/HTMLtree.c
+++ b/HTMLtree.c
@@ -415,7 +415,7 @@ htmlBufNodeDumpFormat(xmlBufPtr buf, xmlDocPtr doc, xmlNodePtr cur,
htmlSaveErrMemory("allocating HTML output buffer");
return (-1);
}
- memset(outbuf, 0, (size_t) sizeof(xmlOutputBuffer));
+ memset(outbuf, 0, sizeof(xmlOutputBuffer));
outbuf->buffer = buf;
outbuf->encoder = NULL;
outbuf->writecallback = NULL;
diff --git a/SAX2.c b/SAX2.c
index 6f46cad3..3ed2e549 100644
--- a/SAX2.c
+++ b/SAX2.c
@@ -1643,7 +1643,7 @@ xmlSAX2StartElement(void *ctx, const xmlChar *fullname, const xmlChar **atts)
if (ctxt->linenumbers) {
if (ctxt->input != NULL) {
if (ctxt->input->line < USHRT_MAX)
- ret->line = (unsigned short) ctxt->input->line;
+ ret->line = ctxt->input->line;
else
ret->line = USHRT_MAX;
}
@@ -1908,7 +1908,7 @@ skip:
if (ctxt->linenumbers) {
if (ctxt->input != NULL) {
if (ctxt->input->line < USHRT_MAX)
- ret->line = (unsigned short) ctxt->input->line;
+ ret->line = ctxt->input->line;
else {
ret->line = USHRT_MAX;
if (ctxt->options & XML_PARSE_BIG_LINES)
@@ -2286,7 +2286,7 @@ xmlSAX2StartElementNs(void *ctx,
if (ctxt->linenumbers) {
if (ctxt->input != NULL) {
if (ctxt->input->line < USHRT_MAX)
- ret->line = (unsigned short) ctxt->input->line;
+ ret->line = ctxt->input->line;
else
ret->line = USHRT_MAX;
}
@@ -2711,7 +2711,7 @@ xmlSAX2ProcessingInstruction(void *ctx, const xmlChar *target,
if (ctxt->linenumbers) {
if (ctxt->input != NULL) {
if (ctxt->input->line < USHRT_MAX)
- ret->line = (unsigned short) ctxt->input->line;
+ ret->line = ctxt->input->line;
else
ret->line = USHRT_MAX;
}
@@ -2771,7 +2771,7 @@ xmlSAX2Comment(void *ctx, const xmlChar *value)
if (ctxt->linenumbers) {
if (ctxt->input != NULL) {
if (ctxt->input->line < USHRT_MAX)
- ret->line = (unsigned short) ctxt->input->line;
+ ret->line = ctxt->input->line;
else
ret->line = USHRT_MAX;
}
diff --git a/buf.c b/buf.c
index 64966016..85313b6c 100644
--- a/buf.c
+++ b/buf.c
@@ -506,7 +506,7 @@ xmlBufGrow(xmlBufPtr buf, int len) {
ret = xmlBufGrowInternal(buf, len);
if (buf->error != 0)
return(-1);
- return((int) ret);
+ return(ret > INT_MAX ? INT_MAX : ret);
}
/**
@@ -1044,11 +1044,11 @@ xmlBufBackToBuffer(xmlBufPtr buf) {
* Keep the buffer but provide a truncated size value.
*/
xmlBufOverflowError(buf, "Allocated size too big for xmlBuffer");
- ret->use = (int) buf->use;
+ ret->use = buf->use;
ret->size = INT_MAX;
} else {
- ret->use = (int) buf->use;
- ret->size = (int) buf->size;
+ ret->use = buf->use;
+ ret->size = buf->size;
}
ret->alloc = buf->alloc;
ret->content = buf->content;
diff --git a/c14n.c b/c14n.c
index bb16ec8b..78eb82ae 100644
--- a/c14n.c
+++ b/c14n.c
@@ -287,7 +287,7 @@ xmlC14NVisibleNsStackCreate(void) {
xmlC14NErrMemory("creating namespaces stack");
return(NULL);
}
- memset(ret, 0 , (size_t) sizeof(xmlC14NVisibleNsStack));
+ memset(ret, 0, sizeof(xmlC14NVisibleNsStack));
return(ret);
}
diff --git a/dict.c b/dict.c
index af6ea358..5c9ca719 100644
--- a/dict.c
+++ b/dict.c
@@ -498,10 +498,10 @@ static unsigned long
xmlDictComputeFastQKey(const xmlChar *prefix, int plen,
const xmlChar *name, int len, int seed)
{
- unsigned long value = (unsigned long) seed;
+ unsigned long value = seed;
if (plen == 0)
- value += 30 * (unsigned long) ':';
+ value += 30 * ':';
else
value += 30 * (*prefix);
@@ -539,7 +539,7 @@ xmlDictComputeFastQKey(const xmlChar *prefix, int plen,
}
len -= plen;
if (len > 0) {
- value += (unsigned long) ':';
+ value += ':';
len--;
}
switch (len) {
diff --git a/encoding.c b/encoding.c
index 845ff55f..c990bcf1 100644
--- a/encoding.c
+++ b/encoding.c
@@ -533,7 +533,7 @@ UTF16LEToUTF8(unsigned char* out, int *outlen,
} else {
tmp = (unsigned char *) in;
c = *tmp++;
- c = c | (((unsigned int)*tmp) << 8);
+ c = c | (*tmp << 8);
in++;
}
if ((c & 0xFC00) == 0xD800) { /* surrogates */
@@ -545,7 +545,7 @@ UTF16LEToUTF8(unsigned char* out, int *outlen,
} else {
tmp = (unsigned char *) in;
d = *tmp++;
- d = d | (((unsigned int)*tmp) << 8);
+ d = d | (*tmp << 8);
in++;
}
if ((d & 0xFC00) == 0xDC00) {
@@ -656,7 +656,7 @@ UTF8ToUTF16LE(unsigned char* outb, int *outlen,
*out++ = c;
} else {
tmp = (unsigned char *) out;
- *tmp = c ;
+ *tmp = (unsigned char) c; /* Explicit truncation */
*(tmp + 1) = c >> 8 ;
out++;
}
@@ -671,13 +671,13 @@ UTF8ToUTF16LE(unsigned char* outb, int *outlen,
} else {
tmp1 = 0xD800 | (c >> 10);
tmp = (unsigned char *) out;
- *tmp = (unsigned char) tmp1;
+ *tmp = (unsigned char) tmp1; /* Explicit truncation */
*(tmp + 1) = tmp1 >> 8;
out++;
tmp2 = 0xDC00 | (c & 0x03FF);
tmp = (unsigned char *) out;
- *tmp = (unsigned char) tmp2;
+ *tmp = (unsigned char) tmp2; /* Explicit truncation */
*(tmp + 1) = tmp2 >> 8;
out++;
}
@@ -774,7 +774,7 @@ UTF16BEToUTF8(unsigned char* out, int *outlen,
if (xmlLittleEndian) {
tmp = (unsigned char *) in;
c = *tmp++;
- c = (c << 8) | (unsigned int) *tmp;
+ c = (c << 8) | *tmp;
in++;
} else {
c= *in++;
@@ -786,7 +786,7 @@ UTF16BEToUTF8(unsigned char* out, int *outlen,
if (xmlLittleEndian) {
tmp = (unsigned char *) in;
d = *tmp++;
- d = (d << 8) | (unsigned int) *tmp;
+ d = (d << 8) | *tmp;
in++;
} else {
d= *in++;
@@ -896,7 +896,7 @@ UTF8ToUTF16BE(unsigned char* outb, int *outlen,
if (xmlLittleEndian) {
tmp = (unsigned char *) out;
*tmp = c >> 8;
- *(tmp + 1) = c;
+ *(tmp + 1) = (unsigned char) c; /* Explicit truncation */
out++;
} else {
*out++ = c;
@@ -909,13 +909,13 @@ UTF8ToUTF16BE(unsigned char* outb, int *outlen,
tmp1 = 0xD800 | (c >> 10);
tmp = (unsigned char *) out;
*tmp = tmp1 >> 8;
- *(tmp + 1) = (unsigned char) tmp1;
+ *(tmp + 1) = (unsigned char) tmp1; /* Explicit truncation */
out++;
tmp2 = 0xDC00 | (c & 0x03FF);
tmp = (unsigned char *) out;
*tmp = tmp2 >> 8;
- *(tmp + 1) = (unsigned char) tmp2;
+ *(tmp + 1) = (unsigned char) tmp2; /* Explicit truncation */
out++;
} else {
*out++ = 0xD800 | (c >> 10);
@@ -2544,7 +2544,7 @@ retry:
break;
case -2: {
xmlChar charref[20];
- int len = (int) xmlBufUse(in);
+ int len = xmlBufUse(in);
xmlChar *content = xmlBufContent(in);
int cur, charrefLen;
diff --git a/globals.c b/globals.c
index aaff09a6..7e5c1aa9 100644
--- a/globals.c
+++ b/globals.c
@@ -498,8 +498,8 @@ void
xmlInitializeGlobalState(xmlGlobalStatePtr gs)
{
#ifdef DEBUG_GLOBALS
- fprintf(stderr, "Initializing globals at %lu for thread %d\n",
- (unsigned long) gs, xmlGetThreadId());
+ fprintf(stderr, "Initializing globals at %p for thread %d\n",
+ (void *) gs, xmlGetThreadId());
#endif
/*
diff --git a/hash.c b/hash.c
index 2567924f..bccc812a 100644
--- a/hash.c
+++ b/hash.c
@@ -132,7 +132,7 @@ xmlHashComputeQKey(xmlHashTablePtr table,
while ((ch = *prefix++) != 0) {
value = value ^ ((value << 5) + (value >> 3) + ch);
}
- value = value ^ ((value << 5) + (value >> 3) + (unsigned long)':');
+ value = value ^ ((value << 5) + (value >> 3) + ':');
}
if (name != NULL) {
while ((ch = *name++) != 0) {
@@ -144,7 +144,7 @@ xmlHashComputeQKey(xmlHashTablePtr table,
while ((ch = *prefix2++) != 0) {
value = value ^ ((value << 5) + (value >> 3) + ch);
}
- value = value ^ ((value << 5) + (value >> 3) + (unsigned long)':');
+ value = value ^ ((value << 5) + (value >> 3) + ':');
}
if (name2 != NULL) {
while ((ch = *name2++) != 0) {
@@ -156,7 +156,7 @@ xmlHashComputeQKey(xmlHashTablePtr table,
while ((ch = *prefix3++) != 0) {
value = value ^ ((value << 5) + (value >> 3) + ch);
}
- value = value ^ ((value << 5) + (value >> 3) + (unsigned long)':');
+ value = value ^ ((value << 5) + (value >> 3) + ':');
}
if (name3 != NULL) {
while ((ch = *name3++) != 0) {
diff --git a/parser.c b/parser.c
index a70879cc..8f6baa11 100644
--- a/parser.c
+++ b/parser.c
@@ -1224,7 +1224,7 @@ xmlAttrNormalizeSpace2(xmlParserCtxtPtr ctxt, xmlChar *src, int *len)
return(NULL);
}
xmlAttrNormalizeSpace(ret, ret);
- *len = (int) strlen((const char *)ret);
+ *len = strlen((const char *)ret);
return(ret);
} else if (remove_head) {
*len -= remove_head;
@@ -4139,7 +4139,7 @@ xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *attlen, int normalize) {
goto mem_error;
}
- if (attlen != NULL) *attlen = (int) len;
+ if (attlen != NULL) *attlen = len;
return(buf);
mem_error:
diff --git a/parserInternals.c b/parserInternals.c
index 4e119535..43f24bfa 100644
--- a/parserInternals.c
+++ b/parserInternals.c
@@ -62,7 +62,7 @@
*/
void
xmlCheckVersion(int version) {
- int myversion = (int) LIBXML_VERSION;
+ int myversion = LIBXML_VERSION;
xmlInitParser();
@@ -248,9 +248,9 @@ void check_buffer(xmlParserInputPtr in) {
xmlGenericError(xmlGenericErrorContext,
"xmlParserInput: cur > base + use problem\n");
}
- xmlGenericError(xmlGenericErrorContext,"buffer %x : content %x, cur %d, use %d\n",
- (int) in, (int) xmlBufContent(in->buf->buffer), in->cur - in->base,
- xmlBufUse(in->buf->buffer));
+ xmlGenericError(xmlGenericErrorContext,"buffer %p : content %x, cur %d, use %d\n",
+ (void *) in, (int) xmlBufContent(in->buf->buffer),
+ in->cur - in->base, xmlBufUse(in->buf->buffer));
}
#else
@@ -551,7 +551,7 @@ xmlCurrentChar(xmlParserCtxtPtr ctxt, int *len) {
if ((*ctxt->input->cur >= 0x20) && (*ctxt->input->cur <= 0x7F)) {
*len = 1;
- return((int) *ctxt->input->cur);
+ return(*ctxt->input->cur);
}
if (ctxt->charset == XML_CHAR_ENCODING_UTF8) {
/*
@@ -640,7 +640,7 @@ xmlCurrentChar(xmlParserCtxtPtr ctxt, int *len) {
}
return(0xA);
}
- return((int) *ctxt->input->cur);
+ return(*ctxt->input->cur);
}
}
/*
@@ -655,7 +655,7 @@ xmlCurrentChar(xmlParserCtxtPtr ctxt, int *len) {
}
return(0xA);
}
- return((int) *ctxt->input->cur);
+ return(*ctxt->input->cur);
encoding_error:
/*
* An encoding problem may arise from a truncated input buffer
@@ -686,7 +686,7 @@ encoding_error:
}
ctxt->charset = XML_CHAR_ENCODING_8859_1;
*len = 1;
- return((int) *ctxt->input->cur);
+ return(*ctxt->input->cur);
}
/**
@@ -758,7 +758,7 @@ xmlStringCurrentChar(xmlParserCtxtPtr ctxt, const xmlChar * cur, int *len)
} else {
/* 1-byte code */
*len = 1;
- return ((int) *cur);
+ return (*cur);
}
}
/*
@@ -767,7 +767,7 @@ xmlStringCurrentChar(xmlParserCtxtPtr ctxt, const xmlChar * cur, int *len)
* XML constructs only use < 128 chars
*/
*len = 1;
- return ((int) *cur);
+ return (*cur);
encoding_error:
/*
@@ -798,7 +798,7 @@ encoding_error:
BAD_CAST buffer, NULL);
}
*len = 1;
- return ((int) *cur);
+ return (*cur);
}
/**
diff --git a/pattern.c b/pattern.c
index cff4469c..4d0423ee 100644
--- a/pattern.c
+++ b/pattern.c
@@ -2207,7 +2207,7 @@ stream_next:
int
xmlStreamPush(xmlStreamCtxtPtr stream,
const xmlChar *name, const xmlChar *ns) {
- return (xmlStreamPushInternal(stream, name, ns, (int) XML_ELEMENT_NODE));
+ return (xmlStreamPushInternal(stream, name, ns, XML_ELEMENT_NODE));
}
/**
@@ -2257,7 +2257,7 @@ xmlStreamPushNode(xmlStreamCtxtPtr stream,
int
xmlStreamPushAttr(xmlStreamCtxtPtr stream,
const xmlChar *name, const xmlChar *ns) {
- return (xmlStreamPushInternal(stream, name, ns, (int) XML_ATTRIBUTE_NODE));
+ return (xmlStreamPushInternal(stream, name, ns, XML_ATTRIBUTE_NODE));
}
/**
diff --git a/tree.c b/tree.c
index 46d74890..b296d920 100644
--- a/tree.c
+++ b/tree.c
@@ -7459,7 +7459,7 @@ xmlBufferDump(FILE *file, xmlBufferPtr buf) {
if (file == NULL)
file = stdout;
ret = fwrite(buf->content, sizeof(xmlChar), buf->use, file);
- return(ret > INT_MAX ? INT_MAX : (int)ret);
+ return(ret > INT_MAX ? INT_MAX : ret);
}
/**
diff --git a/valid.c b/valid.c
index f3a69804..dc2d175d 100644
--- a/valid.c
+++ b/valid.c
@@ -5018,7 +5018,7 @@ cont:
* save the second branch 'or' branch
*/
DEBUG_VALID_MSG("saving 'or' branch");
- if (vstateVPush(ctxt, CONT->c2, NODE, (unsigned char)(DEPTH + 1),
+ if (vstateVPush(ctxt, CONT->c2, NODE, DEPTH + 1,
OCCURS, ROLLBACK_OR) < 0)
return(-1);
DEPTH++;
diff --git a/xmlIO.c b/xmlIO.c
index dbd19446..578c2171 100644
--- a/xmlIO.c
+++ b/xmlIO.c
@@ -2346,7 +2346,7 @@ xmlAllocParserInputBuffer(xmlCharEncoding enc) {
xmlIOErrMemory("creating input buffer");
return(NULL);
}
- memset(ret, 0, (size_t) sizeof(xmlParserInputBuffer));
+ memset(ret, 0, sizeof(xmlParserInputBuffer));
ret->buffer = xmlBufCreateSize(2 * xmlDefaultBufferSize);
if (ret->buffer == NULL) {
xmlFree(ret);
@@ -2385,7 +2385,7 @@ xmlAllocOutputBuffer(xmlCharEncodingHandlerPtr encoder) {
xmlIOErrMemory("creating output buffer");
return(NULL);
}
- memset(ret, 0, (size_t) sizeof(xmlOutputBuffer));
+ memset(ret, 0, sizeof(xmlOutputBuffer));
ret->buffer = xmlBufCreate();
if (ret->buffer == NULL) {
xmlFree(ret);
@@ -2433,7 +2433,7 @@ xmlAllocOutputBufferInternal(xmlCharEncodingHandlerPtr encoder) {
xmlIOErrMemory("creating output buffer");
return(NULL);
}
- memset(ret, 0, (size_t) sizeof(xmlOutputBuffer));
+ memset(ret, 0, sizeof(xmlOutputBuffer));
ret->buffer = xmlBufCreate();
if (ret->buffer == NULL) {
xmlFree(ret);
@@ -2988,8 +2988,8 @@ xmlParserInputBufferCreateStatic(const char *mem, int size,
xmlIOErrMemory("creating input buffer");
return(NULL);
}
- memset(ret, 0, (size_t) sizeof(xmlParserInputBuffer));
- ret->buffer = xmlBufCreateStatic((void *)mem, (size_t) size);
+ memset(ret, 0, sizeof(xmlParserInputBuffer));
+ ret->buffer = xmlBufCreateStatic((void *)mem, size);
if (ret->buffer == NULL) {
xmlFree(ret);
return(NULL);
@@ -3496,7 +3496,7 @@ xmlEscapeContent(unsigned char* out, int *outlen,
*out++ = '3';
*out++ = ';';
} else {
- *out++ = (unsigned char) *in;
+ *out++ = *in;
}
++in;
}
diff --git a/xmlreader.c b/xmlreader.c
index 383f07a6..9c2da90e 100644
--- a/xmlreader.c
+++ b/xmlreader.c
@@ -3614,7 +3614,7 @@ xmlTextReaderQuoteChar(xmlTextReaderPtr reader) {
if (reader == NULL)
return(-1);
/* TODO maybe lookup the attribute value for " first */
- return((int) '"');
+ return('"');
}
/**
diff --git a/xmlsave.c b/xmlsave.c
index 1541d94c..17bc37ea 100644
--- a/xmlsave.c
+++ b/xmlsave.c
@@ -2178,7 +2178,7 @@ xmlNodeDump(xmlBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur, int level,
xmlBufBackToBuffer(buffer);
if (ret > INT_MAX)
return(-1);
- return((int) ret);
+ return(ret);
}
/**
diff --git a/xmlwriter.c b/xmlwriter.c
index 1cf82906..278f25d6 100644
--- a/xmlwriter.c
+++ b/xmlwriter.c
@@ -189,7 +189,7 @@ xmlNewTextWriter(xmlOutputBufferPtr out)
"xmlNewTextWriter : out of memory!\n");
return NULL;
}
- memset(ret, 0, (size_t) sizeof(xmlTextWriter));
+ memset(ret, 0, sizeof(xmlTextWriter));
ret->nodes = xmlListCreate(xmlFreeTextWriterStackEntry,
xmlCmpTextWriterStackEntry);
diff --git a/xpath.c b/xpath.c
index 4d2ccf23..abc08c98 100644
--- a/xpath.c
+++ b/xpath.c
@@ -2205,7 +2205,7 @@ xmlXPathNewCache(void)
xmlXPathErrMemory(NULL, "creating object cache\n");
return(NULL);
}
- memset(ret, 0 , (size_t) sizeof(xmlXPathContextCache));
+ memset(ret, 0 , sizeof(xmlXPathContextCache));
ret->maxNodeset = 100;
ret->maxString = 100;
ret->maxBoolean = 100;
@@ -3305,7 +3305,7 @@ xmlXPathOrderDocElems(xmlDocPtr doc) {
}
} while (cur != NULL);
}
- return((long) count);
+ return(count);
}
/**
@@ -3581,7 +3581,7 @@ xmlXPathNodeSetCreate(xmlNodePtr val) {
xmlXPathErrMemory(NULL, "creating nodeset\n");
return(NULL);
}
- memset(ret, 0 , (size_t) sizeof(xmlNodeSet));
+ memset(ret, 0 , sizeof(xmlNodeSet));
if (val != NULL) {
ret->nodeTab = (xmlNodePtr *) xmlMalloc(XML_NODESET_DEFAULT *
sizeof(xmlNodePtr));
@@ -3591,7 +3591,7 @@ xmlXPathNodeSetCreate(xmlNodePtr val) {
return(NULL);
}
memset(ret->nodeTab, 0 ,
- XML_NODESET_DEFAULT * (size_t) sizeof(xmlNodePtr));
+ XML_NODESET_DEFAULT * sizeof(xmlNodePtr));
ret->nodeMax = XML_NODESET_DEFAULT;
if (val->type == XML_NAMESPACE_DECL) {
xmlNsPtr ns = (xmlNsPtr) val;
@@ -3685,7 +3685,7 @@ xmlXPathNodeSetAddNs(xmlNodeSetPtr cur, xmlNodePtr node, xmlNsPtr ns) {
return(-1);
}
memset(cur->nodeTab, 0 ,
- XML_NODESET_DEFAULT * (size_t) sizeof(xmlNodePtr));
+ XML_NODESET_DEFAULT * sizeof(xmlNodePtr));
cur->nodeMax = XML_NODESET_DEFAULT;
} else if (cur->nodeNr == cur->nodeMax) {
xmlNodePtr *temp;
@@ -3741,7 +3741,7 @@ xmlXPathNodeSetAdd(xmlNodeSetPtr cur, xmlNodePtr val) {
return(-1);
}
memset(cur->nodeTab, 0 ,
- XML_NODESET_DEFAULT * (size_t) sizeof(xmlNodePtr));
+ XML_NODESET_DEFAULT * sizeof(xmlNodePtr));
cur->nodeMax = XML_NODESET_DEFAULT;
} else if (cur->nodeNr == cur->nodeMax) {
xmlNodePtr *temp;
@@ -3796,7 +3796,7 @@ xmlXPathNodeSetAddUnique(xmlNodeSetPtr cur, xmlNodePtr val) {
return(-1);
}
memset(cur->nodeTab, 0 ,
- XML_NODESET_DEFAULT * (size_t) sizeof(xmlNodePtr));
+ XML_NODESET_DEFAULT * sizeof(xmlNodePtr));
cur->nodeMax = XML_NODESET_DEFAULT;
} else if (cur->nodeNr == cur->nodeMax) {
xmlNodePtr *temp;
@@ -3913,7 +3913,7 @@ xmlXPathNodeSetMerge(xmlNodeSetPtr val1, xmlNodeSetPtr val2) {
return(NULL);
}
memset(val1->nodeTab, 0 ,
- XML_NODESET_DEFAULT * (size_t) sizeof(xmlNodePtr));
+ XML_NODESET_DEFAULT * sizeof(xmlNodePtr));
val1->nodeMax = XML_NODESET_DEFAULT;
} else if (val1->nodeNr == val1->nodeMax) {
xmlNodePtr *temp;
@@ -3999,7 +3999,7 @@ xmlXPathNodeSetMergeAndClear(xmlNodeSetPtr set1, xmlNodeSetPtr set2)
return(NULL);
}
memset(set1->nodeTab, 0,
- XML_NODESET_DEFAULT * (size_t) sizeof(xmlNodePtr));
+ XML_NODESET_DEFAULT * sizeof(xmlNodePtr));
set1->nodeMax = XML_NODESET_DEFAULT;
} else if (set1->nodeNr >= set1->nodeMax) {
xmlNodePtr *temp;
@@ -4053,7 +4053,7 @@ xmlXPathNodeSetMergeAndClearNoDupls(xmlNodeSetPtr set1, xmlNodeSetPtr set2)
return(NULL);
}
memset(set1->nodeTab, 0,
- XML_NODESET_DEFAULT * (size_t) sizeof(xmlNodePtr));
+ XML_NODESET_DEFAULT * sizeof(xmlNodePtr));
set1->nodeMax = XML_NODESET_DEFAULT;
} else if (set1->nodeNr >= set1->nodeMax) {
xmlNodePtr *temp;
@@ -4312,7 +4312,7 @@ xmlXPathNewNodeSet(xmlNodePtr val) {
xmlXPathErrMemory(NULL, "creating nodeset\n");
return(NULL);
}
- memset(ret, 0 , (size_t) sizeof(xmlXPathObject));
+ memset(ret, 0 , sizeof(xmlXPathObject));
ret->type = XPATH_NODESET;
ret->boolval = 0;
/* TODO: Check memory error. */
@@ -4342,7 +4342,7 @@ xmlXPathNewValueTree(xmlNodePtr val) {
xmlXPathErrMemory(NULL, "creating result value tree\n");
return(NULL);
}
- memset(ret, 0 , (size_t) sizeof(xmlXPathObject));
+ memset(ret, 0 , sizeof(xmlXPathObject));
ret->type = XPATH_XSLT_TREE;
ret->boolval = 1;
ret->user = (void *) val;
@@ -4403,7 +4403,7 @@ xmlXPathWrapNodeSet(xmlNodeSetPtr val) {
xmlXPathErrMemory(NULL, "creating node set object\n");
return(NULL);
}
- memset(ret, 0 , (size_t) sizeof(xmlXPathObject));
+ memset(ret, 0 , sizeof(xmlXPathObject));
ret->type = XPATH_NODESET;
ret->nodesetval = val;
#ifdef XP_DEBUG_OBJ_USAGE
@@ -5212,7 +5212,7 @@ xmlXPathNewFloat(double val) {
xmlXPathErrMemory(NULL, "creating float object\n");
return(NULL);
}
- memset(ret, 0 , (size_t) sizeof(xmlXPathObject));
+ memset(ret, 0 , sizeof(xmlXPathObject));
ret->type = XPATH_NUMBER;
ret->floatval = val;
#ifdef XP_DEBUG_OBJ_USAGE
@@ -5238,7 +5238,7 @@ xmlXPathNewBoolean(int val) {
xmlXPathErrMemory(NULL, "creating boolean object\n");
return(NULL);
}
- memset(ret, 0 , (size_t) sizeof(xmlXPathObject));
+ memset(ret, 0 , sizeof(xmlXPathObject));
ret->type = XPATH_BOOLEAN;
ret->boolval = (val != 0);
#ifdef XP_DEBUG_OBJ_USAGE
@@ -5264,7 +5264,7 @@ xmlXPathNewString(const xmlChar *val) {
xmlXPathErrMemory(NULL, "creating string object\n");
return(NULL);
}
- memset(ret, 0 , (size_t) sizeof(xmlXPathObject));
+ memset(ret, 0 , sizeof(xmlXPathObject));
ret->type = XPATH_STRING;
if (val != NULL)
ret->stringval = xmlStrdup(val);
@@ -5293,7 +5293,7 @@ xmlXPathWrapString (xmlChar *val) {
xmlXPathErrMemory(NULL, "creating string object\n");
return(NULL);
}
- memset(ret, 0 , (size_t) sizeof(xmlXPathObject));
+ memset(ret, 0 , sizeof(xmlXPathObject));
ret->type = XPATH_STRING;
ret->stringval = val;
#ifdef XP_DEBUG_OBJ_USAGE
@@ -5319,7 +5319,7 @@ xmlXPathNewCString(const char *val) {
xmlXPathErrMemory(NULL, "creating string object\n");
return(NULL);
}
- memset(ret, 0 , (size_t) sizeof(xmlXPathObject));
+ memset(ret, 0 , sizeof(xmlXPathObject));
ret->type = XPATH_STRING;
ret->stringval = xmlStrdup(BAD_CAST val);
#ifdef XP_DEBUG_OBJ_USAGE
@@ -5358,7 +5358,7 @@ xmlXPathWrapExternal (void *val) {
xmlXPathErrMemory(NULL, "creating user object\n");
return(NULL);
}
- memset(ret, 0 , (size_t) sizeof(xmlXPathObject));
+ memset(ret, 0 , sizeof(xmlXPathObject));
ret->type = XPATH_USERS;
ret->user = val;
#ifdef XP_DEBUG_OBJ_USAGE
@@ -5387,7 +5387,7 @@ xmlXPathObjectCopy(xmlXPathObjectPtr val) {
xmlXPathErrMemory(NULL, "copying object\n");
return(NULL);
}
- memcpy(ret, val , (size_t) sizeof(xmlXPathObject));
+ memcpy(ret, val , sizeof(xmlXPathObject));
#ifdef XP_DEBUG_OBJ_USAGE
xmlXPathDebugObjUsageRequested(NULL, val->type);
#endif
@@ -6119,7 +6119,7 @@ xmlXPathNewContext(xmlDocPtr doc) {
xmlXPathErrMemory(NULL, "creating context\n");
return(NULL);
}
- memset(ret, 0 , (size_t) sizeof(xmlXPathContext));
+ memset(ret, 0 , sizeof(xmlXPathContext));
ret->doc = doc;
ret->node = NULL;
@@ -6227,7 +6227,7 @@ xmlXPathNewParserContext(const xmlChar *str, xmlXPathContextPtr ctxt) {
xmlXPathErrMemory(ctxt, "creating parser context\n");
return(NULL);
}
- memset(ret, 0 , (size_t) sizeof(xmlXPathParserContext));
+ memset(ret, 0 , sizeof(xmlXPathParserContext));
ret->cur = ret->base = str;
ret->context = ctxt;
@@ -6263,7 +6263,7 @@ xmlXPathCompParserContext(xmlXPathCompExprPtr comp, xmlXPathContextPtr ctxt) {
xmlXPathErrMemory(ctxt, "creating evaluation context\n");
return(NULL);
}
- memset(ret, 0 , (size_t) sizeof(xmlXPathParserContext));
+ memset(ret, 0 , sizeof(xmlXPathParserContext));
/* Allocate the value stack */
ret->valueTab = (xmlXPathObjectPtr *)
@@ -6361,16 +6361,14 @@ xmlXPathNodeValHash(xmlNodePtr node) {
return(0);
if (string[0] == 0)
return(0);
- return(((unsigned int) string[0]) +
- (((unsigned int) string[1]) << 8));
+ return(string[0] + (string[1] << 8));
case XML_NAMESPACE_DECL:
string = ((xmlNsPtr)node)->href;
if (string == NULL)
return(0);
if (string[0] == 0)
return(0);
- return(((unsigned int) string[0]) +
- (((unsigned int) string[1]) << 8));
+ return(string[0] + (string[1] << 8));
case XML_ATTRIBUTE_NODE:
tmp = ((xmlAttrPtr) node)->children;
break;
@@ -6392,14 +6390,13 @@ xmlXPathNodeValHash(xmlNodePtr node) {
}
if ((string != NULL) && (string[0] != 0)) {
if (len == 1) {
- return(ret + (((unsigned int) string[0]) << 8));
+ return(ret + (string[0] << 8));
}
if (string[1] == 0) {
len = 1;
- ret = (unsigned int) string[0];
+ ret = string[0];
} else {
- return(((unsigned int) string[0]) +
- (((unsigned int) string[1]) << 8));
+ return(string[0] + (string[1] << 8));
}
}
/*
@@ -6448,11 +6445,10 @@ xmlXPathNodeValHash(xmlNodePtr node) {
static unsigned int
xmlXPathStringHash(const xmlChar * string) {
if (string == NULL)
- return((unsigned int) 0);
+ return(0);
if (string[0] == 0)
return(0);
- return(((unsigned int) string[0]) +
- (((unsigned int) string[1]) << 8));
+ return(string[0] + (string[1] << 8));
}
/**
@@ -9197,7 +9193,7 @@ xmlXPathSubstringBeforeFunction(xmlXPathParserContextPtr ctxt, int nargs) {
if (target) {
point = xmlStrstr(str->stringval, find->stringval);
if (point) {
- offset = (int)(point - str->stringval);
+ offset = point - str->stringval;
xmlBufAdd(target, str->stringval, offset);
}
valuePush(ctxt, xmlXPathCacheNewString(ctxt->context,
@@ -9240,7 +9236,7 @@ xmlXPathSubstringAfterFunction(xmlXPathParserContextPtr ctxt, int nargs) {
if (target) {
point = xmlStrstr(str->stringval, find->stringval);
if (point) {
- offset = (int)(point - str->stringval) + xmlStrlen(find->stringval);
+ offset = point - str->stringval + xmlStrlen(find->stringval);
xmlBufAdd(target, &str->stringval[offset],
xmlStrlen(str->stringval) - offset);
}
@@ -9743,7 +9739,7 @@ xmlXPathCurrentChar(xmlXPathParserContextPtr ctxt, int *len) {
} else {
/* 1-byte code */
*len = 1;
- return((int) *cur);
+ return(*cur);
}
encoding_error:
/*
diff --git a/xpointer.c b/xpointer.c
index 71807ac8..63177f5a 100644
--- a/xpointer.c
+++ b/xpointer.c
@@ -268,7 +268,7 @@ xmlXPtrNewPoint(xmlNodePtr node, int indx) {
xmlXPtrErrMemory("allocating point");
return(NULL);
}
- memset(ret, 0 , (size_t) sizeof(xmlXPathObject));
+ memset(ret, 0 , sizeof(xmlXPathObject));
ret->type = XPATH_POINT;
ret->user = (void *) node;
ret->index = indx;
@@ -588,7 +588,7 @@ xmlXPtrLocationSetCreate(xmlXPathObjectPtr val) {
xmlXPtrErrMemory("allocating locationset");
return(NULL);
}
- memset(ret, 0 , (size_t) sizeof(xmlLocationSet));
+ memset(ret, 0 , sizeof(xmlLocationSet));
if (val != NULL) {
ret->locTab = (xmlXPathObjectPtr *) xmlMalloc(XML_RANGESET_DEFAULT *
sizeof(xmlXPathObjectPtr));
@@ -598,7 +598,7 @@ xmlXPtrLocationSetCreate(xmlXPathObjectPtr val) {
return(NULL);
}
memset(ret->locTab, 0 ,
- XML_RANGESET_DEFAULT * (size_t) sizeof(xmlXPathObjectPtr));
+ XML_RANGESET_DEFAULT * sizeof(xmlXPathObjectPtr));
ret->locMax = XML_RANGESET_DEFAULT;
ret->locTab[ret->locNr++] = val;
}
@@ -640,7 +640,7 @@ xmlXPtrLocationSetAdd(xmlLocationSetPtr cur, xmlXPathObjectPtr val) {
return;
}
memset(cur->locTab, 0 ,
- XML_RANGESET_DEFAULT * (size_t) sizeof(xmlXPathObjectPtr));
+ XML_RANGESET_DEFAULT * sizeof(xmlXPathObjectPtr));
cur->locMax = XML_RANGESET_DEFAULT;
} else if (cur->locNr == cur->locMax) {
xmlXPathObjectPtr *temp;
@@ -773,7 +773,7 @@ xmlXPtrNewLocationSetNodes(xmlNodePtr start, xmlNodePtr end) {
xmlXPtrErrMemory("allocating locationset");
return(NULL);
}
- memset(ret, 0 , (size_t) sizeof(xmlXPathObject));
+ memset(ret, 0 , sizeof(xmlXPathObject));
ret->type = XPATH_LOCATIONSET;
if (end == NULL)
ret->user = xmlXPtrLocationSetCreate(xmlXPtrNewCollapsedRange(start));
@@ -800,7 +800,7 @@ xmlXPtrNewLocationSetNodeSet(xmlNodeSetPtr set) {
xmlXPtrErrMemory("allocating locationset");
return(NULL);
}
- memset(ret, 0 , (size_t) sizeof(xmlXPathObject));
+ memset(ret, 0, sizeof(xmlXPathObject));
ret->type = XPATH_LOCATIONSET;
if (set != NULL) {
int i;
@@ -836,7 +836,7 @@ xmlXPtrWrapLocationSet(xmlLocationSetPtr val) {
xmlXPtrErrMemory("allocating locationset");
return(NULL);
}
- memset(ret, 0 , (size_t) sizeof(xmlXPathObject));
+ memset(ret, 0, sizeof(xmlXPathObject));
ret->type = XPATH_LOCATIONSET;
ret->user = (void *) val;
return(ret);