< prev index next >

test/hotspot/jtreg/vmTestbase/nsk/share/jni/ExceptionCheckingJniEnv.cpp

Print this page
rev 52432 : 8213622: Windows VS2013 build failure - "'snprintf': identifier not found"
Summary:
Reviewed-by:

*** 21,30 **** --- 21,31 ---- * or visit www.oracle.com if you need additional information or have any * questions. */ #include <stdlib.h> + #include <string.h> #include "ExceptionCheckingJniEnv.hpp" namespace {
*** 46,69 **** ProcessReturnError(); } } void ProcessReturnError() { ! int len = snprintf(NULL, 0, "%s : %s", _base_msg, _return_error) + 1; ! if (len <= 0) { ! _env->HandleError(_return_error); ! return; ! } char* full_message = (char*) malloc(len); if (full_message == NULL) { _env->HandleError(_return_error); return; } ! snprintf(full_message, len, "%s : %s", _base_msg, _return_error); _env->HandleError(full_message); free(full_message); } --- 47,89 ---- ProcessReturnError(); } } void ProcessReturnError() { ! // This is error prone, but: ! // - Seems like we cannot use std::string (due to windows/solaris not ! // building when used, seemingly due to exception libraries not linking). ! // - Seems like we cannot use sprintf due to VS2013 (JDK-8213622). ! // ! // We are aiming to do: ! // snprintf(full_message, len, "%s : %s", _base_msg, _return_error); ! // but will use strlen + strncpy instead. ! size_t base_len = strlen(_base_msg); ! const char* between_msg = " : "; ! size_t between_len = strlen(between_msg); ! size_t return_len = strlen(_return_error) + 1; ! size_t len = base_len + between_len + return_len; char* full_message = (char*) malloc(len); if (full_message == NULL) { _env->HandleError(_return_error); return; } ! // Now we construct the string using strcpy to not use sprintf/std::string ! // instead of: ! // snprintf(full_message, len, "%s : %s", _base_msg, _return_error); ! strncpy(full_message, _base_msg, base_len); ! strncpy(full_message + base_len, between_msg, between_len); ! strncpy(full_message + base_len + between_len, _return_error, return_len); ! full_message[len] = '\0'; ! ! // -1 due to the '\0' not counted by strlen but is counted for the allocation. ! if (strlen(full_message) != len - 1) { ! _env->GetJNIEnv()->FatalError("Length of message is not what was expected"); ! } _env->HandleError(full_message); free(full_message); }
< prev index next >