8064779: Add additional comments for "8062370: Various minor code improvements"
authorcoleenp
Mon, 17 Nov 2014 11:26:43 -0500
changeset 27667 3c814b51da6c
parent 27666 0b48f6967bbc
child 27668 d373a4781717
8064779: Add additional comments for "8062370: Various minor code improvements" Summary: Provide additional comments to jio_snprintf and jio_vsnprintf Reviewed-by: simonis, coleenp, mgronlun Contributed-by: thomas.stuefe@sap.com
hotspot/src/share/vm/prims/jvm.cpp
hotspot/src/share/vm/prims/jvm.h
--- a/hotspot/src/share/vm/prims/jvm.cpp	Mon Nov 17 09:36:40 2014 +0100
+++ b/hotspot/src/share/vm/prims/jvm.cpp	Mon Nov 17 11:26:43 2014 -0500
@@ -2593,6 +2593,10 @@
   if ((intptr_t)count <= 0) return -1;
 
   int result = vsnprintf(str, count, fmt, args);
+  // Note: on truncation vsnprintf(3) on Unix returns numbers of
+  // characters which would have been written had the buffer been large
+  // enough; on Windows, it returns -1. We handle both cases here and
+  // always return -1, and perform null termination.
   if ((result > 0 && (size_t)result >= count) || result == -1) {
     str[count - 1] = '\0';
     result = -1;
--- a/hotspot/src/share/vm/prims/jvm.h	Mon Nov 17 09:36:40 2014 +0100
+++ b/hotspot/src/share/vm/prims/jvm.h	Mon Nov 17 11:26:43 2014 -0500
@@ -1167,10 +1167,14 @@
  * be renamed to JVM_* in the future?
  */
 
-/*
- * BE CAREFUL! The following functions do not implement the
- * full feature set of standard C printf formats.
- */
+/* jio_snprintf() and jio_vsnprintf() behave like snprintf(3) and vsnprintf(3),
+ *  respectively, with the following differences:
+ * - The string written to str is always zero-terminated, also in case of
+ *   truncation (count is too small to hold the result string), unless count
+ *   is 0. In case of truncation count-1 characters are written and '\0'
+ *   appendend.
+ * - If count is too small to hold the whole string, -1 is returned across
+ *   all platforms. */
 JNIEXPORT int
 jio_vsnprintf(char *str, size_t count, const char *fmt, va_list args);