From 0d945fe20e87ac7ada2d565f751146c2e8fa1ed6 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Mon, 7 Nov 2022 15:43:20 +0100 Subject: Fix deprecation warnings about printf() on macOS The new Xcode 14.1 brings the new Apple Clang compiler which considers sprintf unsafe and geenrates deprecation warnings suggesting to sue snprintf instead. This only happens for C++ code by default, and C code can still use sprintf without any warning. This changes does the following: - Whenever is trivial replace sprintf() with BLI_snprintf. - For all other cases use the newly introduced BLI_sprintf which is a wrapper around sprintf() but without warning. There is a discouragement note in the BLI_sprintf comment to suggest use of BLI_snprintf when the size is known. Differential Revision: https://developer.blender.org/D16410 --- source/blender/blenlib/intern/winstuff.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'source/blender/blenlib/intern/winstuff.c') diff --git a/source/blender/blenlib/intern/winstuff.c b/source/blender/blenlib/intern/winstuff.c index 7e2c5e8f1dd..3a574b60ae2 100644 --- a/source/blender/blenlib/intern/winstuff.c +++ b/source/blender/blenlib/intern/winstuff.c @@ -110,7 +110,7 @@ bool BLI_windows_register_blend_extension(const bool background) &hkey, &dwd); if (lresult == ERROR_SUCCESS) { - sprintf(buffer, "\"%s\" \"%%1\"", BlPath); + BLI_snprintf(buffer, sizeof(buffer), "\"%s\" \"%%1\"", BlPath); lresult = RegSetValueEx(hkey, NULL, 0, REG_SZ, (BYTE *)buffer, strlen(buffer) + 1); RegCloseKey(hkey); } @@ -129,7 +129,7 @@ bool BLI_windows_register_blend_extension(const bool background) &hkey, &dwd); if (lresult == ERROR_SUCCESS) { - sprintf(buffer, "\"%s\", 1", BlPath); + BLI_snprintf(buffer, sizeof(buffer), "\"%s\", 1", BlPath); lresult = RegSetValueEx(hkey, NULL, 0, REG_SZ, (BYTE *)buffer, strlen(buffer) + 1); RegCloseKey(hkey); } @@ -167,10 +167,12 @@ bool BLI_windows_register_blend_extension(const bool background) RegCloseKey(root); printf("success (%s)\n", usr_mode ? "user" : "system"); if (!background) { - sprintf(MBox, - "File extension registered for %s.", - usr_mode ? "the current user. To register for all users, run as an administrator" : - "all users"); + BLI_snprintf(MBox, + sizeof(MBox), + "File extension registered for %s.", + usr_mode ? + "the current user. To register for all users, run as an administrator" : + "all users"); MessageBox(0, MBox, "Blender", MB_OK | MB_ICONINFORMATION); } return true; -- cgit v1.2.3