aboutsummaryrefslogtreecommitdiff
path: root/contrib/expat/tests/structdata.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/expat/tests/structdata.c')
-rw-r--r--contrib/expat/tests/structdata.c41
1 files changed, 22 insertions, 19 deletions
diff --git a/contrib/expat/tests/structdata.c b/contrib/expat/tests/structdata.c
index e81b7b184601..e311f1fae3a9 100644
--- a/contrib/expat/tests/structdata.c
+++ b/contrib/expat/tests/structdata.c
@@ -6,8 +6,9 @@
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
- Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
- Copyright (c) 2000-2017 Expat development team
+ Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk>
+ Copyright (c) 2017-2023 Sebastian Pipping <sebastian@pipping.org>
+ Copyright (c) 2022 Sean McBride <sean@rogue-research.com>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
@@ -30,10 +31,12 @@
USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#ifdef HAVE_EXPAT_CONFIG_H
-# include "expat_config.h"
+#if defined(NDEBUG)
+# undef NDEBUG /* because test suite relies on assert(...) at the moment */
#endif
+#include "expat_config.h"
+
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
@@ -58,7 +61,7 @@
static XML_Char *
xmlstrdup(const XML_Char *s) {
size_t byte_count = (xcstrlen(s) + 1) * sizeof(XML_Char);
- XML_Char *dup = malloc(byte_count);
+ XML_Char *const dup = (XML_Char *)malloc(byte_count);
assert(dup != NULL);
memcpy(dup, s, byte_count);
@@ -81,13 +84,13 @@ StructData_AddItem(StructData *storage, const XML_Char *s, int data0, int data1,
assert(storage != NULL);
assert(s != NULL);
if (storage->count == storage->max_count) {
- StructDataEntry *new;
+ StructDataEntry *new_entries;
storage->max_count += STRUCT_EXTENSION_COUNT;
- new = realloc(storage->entries,
- storage->max_count * sizeof(StructDataEntry));
- assert(new != NULL);
- storage->entries = new;
+ new_entries = (StructDataEntry *)realloc(
+ storage->entries, storage->max_count * sizeof(StructDataEntry));
+ assert(new_entries != NULL);
+ storage->entries = new_entries;
}
entry = &storage->entries[storage->count];
@@ -105,17 +108,17 @@ void
StructData_CheckItems(StructData *storage, const StructDataEntry *expected,
int count) {
char buffer[1024];
- int i;
assert(storage != NULL);
assert(expected != NULL);
if (count != storage->count) {
- sprintf(buffer, "wrong number of entries: got %d, expected %d",
- storage->count, count);
+ snprintf(buffer, sizeof(buffer),
+ "wrong number of entries: got %d, expected %d", storage->count,
+ count);
StructData_Dispose(storage);
fail(buffer);
} else {
- for (i = 0; i < count; i++) {
+ for (int i = 0; i < count; i++) {
const StructDataEntry *got = &storage->entries[i];
const StructDataEntry *want = &expected[i];
@@ -128,11 +131,11 @@ StructData_CheckItems(StructData *storage, const StructDataEntry *expected,
} else {
if (got->data0 != want->data0 || got->data1 != want->data1
|| got->data2 != want->data2) {
- sprintf(buffer,
- "struct '%" XML_FMT_STR
- "' expected (%d,%d,%d), got (%d,%d,%d)",
- got->str, want->data0, want->data1, want->data2, got->data0,
- got->data1, got->data2);
+ snprintf(buffer, sizeof(buffer),
+ "struct '%" XML_FMT_STR
+ "' expected (%d,%d,%d), got (%d,%d,%d)",
+ got->str, want->data0, want->data1, want->data2, got->data0,
+ got->data1, got->data2);
StructData_Dispose(storage);
fail(buffer);
}