| 15 | |
| 16 | template <typename T> |
| 17 | int format_float(char* buf, std::size_t size, const char* format, int precision, |
| 18 | T value) { |
| 19 | #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION |
| 20 | if (precision > 100000) |
| 21 | throw std::runtime_error( |
| 22 | "fuzz mode - avoid large allocation inside snprintf"); |
| 23 | #endif |
| 24 | // Suppress the warning about nonliteral format string. |
| 25 | auto snprintf_ptr = FMT_SNPRINTF; |
| 26 | return precision < 0 ? snprintf_ptr(buf, size, format, value) |
| 27 | : snprintf_ptr(buf, size, format, precision, value); |
| 28 | } |
| 29 | struct sprintf_specs { |
| 30 | int precision; |
| 31 | char type; |