summaryrefslogtreecommitdiff
path: root/sys/src/ape/lib/ap/gen/calloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/src/ape/lib/ap/gen/calloc.c')
-rw-r--r--sys/src/ape/lib/ap/gen/calloc.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/sys/src/ape/lib/ap/gen/calloc.c b/sys/src/ape/lib/ap/gen/calloc.c
index e52210d84..c080c7b3d 100644
--- a/sys/src/ape/lib/ap/gen/calloc.c
+++ b/sys/src/ape/lib/ap/gen/calloc.c
@@ -2,12 +2,14 @@
#include <string.h>
void *
-calloc(size_t nmemb, size_t size)
+calloc(size_t n, size_t s)
{
- void *mp;
+ void *v;
- nmemb = nmemb*size;
- if(mp = malloc(nmemb))
- memset(mp, 0, nmemb);
- return(mp);
+ if(n > 1 && ((size_t)-1)/n < s)
+ return 0;
+ n *= s;
+ if(v = malloc(n))
+ memset(v, 0, n);
+ return v;
}