From 57003866bf9d794e291e4f346ca84d4e954c9f0d Mon Sep 17 00:00:00 2001 From: ray Date: Sun, 7 Jun 2009 08:39:13 +0000 Subject: More cvs/diff/rcs convergence: 1. Mostly variable/function renaming, SIZE_T_MAX->SIZE_MAX, and spacing. 2. One strchr -> strncspn. 3. diff had a weird thing where it set file[12] = ofile[12] but never updated file or ofile, then if file and ofile were different it freed it. I removed it. OK millert --- usr.bin/diff/xmalloc.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'usr.bin/diff/xmalloc.c') diff --git a/usr.bin/diff/xmalloc.c b/usr.bin/diff/xmalloc.c index 125a6deea3b..b5340a9fa60 100644 --- a/usr.bin/diff/xmalloc.c +++ b/usr.bin/diff/xmalloc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: xmalloc.c,v 1.1 2007/05/29 18:24:56 ray Exp $ */ +/* $OpenBSD: xmalloc.c,v 1.2 2009/06/07 08:39:13 ray Exp $ */ /* * Author: Tatu Ylonen * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland @@ -35,6 +35,22 @@ xmalloc(size_t size) return ptr; } +void * +xcalloc(size_t nmemb, size_t size) +{ + void *ptr; + + if (size == 0 || nmemb == 0) + errx(1, "xcalloc: zero size"); + if (SIZE_MAX / nmemb < size) + errx(1, "xcalloc: nmemb * size > SIZE_MAX"); + ptr = calloc(nmemb, size); + if (ptr == NULL) + errx(1, "xcalloc: out of memory (allocating %lu bytes)", + (u_long)(size * nmemb)); + return ptr; +} + void * xrealloc(void *ptr, size_t nmemb, size_t size) { @@ -43,7 +59,7 @@ xrealloc(void *ptr, size_t nmemb, size_t size) if (new_size == 0) errx(2, NULL); - if (SIZE_T_MAX / nmemb < size) + if (SIZE_MAX / nmemb < size) errx(2, NULL); if (ptr == NULL) new_ptr = malloc(new_size); -- cgit v1.2.3-59-g8ed1b