These are redundant because further out there is a guard
for "XML_GE == 1" already. In the visual world, the pattern
is this:
> #if XML_GE == 1
> [..]
> # if XML_GE == 1
> [..]
> # endif
> [..]
> #endif
Spotted by Snild Dolkow, thanks!
Co-authored-by: Snild Dolkow <snild@sony.com>
Defining XML_DTD emnables support for external parameter(!)
entities. External general(!) entities have been supported
even with XML_DTD undefined. (Only now with Expat 2.6.0
defining XML_GE as 0 can take that away.)
Until now, the buffer size to grow to has been calculated based on the
distance from the current parse position to the end of the buffer. This
means that the size of any already-parsed data was not considered,
leading to inconsistent buffer growth.
There was also a special case in XML_Parse() when XML_CONTEXT_BYTES was
zero, where the buffer size would be set to twice the incoming string
length. This patch replaces this with an XML_GetBuffer() call.
Growing the buffer based on its total size makes its growth consistent.
The commit includes a test that checks that we can reach the max buffer
size (usually INT_MAX/2 + 1) regardless of previously parsed content.
GitHub CI couldn't allocate the full 1GiB with MinGW/wine32, though it
works locally with the same compiler and wine version. As a workaround,
the test tries to malloc 1GiB, and reduces `maxbuf` to 512MiB in case
of failure.
All tests now run one instance where SINGLE_BYTES is equivalent to a
single XML_Parse call. Using SINGLE_BYTES therefore gives more coverage,
as evidenced by the new failure we now have to avoid in the test, until
it can be fixed.
All tests now run one instance where SINGLE_BYTES is equivalent to a
single XML_Parse call. There is no longer a need for individual tests
to switch between them.
Since commit 091ba48d ("tests: Run SINGLE_BYTES with no chunking"),
all tests are run an extra time with SINGLE_BYTES set to perform just
a single XML_Parse() call. There is no longer a need for individual
tests to switch between them.
Symptom was this compile warning from MinGW GCC 12:
> [..]/expat/tests/memcheck.c: In function ‘tracking_realloc’:
> [..]/expat/tests/memcheck.c:169:25: error: pointer ‘ptr’ may be used after ‘realloc’ [-Werror=use-after-free]
> 169 | entry->allocation = ptr;
> | ~~~~~~~~~~~~~~~~~~^~~~~
> [..]/expat/tests/memcheck.c:166:25: note: call to ‘realloc’ here
> 166 | entry->allocation = realloc(ptr, size);
> | ^~~~~~~~~~~~~~~~~~
The warning is a false positive since the code was only using ptr
when realloc failed where it is documented that the original pointer is
not freed.
The workaround is to no longer override-and-restore entry->allocation
but to only write to it when realloc was successful. The original
value was equal to ptr so the result is the same.
- Start treating -DXML_CONTEXT_BYTES=0 as "no context"
rather than "context of size 0". Was documented as
"must be set to a positive integer", previously.
- Enforce that macro XML_CONTEXT_BYTES is defined at build time to
avoid accidental misbuilds lacking context in environments that
bypass both of Expats official build systems.
- Detect and reject use of negative context size at compile time.