mirror of
https://github.com/GNOME/libxml2.git
synced 2025-10-14 02:58:39 +08:00
parser: Move xmlSaturatedAdd to private header
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
#ifndef XML_PARSER_H_PRIVATE__
|
||||
#define XML_PARSER_H_PRIVATE__
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#include <libxml/parser.h>
|
||||
#include <libxml/xmlversion.h>
|
||||
|
||||
@@ -153,4 +155,20 @@ xmlExpandEntitiesInAttValue(xmlParserCtxt *ctxt, const xmlChar *str,
|
||||
XML_HIDDEN void
|
||||
xmlParserCheckEOF(xmlParserCtxt *ctxt, xmlParserErrors code);
|
||||
|
||||
static XML_INLINE void
|
||||
xmlSaturatedAdd(unsigned long *dst, unsigned long val) {
|
||||
if (val > ULONG_MAX - *dst)
|
||||
*dst = ULONG_MAX;
|
||||
else
|
||||
*dst += val;
|
||||
}
|
||||
|
||||
static XML_INLINE void
|
||||
xmlSaturatedAddSizeT(unsigned long *dst, size_t val) {
|
||||
if (val > ULONG_MAX - *dst)
|
||||
*dst = ULONG_MAX;
|
||||
else
|
||||
*dst += val;
|
||||
}
|
||||
|
||||
#endif /* XML_PARSER_H_PRIVATE__ */
|
||||
|
16
parser.c
16
parser.c
@@ -408,22 +408,6 @@ xmlNsWarn(xmlParserCtxtPtr ctxt, xmlParserErrors error,
|
||||
info1, info2, info3, 0, msg, info1, info2, info3);
|
||||
}
|
||||
|
||||
static void
|
||||
xmlSaturatedAdd(unsigned long *dst, unsigned long val) {
|
||||
if (val > ULONG_MAX - *dst)
|
||||
*dst = ULONG_MAX;
|
||||
else
|
||||
*dst += val;
|
||||
}
|
||||
|
||||
static void
|
||||
xmlSaturatedAddSizeT(unsigned long *dst, size_t val) {
|
||||
if (val > ULONG_MAX - *dst)
|
||||
*dst = ULONG_MAX;
|
||||
else
|
||||
*dst += val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for non-linear entity expansion behaviour.
|
||||
*
|
||||
|
@@ -697,11 +697,7 @@ xmlParserShrink(xmlParserCtxt *ctxt) {
|
||||
|
||||
if (res > 0) {
|
||||
used -= res;
|
||||
if ((res > ULONG_MAX) ||
|
||||
(in->consumed > ULONG_MAX - (unsigned long)res))
|
||||
in->consumed = ULONG_MAX;
|
||||
else
|
||||
in->consumed += res;
|
||||
xmlSaturatedAddSizeT(&in->consumed, res);
|
||||
}
|
||||
|
||||
xmlBufUpdateInput(buf->buffer, in, used);
|
||||
@@ -732,11 +728,7 @@ xmlParserInputShrink(xmlParserInput *in) {
|
||||
ret = xmlBufShrink(in->buf->buffer, used - LINE_LEN);
|
||||
if (ret > 0) {
|
||||
used -= ret;
|
||||
if ((ret > ULONG_MAX) ||
|
||||
(in->consumed > ULONG_MAX - (unsigned long)ret))
|
||||
in->consumed = ULONG_MAX;
|
||||
else
|
||||
in->consumed += ret;
|
||||
xmlSaturatedAddSizeT(&in->consumed, ret);
|
||||
}
|
||||
|
||||
xmlBufUpdateInput(in->buf->buffer, in, used);
|
||||
|
Reference in New Issue
Block a user