2913 // Printing support ////////////////////////////////////////////////// |
2913 // Printing support ////////////////////////////////////////////////// |
2914 extern "C" { |
2914 extern "C" { |
2915 |
2915 |
2916 ATTRIBUTE_PRINTF(3, 0) |
2916 ATTRIBUTE_PRINTF(3, 0) |
2917 int jio_vsnprintf(char *str, size_t count, const char *fmt, va_list args) { |
2917 int jio_vsnprintf(char *str, size_t count, const char *fmt, va_list args) { |
2918 // see bug 4399518, 4417214 |
2918 // Reject count values that are negative signed values converted to |
|
2919 // unsigned; see bug 4399518, 4417214 |
2919 if ((intptr_t)count <= 0) return -1; |
2920 if ((intptr_t)count <= 0) return -1; |
2920 |
2921 |
2921 int result = vsnprintf(str, count, fmt, args); |
2922 int result = os::vsnprintf(str, count, fmt, args); |
2922 // Note: on truncation vsnprintf(3) on Unix returns number of |
2923 if (result > 0 && (size_t)result >= count) { |
2923 // characters which would have been written had the buffer been large |
|
2924 // enough; on Windows, it returns -1. We handle both cases here and |
|
2925 // always return -1, and perform null termination. |
|
2926 if ((result > 0 && (size_t)result >= count) || result == -1) { |
|
2927 str[count - 1] = '\0'; |
|
2928 result = -1; |
2924 result = -1; |
2929 } |
2925 } |
2930 |
2926 |
2931 return result; |
2927 return result; |
2932 } |
2928 } |