summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Pipping <sebastian@pipping.org>2022-02-14 03:48:27 +0100
committerSebastian Pipping <sebastian@pipping.org>2022-02-20 19:05:36 +0100
commit7764b534e1f1b8514b9269c295ee1943dbb87126 (patch)
tree2f407ebe25f94ffe8e7ed480a61b4652a1518376
parenta4ffcb1231fbb5aeef286e476776c491f7ba6684 (diff)
downloadlibexpat-git-7764b534e1f1b8514b9269c295ee1943dbb87126.tar.gz
lib: Add a multi-char version of poolAppendChar based on memcpy
-rw-r--r--expat/lib/xmlparse.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/expat/lib/xmlparse.c b/expat/lib/xmlparse.c
index 5825b1f1..ba506a33 100644
--- a/expat/lib/xmlparse.c
+++ b/expat/lib/xmlparse.c
@@ -536,6 +536,7 @@ static XML_Char *poolAppend(STRING_POOL *pool, const ENCODING *enc,
static XML_Char *poolStoreString(STRING_POOL *pool, const ENCODING *enc,
const char *ptr, const char *end);
static XML_Bool FASTCALL poolGrow(STRING_POOL *pool);
+static XML_Bool FASTCALL poolGrowUntil(STRING_POOL *pool, size_t needed);
static const XML_Char *FASTCALL poolCopyString(STRING_POOL *pool,
const XML_Char *s);
static const XML_Char *poolCopyStringN(STRING_POOL *pool, const XML_Char *s,
@@ -599,6 +600,11 @@ static unsigned long getDebugLevel(const char *variableName,
(((pool)->ptr == (pool)->end && ! poolGrow(pool)) \
? 0 \
: ((*((pool)->ptr)++ = c), 1))
+#define poolAppendChars(pool, s, len) \
+ (! poolGrowUntil((pool), (len)) \
+ ? 0 \
+ : (memcpy((pool)->ptr, (s), (len) * sizeof(XML_Char)), \
+ (pool)->ptr += (len), 1))
struct XML_ParserStruct {
/* The first member must be m_userData so that the XML_GetUserData
@@ -7268,6 +7274,19 @@ poolGrow(STRING_POOL *pool) {
return XML_TRUE;
}
+static XML_Bool FASTCALL
+poolGrowUntil(STRING_POOL *pool, size_t needed) {
+ for (;;) {
+ const size_t available = pool->end - pool->ptr;
+ if (available >= needed) {
+ return XML_TRUE;
+ }
+ if (! poolGrow(pool)) {
+ return XML_FALSE;
+ }
+ }
+}
+
static int FASTCALL
nextScaffoldPart(XML_Parser parser) {
DTD *const dtd = parser->m_dtd; /* save one level of indirection */