diff options
author | Jim Meyering <jim@meyering.net> | 2005-06-16 14:52:29 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2005-06-16 14:52:29 +0000 |
commit | 5371690c7f7d08b4064827f14f4af947df0b6f4e (patch) | |
tree | 2cf51f7115cffc3c2141b1b7f0eac4ebbcebe0c0 /lib | |
parent | 8236e056a09e2a860b3dc037ed77baacdd15ac5f (diff) | |
download | coreutils-5371690c7f7d08b4064827f14f4af947df0b6f4e.tar.xz |
(rpl_calloc): Allocate a 1-byte buffer (not 1xS or Nx1)
when either N or S is zero.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/calloc.c | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/lib/calloc.c b/lib/calloc.c index 59c65f0ac..9edbf4552 100644 --- a/lib/calloc.c +++ b/lib/calloc.c @@ -1,6 +1,6 @@ /* calloc() function that is glibc compatible. This wrapper function is required at least on Tru64 UNIX 5.1. - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2005 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -32,10 +32,9 @@ void * rpl_calloc (size_t n, size_t s) { size_t bytes; - if (n == 0) - n = 1; - if (s == 0) - s = 1; + + if (n == 0 || s == 0) + return calloc (1, 1); /* Defend against buggy calloc implementations that mishandle size_t overflow. */ |