diff options
author | Ran Benita <ran234@gmail.com> | 2012-03-23 23:47:26 +0200 |
---|---|---|
committer | Daniel Stone <daniel@fooishbar.org> | 2012-03-27 14:09:50 +0100 |
commit | 861b0c79c40786c5384adba208f353003b291849 (patch) | |
tree | a72220d24b0e8ee847c30c588a719cd5e38837a8 /src/utils.c | |
parent | 0480f427adcc745c139841a23c80d15a3d44f4db (diff) | |
download | xorg-lib-libxkbcommon-861b0c79c40786c5384adba208f353003b291849.tar.gz |
Rewrite recalloc to the correct type
The recalloc function should be expressed in terms of bytes to match its
name. However uTypedRecalloc retains its type so nothing is changed.
Signed-off-by: Ran Benita <ran234@gmail.com>
Diffstat (limited to 'src/utils.c')
-rw-r--r-- | src/utils.c | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/src/utils.c b/src/utils.c index a9d59c2..031162e 100644 --- a/src/utils.c +++ b/src/utils.c @@ -34,20 +34,17 @@ #include <string.h> void * -recalloc(void * old, unsigned nOld, unsigned nNew, unsigned itemSize) +recalloc(void *ptr, size_t old_size, size_t new_size) { char *rtrn; - if (old == NULL) - rtrn = calloc(nNew, itemSize); - else - { - rtrn = realloc(old, nNew * itemSize); - if ((rtrn) && (nNew > nOld)) - { - memset(&rtrn[nOld * itemSize], 0, (nNew - nOld) * itemSize); - } - } + if (ptr == NULL) + return calloc(1, new_size); + + rtrn = realloc(ptr, new_size); + if (rtrn && new_size > old_size) + memset(&rtrn[old_size], 0, new_size - old_size); + return rtrn; } |