beltoforion / muparser

muparser is a fast math parser library for C/C++ with (optional) OpenMP support.

Home Page:http://beltoforion.de/en/muparser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`sprintf` deprecation warning on macOS

philipturner opened this issue · comments

I came across a compiler warning regarding sprintf. On macOS 13, the function was deprecated in favor of vsprintf. This deprecation has affected multiple code bases, including VkFFT and GROMACS. Hopefully you can fix it early, as additional clients may face the compiler warning.

/Users/philipturner/Documents/GROMACS/gromacs/src/external/muparser/src/muParserDLL.cpp:201:3: warning: '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. [-Wdeprecated-declarations]
                sprintf(s_tmpOutBuf, "%s", p->GetVersion().c_str());
                ^
/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)))
                                                      ^
/Users/philipturner/Documents/GROMACS/gromacs/src/external/muparser/src/muParserDLL.cpp:598:3: warning: '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. [-Wdeprecated-declarations]
                sprintf(s_tmpOutBuf, "%s", p->GetExpr().c_str());
                ^
/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)))
                                                      ^
/Users/philipturner/Documents/GROMACS/gromacs/src/external/muparser/src/muParserDLL.cpp:935:2: warning: '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. [-Wdeprecated-declarations]
        sprintf(s_tmpOutBuf, "%s", pMsg);
        ^
/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)))
                                                      ^
/Users/philipturner/Documents/GROMACS/gromacs/src/external/muparser/src/muParserDLL.cpp:953:2: warning: '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. [-Wdeprecated-declarations]
        sprintf(s_tmpOutBuf, "%s", pToken);
        ^
/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)))

I replaced sprintf with snprintf which should solve the issue. Please test it.

No errors anymore.

Detailed test output
(base) philipturner@M1-Max-MacBook-Pro GROMACS % git clone https://github.com/beltoforion/muparser
Cloning into 'muparser'...
remote: Enumerating objects: 2009, done.
remote: Counting objects: 100% (391/391), done.
remote: Compressing objects: 100% (169/169), done.
remote: Total 2009 (delta 257), reused 324 (delta 219), pack-reused 1618
Receiving objects: 100% (2009/2009), 2.80 MiB | 20.35 MiB/s, done.
Resolving deltas: 100% (1288/1288), done.
(base) philipturner@M1-Max-MacBook-Pro GROMACS % cd muparser
(base) philipturner@M1-Max-MacBook-Pro muparser % git checkout bec39ca3505b313c93ee4e392baab928c3cf83dd
Note: switching to 'bec39ca3505b313c93ee4e392baab928c3cf83dd'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at bec39ca Merge branch 'master' of https://github.com/beltoforion/muparser
(base) philipturner@M1-Max-MacBook-Pro muparser % mkdir build
(base) philipturner@M1-Max-MacBook-Pro muparser % cd build
(base) philipturner@M1-Max-MacBook-Pro build % cmake ..
-- The C compiler identification is AppleClang 14.0.0.14000029
-- The CXX compiler identification is AppleClang 14.0.0.14000029
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenMP_C: -Xclang -fopenmp (found version "5.0") 
-- Found OpenMP_CXX: -Xclang -fopenmp (found version "5.0") 
-- Found OpenMP: TRUE (found version "5.0")  
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/philipturner/Documents/GROMACS/muparser/build
(base) philipturner@M1-Max-MacBook-Pro build % make
[  6%] Building CXX object CMakeFiles/muparser.dir/src/muParser.cpp.o
[ 12%] Building CXX object CMakeFiles/muparser.dir/src/muParserBase.cpp.o
[ 18%] Building CXX object CMakeFiles/muparser.dir/src/muParserBytecode.cpp.o
[ 25%] Building CXX object CMakeFiles/muparser.dir/src/muParserCallback.cpp.o
[ 31%] Building CXX object CMakeFiles/muparser.dir/src/muParserDLL.cpp.o
/Users/philipturner/Documents/GROMACS/muparser/src/muParserDLL.cpp:211:3: warning: '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. [-Wdeprecated-declarations]
                sprintf(s_tmpOutBuf, "%s", p->GetVersion().c_str());
                ^
/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)))
                                                      ^
/Users/philipturner/Documents/GROMACS/muparser/src/muParserDLL.cpp:879:3: warning: '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. [-Wdeprecated-declarations]
                sprintf(s_tmpOutBuf, "%s", p->GetExpr().c_str());
                ^
/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)))
                                                      ^
/Users/philipturner/Documents/GROMACS/muparser/src/muParserDLL.cpp:1217:2: warning: '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. [-Wdeprecated-declarations]
        sprintf(s_tmpOutBuf, "%s", pMsg);
        ^
/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)))
                                                      ^
/Users/philipturner/Documents/GROMACS/muparser/src/muParserDLL.cpp:1236:2: warning: '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. [-Wdeprecated-declarations]
        sprintf(s_tmpOutBuf, "%s", pToken);
        ^
/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)))
                                                      ^
4 warnings generated.
[ 37%] Building CXX object CMakeFiles/muparser.dir/src/muParserError.cpp.o
[ 43%] Building CXX object CMakeFiles/muparser.dir/src/muParserInt.cpp.o
[ 50%] Building CXX object CMakeFiles/muparser.dir/src/muParserTest.cpp.o
[ 56%] Building CXX object CMakeFiles/muparser.dir/src/muParserTokenReader.cpp.o
[ 62%] Linking CXX shared library libmuparser.dylib
[ 62%] Built target muparser
[ 68%] Building CXX object CMakeFiles/example1.dir/samples/example1/example1.cpp.o
[ 75%] Linking CXX executable example1
[ 75%] Built target example1
[ 81%] Building C object CMakeFiles/example2.dir/samples/example2/example2.c.o
[ 87%] Linking C executable example2
[ 87%] Built target example2
[ 93%] Building CXX object CMakeFiles/t_ParserTest.dir/test/t_ParserTest.cpp.o
[100%] Linking CXX executable t_ParserTest
[100%] Built target t_ParserTest
(base) philipturner@M1-Max-MacBook-Pro build % cd ../
(base) philipturner@M1-Max-MacBook-Pro muparser % rm -rf build
(base) philipturner@M1-Max-MacBook-Pro muparser % git checkout main
error: pathspec 'main' did not match any file(s) known to git
(base) philipturner@M1-Max-MacBook-Pro muparser % git checkout master
Previous HEAD position was bec39ca Merge branch 'master' of https://github.com/beltoforion/muparser
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
(base) philipturner@M1-Max-MacBook-Pro muparser % git log
commit 2ec633f82006a1d26ef7278aa41a4d4cc0c2cccd (HEAD -> master, origin/master, origin/HEAD)
Author: Ingo Berg <github_contact@beltoforion.de>
Date:   Sun Nov 6 17:39:13 2022 +0100

    fix for #117 (sprintf deprecated)

commit bec39ca3505b313c93ee4e392baab928c3cf83dd
Merge: 6c5d4de 949dc82
Author: Ingo Berg <github_contact@beltoforion.de>
Date:   Thu Oct 20 00:29:08 2022 +0200

    Merge branch 'master' of https://github.com/beltoforion/muparser

commit 6c5d4dec46bbc612e32d617ef96f588a811c3985
Author: Ingo Berg <github_contact@beltoforion.de>
Date:   Thu Oct 20 00:28:00 2022 +0200

    fed my OCD

commit 949dc82edaab49627c55df10439fcc8d93123055
Author: Ingo Berg <2202567+beltoforion@users.noreply.github.com>
Date:   Wed Oct 19 23:51:53 2022 +0200

    Update README.rst

commit c082859ec7b9a2719b1e3ab849036db95bb46ac9
Merge: 446dcd3 0e79fc2
Author: Ingo Berg <github_contact@beltoforion.de>
Date:   Wed Oct 19 23:49:39 2022 +0200

    Merge branch 'master' of https://github.com/beltoforion/muparser

commit 446dcd3765b0f842c73ed156ecc06c66a11593ab
Author: Ingo Berg <github_contact@beltoforion.de>
Date:   Wed Oct 19 23:49:37 2022 +0200

    Update CHANGELOG

commit 0e79fc2bcdeb4ee28ab370041f70e2bc58be635a
Author: Ingo Berg <2202567+beltoforion@users.noreply.github.com>
Date:   Wed Oct 19 23:49:03 2022 +0200

    Update README.rst
(base) philipturner@M1-Max-MacBook-Pro muparser % mkdir build
(base) philipturner@M1-Max-MacBook-Pro muparser % cd build
(base) philipturner@M1-Max-MacBook-Pro build % cmake ..
-- The C compiler identification is AppleClang 14.0.0.14000029
-- The CXX compiler identification is AppleClang 14.0.0.14000029
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenMP_C: -Xclang -fopenmp (found version "5.0") 
-- Found OpenMP_CXX: -Xclang -fopenmp (found version "5.0") 
-- Found OpenMP: TRUE (found version "5.0")  
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/philipturner/Documents/GROMACS/muparser/build
(base) philipturner@M1-Max-MacBook-Pro build % make
[  6%] Building CXX object CMakeFiles/muparser.dir/src/muParser.cpp.o
[ 12%] Building CXX object CMakeFiles/muparser.dir/src/muParserBase.cpp.o
[ 18%] Building CXX object CMakeFiles/muparser.dir/src/muParserBytecode.cpp.o
[ 25%] Building CXX object CMakeFiles/muparser.dir/src/muParserCallback.cpp.o
[ 31%] Building CXX object CMakeFiles/muparser.dir/src/muParserDLL.cpp.o
[ 37%] Building CXX object CMakeFiles/muparser.dir/src/muParserError.cpp.o
[ 43%] Building CXX object CMakeFiles/muparser.dir/src/muParserInt.cpp.o
[ 50%] Building CXX object CMakeFiles/muparser.dir/src/muParserTest.cpp.o
[ 56%] Building CXX object CMakeFiles/muparser.dir/src/muParserTokenReader.cpp.o
[ 62%] Linking CXX shared library libmuparser.dylib
[ 62%] Built target muparser
[ 68%] Building CXX object CMakeFiles/example1.dir/samples/example1/example1.cpp.o
[ 75%] Linking CXX executable example1
[ 75%] Built target example1
[ 81%] Building C object CMakeFiles/example2.dir/samples/example2/example2.c.o
[ 87%] Linking C executable example2
[ 87%] Built target example2
[ 93%] Building CXX object CMakeFiles/t_ParserTest.dir/test/t_ParserTest.cpp.o
[100%] Linking CXX executable t_ParserTest
[100%] Built target t_ParserTest
(base) philipturner@M1-Max-MacBook-Pro build % make check
make: *** No rule to make target `check'.  Stop.

If I may ask, when do you anticipate creating the next muParser release? That's the time when GROMACS can upgrade their dependency and properly resolve the sprintf error. Perhaps after that happens, we can close this thread.

Soon. As in a couple of days soon or at least in november.

issue closed; 2.3.4 is released

I wish my gcc compiler had this warning... chasing down a bug where someone used sprintf on a fixed sized buffer of 128 bytes... of course it was too short eventually...