--- libelwix/src/array.c 2013/01/17 10:05:35 1.1.1.1 +++ libelwix/src/array.c 2013/03/25 10:46:41 1.1.1.1.6.2 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: array.c,v 1.1.1.1 2013/01/17 10:05:35 misho Exp $ +* $Id: array.c,v 1.1.1.1.6.2 2013/03/25 10:46:41 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -374,7 +374,7 @@ array_Elem(array_t * __restrict arr, int n, void *data * return: -1 not found empty position, array is full!, >-1 return position of stored element into array */ inline int -array_Push(array_t * __restrict arr, void **data, int nogrow) +array_Push(array_t * __restrict arr, void *data, int nogrow) { int ret = -1; @@ -387,9 +387,8 @@ array_Push(array_t * __restrict arr, void **data, int if (!nogrow && ret >= array_Size(arr) && array_Grow(arr, ret + 1, 0)) return -1; - ret = arr->arr_last++; - if (data) - arr->arr_data[arr->arr_last] = *data; + ret = ++arr->arr_last; + arr->arr_data[arr->arr_last] = data; return ret; } @@ -410,12 +409,13 @@ array_Pop(array_t * __restrict arr, void ** __restrict if (!arr) return -1; - ret = array_Last(arr); - - if (data) - *data = arr->arr_data[ret]; - if (!nodel) - arr->arr_data[arr->arr_last--] = NULL; + if ((ret = array_Last(arr)) != -1) { + if (data) + *data = arr->arr_data[arr->arr_last]; + if (!nodel) + arr->arr_data[arr->arr_last] = NULL; + arr->arr_last--; + } return ret; }