< prev index next >

src/share/vm/runtime/java.cpp

Print this page
rev 4140 : 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

*** 1,7 **** /* ! * Copyright (c) 1997, 2011, 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 * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. --- 1,7 ---- /* ! * 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 * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation.
*** 738,764 **** return (e > o) ? 1 : ((e == o) ? 0 : -1); } } void JDK_Version::to_string(char* buffer, size_t buflen) const { size_t index = 0; if (!is_valid()) { jio_snprintf(buffer, buflen, "%s", "(uninitialized)"); } else if (is_partially_initialized()) { jio_snprintf(buffer, buflen, "%s", "(uninitialized) pre-1.6.0"); } else { ! index += jio_snprintf( &buffer[index], buflen - index, "%d.%d", _major, _minor); if (_micro > 0) { ! index += jio_snprintf(&buffer[index], buflen - index, ".%d", _micro); } if (_update > 0) { ! index += jio_snprintf(&buffer[index], buflen - index, "_%02d", _update); } if (_special > 0) { ! index += jio_snprintf(&buffer[index], buflen - index, "%c", _special); } if (_build > 0) { ! index += jio_snprintf(&buffer[index], buflen - index, "-b%02d", _build); } } } --- 738,775 ---- return (e > o) ? 1 : ((e == o) ? 0 : -1); } } void JDK_Version::to_string(char* buffer, size_t buflen) const { + assert(buffer && buflen > 0, "call with useful buffer"); size_t index = 0; if (!is_valid()) { jio_snprintf(buffer, buflen, "%s", "(uninitialized)"); } else if (is_partially_initialized()) { jio_snprintf(buffer, buflen, "%s", "(uninitialized) pre-1.6.0"); } else { ! int rc = jio_snprintf( &buffer[index], buflen - index, "%d.%d", _major, _minor); + if (rc == -1) return; + index += rc; if (_micro > 0) { ! rc = jio_snprintf(&buffer[index], buflen - index, ".%d", _micro); ! if (rc == -1) return; ! index += rc; } if (_update > 0) { ! rc = jio_snprintf(&buffer[index], buflen - index, "_%02d", _update); ! if (rc == -1) return; ! index += rc; } if (_special > 0) { ! rc = jio_snprintf(&buffer[index], buflen - index, "%c", _special); ! if (rc == -1) return; ! index += rc; } if (_build > 0) { ! rc = jio_snprintf(&buffer[index], buflen - index, "-b%02d", _build); ! if (rc == -1) return; ! index += rc; } } }
< prev index next >