diff options
Diffstat (limited to 'newlib/libc/stdio/vsnprintf.c')
-rw-r--r-- | newlib/libc/stdio/vsnprintf.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/newlib/libc/stdio/vsnprintf.c b/newlib/libc/stdio/vsnprintf.c index 9fc1b2d89..e935b49c1 100644 --- a/newlib/libc/stdio/vsnprintf.c +++ b/newlib/libc/stdio/vsnprintf.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 @@ -29,6 +29,7 @@ static char sccsid[] = "%W% (Berkeley) %G%"; #else #include <varargs.h> #endif +#include <errno.h> #ifndef _REENT_ONLY @@ -41,12 +42,20 @@ _DEFUN(vsnprintf, (str, size, fmt, ap), { int ret; FILE f; + struct _reent *ptr = _REENT; + if (size > INT_MAX) + { + ptr->_errno = EOVERFLOW; + return EOF; + } f._flags = __SWR | __SSTR; f._bf._base = f._p = (unsigned char *) str; f._bf._size = f._w = (size > 0 ? size - 1 : 0); f._file = -1; /* No file. */ - ret = _vfprintf_r (_REENT, &f, fmt, ap); + ret = _vfprintf_r (ptr, &f, fmt, ap); + if (ret < EOF) + ptr->_errno = EOVERFLOW; if (size > 0) *f._p = 0; return ret; @@ -65,11 +74,18 @@ _DEFUN(_vsnprintf_r, (ptr, str, size, fmt, ap), int ret; FILE f; + if (size > INT_MAX) + { + ptr->_errno = EOVERFLOW; + return EOF; + } f._flags = __SWR | __SSTR; f._bf._base = f._p = (unsigned char *) str; f._bf._size = f._w = (size > 0 ? size - 1 : 0); f._file = -1; /* No file. */ ret = _vfprintf_r (ptr, &f, fmt, ap); + if (ret < EOF) + ptr->_errno = EOVERFLOW; if (size > 0) *f._p = 0; return ret; |