From 21313cdffdeab10f33ac444fa163fee2c792b6ec Mon Sep 17 00:00:00 2001 From: Ray Lai Date: Thu, 13 Apr 2006 16:55:10 +0000 Subject: Add error checking for vasprintf. Stylistic suggestions from xsa@. OK xsa@ --- usr.bin/cvs/diff.c | 9 ++++++--- usr.bin/cvs/log.c | 47 +++++++++++++++++++++++------------------------ 2 files changed, 29 insertions(+), 27 deletions(-) (limited to 'usr.bin/cvs') diff --git a/usr.bin/cvs/diff.c b/usr.bin/cvs/diff.c index caeaff903bc..c737b1a013f 100644 --- a/usr.bin/cvs/diff.c +++ b/usr.bin/cvs/diff.c @@ -1,4 +1,4 @@ -/* $OpenBSD: diff.c,v 1.87 2006/04/05 01:38:55 ray Exp $ */ +/* $OpenBSD: diff.c,v 1.88 2006/04/13 16:55:09 ray Exp $ */ /* * Copyright (C) Caldera International Inc. 2001-2002. * All rights reserved. @@ -1720,14 +1720,17 @@ void diff_output(const char *fmt, ...) { va_list vap; + int i; char *str; va_start(vap, fmt); - vasprintf(&str, fmt, vap); + i = vasprintf(&str, fmt, vap); + va_end(vap); + if (i == -1) + fatal("diff_output: %s", strerror(errno)); if (diffbuf != NULL) cvs_buf_append(diffbuf, str, strlen(str)); else cvs_printf("%s", str); xfree(str); - va_end(vap); } diff --git a/usr.bin/cvs/log.c b/usr.bin/cvs/log.c index 9bcbfe2fb91..266334467d4 100644 --- a/usr.bin/cvs/log.c +++ b/usr.bin/cvs/log.c @@ -1,4 +1,4 @@ -/* $OpenBSD: log.c,v 1.31 2006/03/15 21:34:59 niallo Exp $ */ +/* $OpenBSD: log.c,v 1.32 2006/04/13 16:55:09 ray Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau * All rights reserved. @@ -306,31 +306,30 @@ cvs_printf(const char *fmt, ...) #if !defined(RCSPROG) if (cvs_cmdop == CVS_OP_SERVER) { ret = vasprintf(&nstr, fmt, vap); - if (ret != -1) { - for (dp = nstr; *dp != '\0';) { - sp = strchr(dp, '\n'); - if (sp == NULL) - for (sp = dp; *sp != '\0'; sp++) - ; - - if (send_m) { - send_m = 0; - putc('M', stdout); - putc(' ', stdout); - } - - fwrite(dp, sizeof(char), (size_t)(sp - dp), - stdout); - - if (*sp != '\n') - break; - - putc('\n', stdout); - send_m = 1; - dp = sp + 1; + if (ret == -1) + fatal("cvs_printf: %s", strerror(errno)); + for (dp = nstr; *dp != '\0';) { + sp = strchr(dp, '\n'); + if (sp == NULL) + for (sp = dp; *sp != '\0'; sp++) + ; + + if (send_m) { + send_m = 0; + putc('M', stdout); + putc(' ', stdout); } - xfree(nstr); + + fwrite(dp, sizeof(char), (size_t)(sp - dp), stdout); + + if (*sp != '\n') + break; + + putc('\n', stdout); + send_m = 1; + dp = sp + 1; } + xfree(nstr); } else #endif ret = vprintf(fmt, vap); -- cgit v1.2.3