From 99304ce6c4067c1ad11d9c4723580cb09bf1d853 Mon Sep 17 00:00:00 2001 From: Jeff Johnston Date: Mon, 12 Mar 2007 20:30:08 +0000 Subject: 2007-03-12 Eric Blake * libc/stdio/fvwrite.c (__sfvwrite_r): Fix reentrancy. * libc/stdio/vasprintf.c (vasprintf, _vasprintf_r): Pass failed allocation to caller. * libc/stdio/asprintf.c (_asprintf_r, asprintf): Likewise. * libc/stdio/asiprintf.c (_asiprintf_r, asiprintf): Likewise. * libc/stdio/vasiprintf.c (vasiprintf, _vasiprintf_r): Likewise. --- newlib/libc/stdio/vasprintf.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'newlib/libc/stdio/vasprintf.c') diff --git a/newlib/libc/stdio/vasprintf.c b/newlib/libc/stdio/vasprintf.c index 43197d582..2c8065cbc 100644 --- a/newlib/libc/stdio/vasprintf.c +++ b/newlib/libc/stdio/vasprintf.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1990 The Regents of the University of California. + * Copyright (c) 1990, 2007 The Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms are permitted @@ -46,8 +46,11 @@ _DEFUN(vasprintf, (strp, fmt, ap), f._bf._size = f._w = 0; f._file = -1; /* No file. */ ret = _vfprintf_r (_REENT, &f, fmt, ap); - *f._p = 0; - *strp = f._bf._base; + if (ret >= 0) + { + *f._p = 0; + *strp = f._bf._base; + } return ret; } @@ -68,8 +71,10 @@ _DEFUN(_vasprintf_r, (ptr, strp, fmt, ap), f._bf._size = f._w = 0; f._file = -1; /* No file. */ ret = _vfprintf_r (ptr, &f, fmt, ap); - *f._p = 0; - *strp = f._bf._base; + if (ret >= 0) + { + *f._p = 0; + *strp = f._bf._base; + } return ret; } - -- cgit v1.2.3