Skip to content

Commit

Permalink
Use realloc for everything (Issue #300)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelrsweet committed Mar 6, 2024
1 parent 4c9b2d2 commit c07a57e
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 11 deletions.
4 changes: 3 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 1 addition & 3 deletions mxml-attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 1 addition & 6 deletions mxml-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
1 change: 0 additions & 1 deletion mxml.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c07a57e

Please sign in to comment.