mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-10-24 13:33:01 +03:00
parser: Move xmlSaturatedAdd to private header
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
#ifndef XML_PARSER_H_PRIVATE__
|
#ifndef XML_PARSER_H_PRIVATE__
|
||||||
#define XML_PARSER_H_PRIVATE__
|
#define XML_PARSER_H_PRIVATE__
|
||||||
|
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
#include <libxml/parser.h>
|
#include <libxml/parser.h>
|
||||||
#include <libxml/xmlversion.h>
|
#include <libxml/xmlversion.h>
|
||||||
|
|
||||||
@@ -153,4 +155,20 @@ xmlExpandEntitiesInAttValue(xmlParserCtxt *ctxt, const xmlChar *str,
|
|||||||
XML_HIDDEN void
|
XML_HIDDEN void
|
||||||
xmlParserCheckEOF(xmlParserCtxt *ctxt, xmlParserErrors code);
|
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__ */
|
#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);
|
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.
|
* Check for non-linear entity expansion behaviour.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -697,11 +697,7 @@ xmlParserShrink(xmlParserCtxt *ctxt) {
|
|||||||
|
|
||||||
if (res > 0) {
|
if (res > 0) {
|
||||||
used -= res;
|
used -= res;
|
||||||
if ((res > ULONG_MAX) ||
|
xmlSaturatedAddSizeT(&in->consumed, res);
|
||||||
(in->consumed > ULONG_MAX - (unsigned long)res))
|
|
||||||
in->consumed = ULONG_MAX;
|
|
||||||
else
|
|
||||||
in->consumed += res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
xmlBufUpdateInput(buf->buffer, in, used);
|
xmlBufUpdateInput(buf->buffer, in, used);
|
||||||
@@ -732,11 +728,7 @@ xmlParserInputShrink(xmlParserInput *in) {
|
|||||||
ret = xmlBufShrink(in->buf->buffer, used - LINE_LEN);
|
ret = xmlBufShrink(in->buf->buffer, used - LINE_LEN);
|
||||||
if (ret > 0) {
|
if (ret > 0) {
|
||||||
used -= ret;
|
used -= ret;
|
||||||
if ((ret > ULONG_MAX) ||
|
xmlSaturatedAddSizeT(&in->consumed, ret);
|
||||||
(in->consumed > ULONG_MAX - (unsigned long)ret))
|
|
||||||
in->consumed = ULONG_MAX;
|
|
||||||
else
|
|
||||||
in->consumed += ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
xmlBufUpdateInput(in->buf->buffer, in, used);
|
xmlBufUpdateInput(in->buf->buffer, in, used);
|
||||||
|
|||||||
Reference in New Issue
Block a user