Use realloc for everything (Issue #300)

This commit is contained in:
Michael R Sweet 2024-03-06 16:26:32 -05:00
parent 4c9b2d2260
commit c07a57e02f
No known key found for this signature in database
GPG Key ID: BE67C75EC81F3244
4 changed files with 5 additions and 11 deletions

View File

@ -1,16 +1,18 @@
# Changes in Mini-XML 4.0.0
- Now require C99 support.
- Now require C99 support (Issue #300)
- Now install as "libmxml4" to support installing both Mini-XML 3.x and 4.x at
the same time (use `--disable-libmxml4-prefix` configure option to disable)
- Added `mxmlLoadIO` and `mxmlSaveIO` functions to load and save XML via
callbacks (Issue #98)
- Added new `MXML_TYPE_CDATA`, `MXML_TYPE_COMMENT`, `MXML_TYPE_DECLARATION`, and
`MXML_TYPE_DIRECTIVE` node types (Issue #250)
- Added `mxmlLoadFilename` and `mxmlSaveFilename` functions (Issue #291)
- Renamed `mxml_type_t` enumerations to `MXML_TYPE_xxx` (Issue #251)
- Updated APIs to use bool type instead of an int representing a boolean value.
- Updated the SAX callback to return a `bool` value to control processing
(Issue #51)
- Updated the load and save callbacks to include a context pointer (Issue #106)
# Changes in Mini-XML 3.3.2

View File

@ -246,9 +246,7 @@ mxml_set_attr(mxml_node_t *node, // I - Element node
}
// Add a new attribute...
attr = realloc(node->value.element.attrs, (node->value.element.num_attrs + 1) * sizeof(_mxml_attr_t));
if (!attr)
if ((attr = realloc(node->value.element.attrs, (node->value.element.num_attrs + 1) * sizeof(_mxml_attr_t))) == NULL)
{
_mxml_error("Unable to allocate memory for attribute '%s' in element %s.", name, node->value.element.name);
return (false);

View File

@ -245,12 +245,7 @@ mxmlIndexNew(mxml_node_t *node, // I - XML node tree
{
if (ind->num_nodes >= ind->alloc_nodes)
{
if (!ind->alloc_nodes)
temp = malloc(64 * sizeof(mxml_node_t *));
else
temp = realloc(ind->nodes, (ind->alloc_nodes + 64) * sizeof(mxml_node_t *));
if (!temp)
if ((temp = realloc(ind->nodes, (ind->alloc_nodes + 64) * sizeof(mxml_node_t *))) == NULL)
{
// Unable to allocate memory for the index, so abort...
_mxml_error("Unable to allocate memory for index nodes.");

1
mxml.h
View File

@ -17,7 +17,6 @@
# include <string.h>
# include <ctype.h>
# include <errno.h>
# include <sys/types.h>
# include <limits.h>
# if defined(_WIN32) && !defined(__CUPS_SSIZE_T_DEFINED)
# define __CUPS_SSIZE_T_DEFINED