mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-17 22:50:51 +00:00
make plist arrays unlimited in size
This commit is contained in:
parent
55eb6c3ab1
commit
d5003f363d
2 changed files with 12 additions and 6 deletions
|
@ -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;
|
||||
|
||||
|
|
|
@ -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)
|
||||
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;
|
||||
|
|
Loading…
Reference in a new issue