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) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 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
@ -588,14 +588,14 @@ getGMTOffsetID()
// Ignore daylight saving settings to calculate current time difference
localtm.tm_isdst = 0;
int gmt_off = (int)(difftime(mktime(&localtm), mktime(&gmt)) / 60.0);
sprintf(buf, (const char *)"GMT%c%02.2d:%02.2d",
snprintf(buf, sizeof(buf), (const char *)"GMT%c%02.2d:%02.2d",
gmt_off < 0 ? '-' : '+' , abs(gmt_off / 60), gmt_off % 60);
#else
if (strftime(offset, 6, "%z", &localtm) != 5) {
return strdup("GMT");
}
sprintf(buf, (const char *)"GMT%c%c%c:%c%c", offset[0], offset[1], offset[2],
snprintf(buf, sizeof(buf), (const char *)"GMT%c%c%c:%c%c", offset[0], offset[1], offset[2],
offset[3], offset[4]);
#endif
return strdup(buf);

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
@ -387,7 +387,7 @@ CreateExecutionEnvironment(int *pargc, char ***pargv,
if (lastslash)
*lastslash = '\0';
sprintf(new_runpath, LD_LIBRARY_PATH "="
snprintf(new_runpath, new_runpath_size, LD_LIBRARY_PATH "="
"%s:"
"%s/lib:"
"%s/../lib",