From d5003f363dd639f80c8fb3872116e093ce66d335 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 7 Apr 2003 19:29:52 +0000 Subject: [PATCH] make plist arrays unlimited in size --- include/QF/qfplist.h | 6 ++---- libs/util/qfplist.c | 12 ++++++++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/include/QF/qfplist.h b/include/QF/qfplist.h index 29a5012ba..d86c5e352 100644 --- a/include/QF/qfplist.h +++ b/include/QF/qfplist.h @@ -37,9 +37,6 @@ inrange((ch), '0', '9') ? ((ch) - 0x30) \ : (inrange((ch), 'a', 'f') ? ((ch) - 0x57) : ((ch) - 0x37)) -// Maximum number of items in an array -#define MAX_ARRAY_INDEX 128 - typedef enum {QFDictionary, QFArray, QFBinary, QFString} pltype_t; // possible types /* @@ -65,7 +62,8 @@ typedef struct dictkey_s dictkey_t; */ struct plarray_s { int numvals; // Number of items in array - struct plitem_s *values[MAX_ARRAY_INDEX+1]; // Array data + int maxvals; + struct plitem_s **values; // Array data }; typedef struct plarray_s plarray_t; diff --git a/libs/util/qfplist.c b/libs/util/qfplist.c index 78043a134..3a18b9d60 100644 --- a/libs/util/qfplist.c +++ b/libs/util/qfplist.c @@ -120,6 +120,7 @@ PL_FreeItem (plitem_t *item) while (i-- > 0) { PL_FreeItem (((plarray_t *) item->data)->values[i]); } + free (((plarray_t *) item->data)->values); free (item->data); } break; @@ -193,8 +194,15 @@ PL_A_InsertObjectAtIndex (plitem_t *array_item, plitem_t *item, int index) array = (plarray_t *)array_item->data; - if (array->numvals == MAX_ARRAY_INDEX) - return NULL; + if (array->numvals == array->maxvals) { + plitem_t **tmp = realloc (array->values, array->maxvals + 128); + if (!tmp) + return NULL; + array->maxvals += 128; + array->values = tmp; + memset (array->values + array->numvals, 0, + (array->maxvals - array->numvals) * sizeof (plitem_t *)); + } if (index == -1) index = array->numvals;