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
This commit is contained in:
2022-11-07 15:43:20 +01:00
parent dc609d9f1f
commit 0d945fe20e
31 changed files with 153 additions and 118 deletions

View File

@@ -7,6 +7,7 @@
#include "BLI_math.h"
#include "BLI_sort.h"
#include "BLI_string.h"
#include "DNA_material_types.h"
#include "DNA_mesh_types.h"
@@ -4247,16 +4248,16 @@ char *BPy_BMElem_StringFromHType_ex(const char htype, char ret[32])
/* zero to ensure string is always NULL terminated */
char *ret_ptr = ret;
if (htype & BM_VERT) {
ret_ptr += sprintf(ret_ptr, "/%s", BPy_BMVert_Type.tp_name);
ret_ptr += BLI_sprintf(ret_ptr, "/%s", BPy_BMVert_Type.tp_name);
}
if (htype & BM_EDGE) {
ret_ptr += sprintf(ret_ptr, "/%s", BPy_BMEdge_Type.tp_name);
ret_ptr += BLI_sprintf(ret_ptr, "/%s", BPy_BMEdge_Type.tp_name);
}
if (htype & BM_FACE) {
ret_ptr += sprintf(ret_ptr, "/%s", BPy_BMFace_Type.tp_name);
ret_ptr += BLI_sprintf(ret_ptr, "/%s", BPy_BMFace_Type.tp_name);
}
if (htype & BM_LOOP) {
ret_ptr += sprintf(ret_ptr, "/%s", BPy_BMLoop_Type.tp_name);
ret_ptr += BLI_sprintf(ret_ptr, "/%s", BPy_BMLoop_Type.tp_name);
}
ret[0] = '(';
*ret_ptr++ = ')';

View File

@@ -993,7 +993,7 @@ static PyObject *pyrna_prop_str(BPy_PropertyRNA *self)
}
if (len != -1) {
sprintf(--c, "[%d]", len);
BLI_sprintf(--c, "[%d]", len);
}
/* If a pointer, try to print name of pointer target too. */