diff options
Diffstat (limited to 'newlib/libc/stdio/asiprintf.c')
-rw-r--r-- | newlib/libc/stdio/asiprintf.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/newlib/libc/stdio/asiprintf.c b/newlib/libc/stdio/asiprintf.c index e8e10bf38..afb1f7c33 100644 --- a/newlib/libc/stdio/asiprintf.c +++ b/newlib/libc/stdio/asiprintf.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 @@ -57,8 +57,11 @@ _asiprintf_r(ptr, strp, fmt, va_alist) #endif ret = vfiprintf (&f, fmt, ap); va_end (ap); - *f._p = 0; - *strp = f._bf._base; + if (ret >= 0) + { + *f._p = 0; + *strp = f._bf._base; + } return (ret); } @@ -79,7 +82,7 @@ asiprintf(strp, fmt, va_alist) int ret; va_list ap; FILE f; - + /* mark a zero-length reallocatable buffer */ f._flags = __SWR | __SSTR | __SMBF; f._bf._base = f._p = NULL; @@ -92,8 +95,11 @@ asiprintf(strp, fmt, va_alist) #endif ret = vfiprintf (&f, fmt, ap); va_end (ap); - *f._p = 0; - *strp = f._bf._base; + if (ret >= 0) + { + *f._p = 0; + *strp = f._bf._base; + } return (ret); } |