--- libaitio/src/Attic/array.c 2011/05/19 03:01:20 1.2.4.2 +++ libaitio/src/Attic/array.c 2011/05/19 04:05:14 1.2.4.4 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: array.c,v 1.2.4.2 2011/05/19 03:01:20 misho Exp $ +* $Id: array.c,v 1.2.4.4 2011/05/19 04:05:14 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -128,12 +128,13 @@ io_arrayTo(array_t * __restrict arr) if (!arr || !io_arraySize(arr)) return NULL; - args = (char **) calloc(io_arraySize(arr), sizeof(char*)); + args = (char **) calloc(io_arraySize(arr) + 1, sizeof(char*)); if (!args) { LOGERR; return NULL; } else memcpy(args, arr->arr_data, io_arraySize(arr) * sizeof(char*)); + args[io_arraySize(arr)] = NULL; return args; } @@ -225,13 +226,20 @@ io_arrayGrow(array_t * __restrict arr, int newNumItems */ arr->arr_num = newNumItems; - data = realloc(arr->arr_data, io_arraySize(arr) * sizeof(void*)); - if (!data) { - LOGERR; - return -1; - } else - arr->arr_data = data; - memset(arr->arr_data + (io_arraySize(arr) - n), 0, n * sizeof(void*)); + if (io_arraySize(arr)) { + data = realloc(arr->arr_data, io_arraySize(arr) * sizeof(void*)); + if (!data) { + LOGERR; + return -1; + } else + arr->arr_data = data; + + memset(arr->arr_data + (io_arraySize(arr) - n), 0, n * sizeof(void*)); + } else { + if (arr->arr_data) + free(arr->arr_data); + arr->arr_data = NULL; + } return 0; }