From 982346047dcf207e78c3208a44d0080044f834be Mon Sep 17 00:00:00 2001 From: Attila Kovacs Date: Sun, 22 Dec 2024 15:33:20 +0100 Subject: [PATCH] More fixes to JSON string buffer sizing --- src/xjson.c | 10 +++++----- src/xstruct.c | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/xjson.c b/src/xjson.c index 30989d6..d5e3891 100644 --- a/src/xjson.c +++ b/src/xjson.c @@ -1097,10 +1097,10 @@ static int GetArrayStringSize(int prefixSize, char *ptr, XType type, int ndim, c switch(type) { case X_UNKNOWN: - return prefixSize + sizeof(JSON_NULL); + return sizeof(JSON_NULL); case X_STRUCT: - m = GetObjectStringSize(prefixSize, (XStructure *) ptr); + m = GetObjectStringSize(prefixSize + ilen, (XStructure *) ptr); prop_error(fn, m); return m; @@ -1108,11 +1108,11 @@ static int GetArrayStringSize(int prefixSize, char *ptr, XType type, int ndim, c case X_RAW: m = GetJsonStringSize(*(char **) ptr, TERMINATED_STRING); prop_error(fn, m); - return m + prefixSize; + return m; case X_FIELD: { const XField *f = (XField *) ptr; - m = GetFieldStringSize(prefixSize, f, TRUE); + m = GetFieldStringSize(prefixSize + ilen, f, TRUE); prop_error(fn, m); return m; } @@ -1120,7 +1120,7 @@ static int GetArrayStringSize(int prefixSize, char *ptr, XType type, int ndim, c default: m = xStringElementSizeOf(type); prop_error(fn, m); - return m + prefixSize; + return m; } } else { diff --git a/src/xstruct.c b/src/xstruct.c index 53d406f..02c96ae 100644 --- a/src/xstruct.c +++ b/src/xstruct.c @@ -1007,9 +1007,9 @@ int xReduceField(XField *f) { } /** - * Recursively eliminates unneccessary embedding of singular structures inside a structure as well as reduces the - * dimension of all array fields with xReduceDims(). It will also eliminate the unnecessary wrapping of a singular - * array into a single XField. + * Recursively eliminates unneccessary embedding of singular structures inside a structure and reduces the + * dimensions of array fields with xReduceDims(), recursively. It will also eliminate the unnecessary wrapping + * of a singular array into a single XField. * * @param s Pointer to a structure. * @return X_SUCCESS (0) if successful or else X_STRUCT_INVALID if the argument is NULL (errno is