summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorRobin Barker <rmbarker.cpan@btinternet.com>2011-01-16 13:41:29 -0800
committerFather Chrysostomos <sprout@cpan.org>2011-01-16 14:20:00 -0800
commit7dac5c648d8c8deacaae358a3f16334d2063161b (patch)
treea4b1d6294cb37c339618bae7f0b9226708358150 /util.c
parent34c029c730b43da9f32a520b0550f9552493424d (diff)
downloadperl-7dac5c648d8c8deacaae358a3f16334d2063161b.tar.gz
util.c handling of return value of vsnprintf
At two points in util.c, there is code that use vsnprintf if available, otherwise vsprintf. The handling of the return value does not reflect which function has been called. The patch tries to improve this.
Diffstat (limited to 'util.c')
-rw-r--r--util.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/util.c b/util.c
index 67a5cbe4d1..8d9d2e48a2 100644
--- a/util.c
+++ b/util.c
@@ -6267,8 +6267,14 @@ Perl_my_snprintf(char *buffer, const Size_t len, const char *format, ...)
retval = vsprintf(buffer, format, ap);
#endif
va_end(ap);
- /* vsnprintf() shows failure with >= len, vsprintf() with < 0 */
- if (retval < 0 || (len > 0 && (Size_t)retval >= len))
+ /* vsprintf() shows failure with < 0 */
+ if (retval < 0
+#ifdef HAS_VSNPRINTF
+ /* vsnprintf() shows failure with >= len */
+ ||
+ (len > 0 && (Size_t)retval >= len)
+#endif
+ )
Perl_croak(aTHX_ "panic: my_snprintf buffer overflow");
return retval;
}
@@ -6307,8 +6313,14 @@ Perl_my_vsnprintf(char *buffer, const Size_t len, const char *format, va_list ap
retval = vsprintf(buffer, format, ap);
# endif
#endif /* #ifdef NEED_VA_COPY */
- /* vsnprintf() shows failure with >= len, vsprintf() with < 0 */
- if (retval < 0 || (len > 0 && (Size_t)retval >= len))
+ /* vsprintf() shows failure with < 0 */
+ if (retval < 0
+#ifdef HAS_VSNPRINTF
+ /* vsnprintf() shows failure with >= len */
+ ||
+ (len > 0 && (Size_t)retval >= len)
+#endif
+ )
Perl_croak(aTHX_ "panic: my_vsnprintf buffer overflow");
return retval;
}