diff -uprk.orig cvs-1.11.10.orig/src/cvs.h cvs-1.11.10/src/cvs.h --- cvs-1.11.10.orig/src/cvs.h 2003-12-20 20:17:57 +0300 +++ cvs-1.11.10/src/cvs.h 2003-12-20 20:18:11 +0300 @@ -460,6 +460,8 @@ extern void check_numeric PROTO ((const char *getcaller PROTO((void)); char *time_stamp PROTO((char *file)); +extern char *xasprintf (char **ptr, const char *fmt, ...) + __attribute__ ((__format__ (__printf__, 2, 3))); void *xmalloc PROTO((size_t bytes)); void *xrealloc PROTO((void *ptr, size_t bytes)); void expand_string PROTO ((char **, size_t *, size_t)); diff -uprk.orig cvs-1.11.10.orig/src/subr.c cvs-1.11.10/src/subr.c --- cvs-1.11.10.orig/src/subr.c 2003-12-20 20:17:56 +0300 +++ cvs-1.11.10/src/subr.c 2003-12-20 20:25:07 +0300 @@ -9,6 +9,7 @@ */ #include +#include #include "cvs.h" #include "getline.h" @@ -23,6 +24,19 @@ extern char *getlogin (); +char * +xasprintf (char **ptr, const char *fmt, ...) +{ + va_list arg; + + va_start (arg, fmt); + if (vasprintf (ptr, fmt, arg) < 0) + error (1, errno, "vasprintf"); + va_end (arg); + + return *ptr; +} + /* * malloc some data and die if it fails */ @@ -32,17 +46,11 @@ xmalloc (bytes) { char *cp; - /* Parts of CVS try to xmalloc zero bytes and then free it. Some - systems have a malloc which returns NULL for zero byte - allocations but a free which can't handle NULL, so compensate. */ - if (bytes == 0) - bytes = 1; - cp = malloc (bytes); if (cp == NULL) { char buf[80]; - sprintf (buf, "out of memory; can not allocate %lu bytes", + sprintf (buf, "cannot allocate %lu bytes: out of memory", (unsigned long) bytes); error (1, 0, buf); } @@ -59,17 +67,12 @@ xrealloc (ptr, bytes) void *ptr; size_t bytes; { - char *cp; - - if (!ptr) - cp = malloc (bytes); - else - cp = realloc (ptr, bytes); + char *cp = realloc (ptr, bytes); if (cp == NULL) { char buf[80]; - sprintf (buf, "out of memory; can not reallocate %lu bytes", + sprintf (buf, "can not reallocate %lu bytes: out of memory", (unsigned long) bytes); error (1, 0, buf); }