Mercurial > hg > graal-jvmci-8
comparison src/share/vm/prims/jvm.cpp @ 23967:c48b303692bb jdk8u111-b09
8162419: closed/com/oracle/jfr/runtime/TestVMInfoEvent.sh failing after JDK-8155968
Summary: Under error conditions, always return -1 and perform null termination regardless of the behavior of underlying vsnprintf() implementation.
Reviewed-by: dholmes, cjplummer
author | shshahma |
---|---|
date | Tue, 16 Aug 2016 08:59:54 +0000 |
parents | 0cdf9eb633c4 |
children | f13e777eb255 1ccd27199595 |
comparison
equal
deleted
inserted
replaced
23966:632e5df21897 | 23967:c48b303692bb |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
2866 | 2866 |
2867 ATTRIBUTE_PRINTF(3, 0) | 2867 ATTRIBUTE_PRINTF(3, 0) |
2868 int jio_vsnprintf(char *str, size_t count, const char *fmt, va_list args) { | 2868 int jio_vsnprintf(char *str, size_t count, const char *fmt, va_list args) { |
2869 // see bug 4399518, 4417214 | 2869 // see bug 4399518, 4417214 |
2870 if ((intptr_t)count <= 0) return -1; | 2870 if ((intptr_t)count <= 0) return -1; |
2871 return vsnprintf(str, count, fmt, args); | 2871 |
2872 int result = vsnprintf(str, count, fmt, args); | |
2873 // Note: on truncation vsnprintf(3) on Unix returns number of | |
2874 // characters which would have been written had the buffer been large | |
2875 // enough; on Windows, it returns -1. We handle both cases here and | |
2876 // always return -1, and perform null termination. | |
2877 if ((result > 0 && (size_t)result >= count) || result == -1) { | |
2878 str[count - 1] = '\0'; | |
2879 result = -1; | |
2880 } | |
2881 | |
2882 return result; | |
2872 } | 2883 } |
2873 | 2884 |
2874 ATTRIBUTE_PRINTF(3, 0) | 2885 ATTRIBUTE_PRINTF(3, 0) |
2875 int jio_snprintf(char *str, size_t count, const char *fmt, ...) { | 2886 int jio_snprintf(char *str, size_t count, const char *fmt, ...) { |
2876 va_list args; | 2887 va_list args; |