=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/diff/xmalloc.c,v retrieving revision 1.1 retrieving revision 1.2 diff -c -r1.1 -r1.2 *** src/usr.bin/diff/xmalloc.c 2007/05/29 18:24:56 1.1 --- src/usr.bin/diff/xmalloc.c 2009/06/07 08:39:13 1.2 *************** *** 1,4 **** ! /* $OpenBSD: xmalloc.c,v 1.1 2007/05/29 18:24:56 ray Exp $ */ /* * Author: Tatu Ylonen * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland --- 1,4 ---- ! /* $OpenBSD: xmalloc.c,v 1.2 2009/06/07 08:39:13 ray Exp $ */ /* * Author: Tatu Ylonen * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland *************** *** 36,41 **** --- 36,57 ---- } 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) { void *new_ptr; *************** *** 43,49 **** if (new_size == 0) errx(2, NULL); ! if (SIZE_T_MAX / nmemb < size) errx(2, NULL); if (ptr == NULL) new_ptr = malloc(new_size); --- 59,65 ---- if (new_size == 0) errx(2, NULL); ! if (SIZE_MAX / nmemb < size) errx(2, NULL); if (ptr == NULL) new_ptr = malloc(new_size);