Mercurial > hg > graal-jvmci-8
diff 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 |
line wrap: on
line diff
--- a/src/share/vm/prims/jvm.cpp Mon Aug 08 11:27:33 2016 -0700 +++ b/src/share/vm/prims/jvm.cpp Tue Aug 16 08:59:54 2016 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -2868,7 +2868,18 @@ int jio_vsnprintf(char *str, size_t count, const char *fmt, va_list args) { // see bug 4399518, 4417214 if ((intptr_t)count <= 0) return -1; - return vsnprintf(str, count, fmt, args); + + int result = vsnprintf(str, count, fmt, args); + // Note: on truncation vsnprintf(3) on Unix returns number 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; + } + + return result; } ATTRIBUTE_PRINTF(3, 0)