src/3rdparty: modp: Disable deprecation warning for sprintf

This commit is contained in:
Tim Wojtulewicz 2024-01-04 12:34:28 -07:00
parent dfd32b3b37
commit 6a060588c2

View file

@ -186,7 +186,14 @@ size_t modp_dtoa(double value, char* str, int prec)
which can be 100s of characters overflowing your buffers == bad which can be 100s of characters overflowing your buffers == bad
*/ */
if (value >= thres_max) { if (value >= thres_max) {
#pragma GCC diagnostic push
// Ignore the diagnostic warning about sprintf being deprecated here. We
// have to assume that the size of the string is long enough here
// because we'd have to change the function definition to support
// passing a length.
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
int n = sprintf(str, "%.*e", DBL_DECIMAL_DIG - 1, neg ? -value : value); int n = sprintf(str, "%.*e", DBL_DECIMAL_DIG - 1, neg ? -value : value);
#pragma GCC diagnostic pop
n -= sn_strip_trailing_zeros(str); n -= sn_strip_trailing_zeros(str);
return n; return n;
} }
@ -287,7 +294,14 @@ size_t modp_dtoa2(double value, char* str, int prec)
which can be 100s of characters overflowing your buffers == bad which can be 100s of characters overflowing your buffers == bad
*/ */
if (value >= thres_max) { if (value >= thres_max) {
#pragma GCC diagnostic push
// Ignore the diagnostic warning about sprintf being deprecated here. We
// have to assume that the size of the string is long enough here
// because we'd have to change the function definition to support
// passing a length.
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
int n = sprintf(str, "%.*e", DBL_DECIMAL_DIG - 1, neg ? -value : value); int n = sprintf(str, "%.*e", DBL_DECIMAL_DIG - 1, neg ? -value : value);
#pragma GCC diagnostic pop
n -= sn_strip_trailing_zeros(str); n -= sn_strip_trailing_zeros(str);
return n; return n;
} }
@ -306,7 +320,14 @@ size_t modp_dtoa2(double value, char* str, int prec)
double smallest = _pow10r[prec]; double smallest = _pow10r[prec];
if (value != 0.0 && value < smallest) { if (value != 0.0 && value < smallest) {
#pragma GCC diagnostic push
// Ignore the diagnostic warning about sprintf being deprecated here. We
// have to assume that the size of the string is long enough here
// because we'd have to change the function definition to support
// passing a length.
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
int n = sprintf(str, "%.*e", DBL_DECIMAL_DIG - 1, neg ? -value : value); int n = sprintf(str, "%.*e", DBL_DECIMAL_DIG - 1, neg ? -value : value);
#pragma GCC diagnostic pop
n -= sn_strip_trailing_zeros(str); n -= sn_strip_trailing_zeros(str);
return n; return n;
} }