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/BLI_string.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'source/blender/blenlib/BLI_string.h') diff --git a/source/blender/blenlib/BLI_string.h b/source/blender/blenlib/BLI_string.h index 17abcf52ecc..fb02ea5fb17 100644 --- a/source/blender/blenlib/BLI_string.h +++ b/source/blender/blenlib/BLI_string.h @@ -205,6 +205,13 @@ size_t BLI_vsnprintf_rlen(char *__restrict buffer, char *BLI_sprintfN(const char *__restrict format, ...) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_PRINTF_FORMAT(1, 2); +/** + * A wrapper around ::sprintf() which does not generate security warnings. + * + * \note Use BLI_snprintf for cases when the string size is known. + */ +int BLI_sprintf(char *__restrict str, const char *__restrict format, ...); + /** * This roughly matches C and Python's string escaping with double quotes - `"`. * -- cgit v1.2.3 From 3fa6aacb91f4a0d04c1ef3c67449df67696cea6b Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 9 Nov 2022 12:28:34 +1100 Subject: Cleanup: add function attributes to BLI_sprintf Quiet warning, suggesting to use attributes with GCC. --- source/blender/blenlib/BLI_string.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'source/blender/blenlib/BLI_string.h') diff --git a/source/blender/blenlib/BLI_string.h b/source/blender/blenlib/BLI_string.h index fb02ea5fb17..ed15e0871b9 100644 --- a/source/blender/blenlib/BLI_string.h +++ b/source/blender/blenlib/BLI_string.h @@ -206,11 +206,12 @@ char *BLI_sprintfN(const char *__restrict format, ...) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_PRINTF_FORMAT(1, 2); /** - * A wrapper around ::sprintf() which does not generate security warnings. + * A wrapper around `::sprintf()` which does not generate security warnings. * - * \note Use BLI_snprintf for cases when the string size is known. + * \note Use #BLI_snprintf for cases when the string size is known. */ -int BLI_sprintf(char *__restrict str, const char *__restrict format, ...); +int BLI_sprintf(char *__restrict str, const char *__restrict format, ...) ATTR_NONNULL(1, 2) + ATTR_PRINTF_FORMAT(2, 3); /** * This roughly matches C and Python's string escaping with double quotes - `"`. -- cgit v1.2.3