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/blenloader/intern/writefile.cc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'source/blender/blenloader/intern/writefile.cc') diff --git a/source/blender/blenloader/intern/writefile.cc b/source/blender/blenloader/intern/writefile.cc index 42bc884098e..6e48b65eb25 100644 --- a/source/blender/blenloader/intern/writefile.cc +++ b/source/blender/blenloader/intern/writefile.cc @@ -1048,7 +1048,7 @@ static void write_global(WriteData *wd, int fileflags, Main *mainvar) if (fileflags & G_FILE_RECOVER_WRITE) { STRNCPY(fg.filepath, mainvar->filepath); } - sprintf(subvstr, "%4d", BLENDER_FILE_SUBVERSION); + BLI_snprintf(subvstr, sizeof(subvstr), "%4d", BLENDER_FILE_SUBVERSION); memcpy(fg.subvstr, subvstr, 4); fg.subversion = BLENDER_FILE_SUBVERSION; @@ -1102,11 +1102,12 @@ static bool write_file_handle(Main *mainvar, wd = mywrite_begin(ww, compare, current); BlendWriter writer = {wd}; - sprintf(buf, - "BLENDER%c%c%.3d", - (sizeof(void *) == 8) ? '-' : '_', - (ENDIAN_ORDER == B_ENDIAN) ? 'V' : 'v', - BLENDER_FILE_VERSION); + BLI_snprintf(buf, + sizeof(buf), + "BLENDER%c%c%.3d", + (sizeof(void *) == 8) ? '-' : '_', + (ENDIAN_ORDER == B_ENDIAN) ? 'V' : 'v', + BLENDER_FILE_VERSION); mywrite(wd, buf, 12); -- cgit v1.2.3