From e2cc394713b838c43fc91fe8f07afb61dbb019f6 Mon Sep 17 00:00:00 2001 From: KONNO Kazuhiro Date: Tue, 4 Jul 2023 14:11:06 +0900 Subject: [PATCH] macOS: Stop using sprintf in java.desktop This commit backports the changes for macOS from Java 21, replacing sprintf() by snprintf(). Signed-off-by: KONNO Kazuhiro --- .../macosx/native/libawt_lwawt/font/AWTStrike.m | 7 ++++++- .../macosx/native/libjsound/PLATFORM_API_MacOSX_Ports.cpp | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/java.desktop/macosx/native/libawt_lwawt/font/AWTStrike.m b/src/java.desktop/macosx/native/libawt_lwawt/font/AWTStrike.m index 2c991a2fc2f..bc1a4908c71 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/font/AWTStrike.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/font/AWTStrike.m @@ -22,6 +22,11 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ +/* + * =========================================================================== + * (C) Copyright IBM Corp. 2023 All Rights Reserved. + * =========================================================================== + */ #import "java_awt_geom_PathIterator.h" #import "sun_font_CStrike.h" @@ -102,7 +107,7 @@ + (AWTStrike *) awtStrikeForFont:(AWTFont *)awtFont #define AWT_FONT_CLEANUP_FINISH \ if (_fontThrowJavaException == YES) { \ char s[512]; \ - sprintf(s, "%s-%s:%d", __FILE__, __FUNCTION__, __LINE__); \ + snprintf(s, sizeof(s), "%s-%s:%d", __FILE__, __FUNCTION__, __LINE__); \ JNU_ThrowByName(env, "java/lang/RuntimeException", s); \ } diff --git a/src/java.desktop/macosx/native/libjsound/PLATFORM_API_MacOSX_Ports.cpp b/src/java.desktop/macosx/native/libjsound/PLATFORM_API_MacOSX_Ports.cpp index ed2de311c22..cf2c07f3a4b 100644 --- a/src/java.desktop/macosx/native/libjsound/PLATFORM_API_MacOSX_Ports.cpp +++ b/src/java.desktop/macosx/native/libjsound/PLATFORM_API_MacOSX_Ports.cpp @@ -22,6 +22,11 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ +/* + * =========================================================================== + * (C) Copyright IBM Corp. 2023 All Rights Reserved. + * =========================================================================== + */ //#define USE_ERROR //#define USE_TRACE @@ -635,7 +640,7 @@ void PORT_GetControls(void* id, INT32 portIndex, PortControlCreator* creator) { if (channelName == NULL) { return; } - sprintf(channelName, "Ch %d", ch); + snprintf(channelName, 16, "Ch %d", ch); } void* jControls[2];