oneTBB icon indicating copy to clipboard operation
oneTBB copied to clipboard

Mac: oneTBB build fails with XCode 14 installed due to sprintf() deprecation error

Open peteschroed opened this issue 3 years ago • 2 comments

I'm building latest oneTBB on an M1 MBP with MacOS Monterey 12.6.1. After upgrading from XCode 13.4.1 to 14.1, oneTBB fails to build due to two sprintf() deprecation errors.

Apple developer forum thread with more info

Build commands:

cmake .. -DCMAKE_OSX_ARCHITECTURES=arm64
cmake –build .

Build errors:

test/common/doctest.h:3698

[ 13%] Building CXX object test/CMakeFiles/test_tick_count.dir/tbb/test_tick_count.cpp.o
In file included from /Users/pete.schroeder/p4/oneTBB_2021_7_v2/test/tbb/test_tick_count.cpp:17:
In file included from /Users/pete.schroeder/p4/oneTBB_2021_7_v2/test/common/test.h:32:
/Users/pete.schroeder/p4/oneTBB_2021_7_v2/test/common/doctest.h:3702:1: error: 'sprintf' is deprecated: This function is provided for compatibility reasons only.  Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead. [-Werror,-Wdeprecated-declarations]

test/tbb/test_parallel_sort.cpp:106

[ 25%] Building CXX object test/CMakeFiles/test_parallel_sort.dir/tbb/test_parallel_sort.cpp.o
/Users/pete.schroeder/p4/oneTBB_2021_7_v2/test/tbb/test_parallel_sort.cpp:106:5: error: 'sprintf' is deprecated: This function is provided for compatibility reasons only.  Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead. [-Werror,-Wdeprecated-declarations]
    sprintf(buffer, "%f", static_cast<float>(key));
    ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/usr/include/stdio.h:188:1: note: 'sprintf' has been explicitly marked deprecated here
__deprecated_msg("This function is provided for compatibility reasons only.  Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead.")
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/usr/include/sys/cdefs.h:215:48: note: expanded from macro '__deprecated_msg'
        #define __deprecated_msg(_msg) __attribute__((__deprecated__(_msg)))
                                                      ^
1 error generated.
make[2]: *** [test/CMakeFiles/test_parallel_sort.dir/tbb/test_parallel_sort.cpp.o] Error 1
make[1]: *** [test/CMakeFiles/test_parallel_sort.dir/all] Error 2
make: *** [all] Error 2

Diff to fix - builds locally, but not yet tested on other platforms:

diff --git a/test/common/doctest.h b/test/common/doctest.h
index 27a5734a..ac5970a5 100644
--- a/test/common/doctest.h
+++ b/test/common/doctest.h
@@ -3695,7 +3695,7 @@ String toString(double long in) { return fpToString(in, 15); }
 #define DOCTEST_TO_STRING_OVERLOAD(type, fmt)                                                      \
     String toString(type in) {                                                                     \
         char buf[64];                                                                              \
-        std::sprintf(buf, fmt, in);                                                                \
+        std::snprintf(buf, sizeof(buf), fmt, in);                                                                \
         return buf;                                                                                \
     }
 
diff --git a/test/tbb/test_parallel_sort.cpp b/test/tbb/test_parallel_sort.cpp
index e4e9451b..e11fe9e8 100644
--- a/test/tbb/test_parallel_sort.cpp
+++ b/test/tbb/test_parallel_sort.cpp
@@ -103,7 +103,7 @@ void set(std::string& string_ref, KeyType key) {
 #if _MSC_VER && __STDC_SECURE_LIB__>=200411
     sprintf_s(buffer, sizeof(buffer), "%f", static_cast<float>(key));
 #else
-    sprintf(buffer, "%f", static_cast<float>(key));
+    snprintf(buffer, sizeof(buffer), "%f", static_cast<float>(key));
 #endif
     string_ref = buffer;
 }

peteschroed avatar Nov 16 '22 06:11 peteschroed

This issue can be fixed with PR: #954

phprus avatar Nov 16 '22 06:11 phprus

Fix for this issue merged into master.

phprus avatar Jan 14 '23 18:01 phprus

@peteschroed is this issue still relevant?

nofuturre avatar Jul 10 '24 12:07 nofuturre

If anyone encounter this issue in the future please open new issue with a link to this one

nofuturre avatar Jul 23 '24 07:07 nofuturre