8308022: update for deprecated sprintf for java.base

Reviewed-by: naoto
This commit is contained in:
Xue-Lei Andrew Fan 2023-05-31 16:26:48 +00:00
parent 1264902517
commit 42ca6e6942
6 changed files with 37 additions and 32 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2023, 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
@ -134,18 +134,19 @@ getEncodingInternal(LCID lcid)
static char* getConsoleEncoding()
{
char* buf = malloc(16);
size_t buflen = 16;
char* buf = malloc(buflen);
int cp;
if (buf == NULL) {
return NULL;
}
cp = GetConsoleCP();
if (cp >= 874 && cp <= 950)
sprintf(buf, "ms%d", cp);
snprintf(buf, buflen, "ms%d", cp);
else if (cp == 65001)
sprintf(buf, "UTF-8");
snprintf(buf, buflen, "UTF-8");
else
sprintf(buf, "cp%d", cp);
snprintf(buf, buflen, "cp%d", cp);
return buf;
}
@ -575,7 +576,7 @@ GetJavaProperties(JNIEnv* env)
sprops.os_name = "Windows (unknown)";
break;
}
sprintf(buf, "%d.%d", majorVersion, minorVersion);
snprintf(buf, sizeof(buf), "%d.%d", majorVersion, minorVersion);
sprops.os_version = _strdup(buf);
#if defined(_M_AMD64)
sprops.os_arch = "amd64";