Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'newlib/libc/stdio/vsnprintf.c')
-rw-r--r--newlib/libc/stdio/vsnprintf.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/newlib/libc/stdio/vsnprintf.c b/newlib/libc/stdio/vsnprintf.c
index 18df5864a..5ca0ff27b 100644
--- a/newlib/libc/stdio/vsnprintf.c
+++ b/newlib/libc/stdio/vsnprintf.c
@@ -45,10 +45,11 @@ vsnprintf (str, size, fmt, ap)
f._flags = __SWR | __SSTR;
f._bf._base = f._p = (unsigned char *) str;
- f._bf._size = f._w = size;
+ f._bf._size = f._w = (size > 0 ? size - 1 : 0);
f._data = _REENT;
ret = vfprintf (&f, fmt, ap);
- *f._p = 0;
+ if (size > 0)
+ *f._p = 0;
return ret;
}
@@ -65,9 +66,10 @@ vsnprintf_r (ptr, str, size, fmt, ap)
f._flags = __SWR | __SSTR;
f._bf._base = f._p = (unsigned char *) str;
- f._bf._size = f._w = size;
+ f._bf._size = f._w = (size > 0 ? size - 1 : 0);
f._data = ptr;
ret = vfprintf (&f, fmt, ap);
- *f._p = 0;
+ if (size > 0)
+ *f._p = 0;
return ret;
}