From 4d65be44d2cfab9c4057467c56407584f30d2a12 Mon Sep 17 00:00:00 2001 From: Asra Ali Date: Wed, 29 Apr 2020 10:32:03 -0400 Subject: [PATCH] address comment Signed-off-by: Asra Ali --- CMakeLists.txt | 1 + include/fmt/format-inl.h | 2 +- include/fmt/format.h | 4 ++-- src/format.cc | 2 +- test/fuzzing/README.md | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b2e2ad7b..29b9dd58 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -308,6 +308,7 @@ endif () # Control fuzzing independent of the unit tests. if (FMT_FUZZ) add_subdirectory(test/fuzzing) + target_compile_definitions(fmt PUBLIC FMT_FUZZ) endif () set(gitignore ${PROJECT_SOURCE_DIR}/.gitignore) diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index b7ce3bdd..9cb36273 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -1151,7 +1151,7 @@ int snprintf_float(T value, int precision, float_specs specs, for (;;) { auto begin = buf.data() + offset; auto capacity = buf.capacity() - offset; -#if FMT_FUZZ +#ifdef FMT_FUZZ if (precision > 100000) throw std::runtime_error( "fuzz mode - avoid large allocation inside snprintf"); diff --git a/include/fmt/format.h b/include/fmt/format.h index 45604422..20433d1b 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -699,7 +699,7 @@ class basic_memory_buffer : public internal::buffer { template void basic_memory_buffer::grow(std::size_t size) { -#if FMT_FUZZ +#ifdef FMT_FUZZ if (size > 1000) throw std::runtime_error("fuzz mode - won't grow that much"); #endif std::size_t old_capacity = this->capacity(); @@ -1136,7 +1136,7 @@ template class float_writer { *it++ = static_cast('0'); return it; } -#if FMT_FUZZ +#ifdef FMT_FUZZ if (num_zeros > 1000) throw std::runtime_error("fuzz mode - avoiding excessive cpu use"); #endif diff --git a/src/format.cc b/src/format.cc index ec633e55..e6849b93 100644 --- a/src/format.cc +++ b/src/format.cc @@ -13,7 +13,7 @@ namespace internal { template int format_float(char* buf, std::size_t size, const char* format, int precision, T value) { -#if FMT_FUZZ +#ifdef FMT_FUZZ if (precision > 100000) throw std::runtime_error( "fuzz mode - avoid large allocation inside snprintf"); diff --git a/test/fuzzing/README.md b/test/fuzzing/README.md index 54958490..8f7a4536 100644 --- a/test/fuzzing/README.md +++ b/test/fuzzing/README.md @@ -7,7 +7,7 @@ in fmt. It is a part of the continous fuzzing at The source code is modified to make the fuzzing possible without locking up on resource exhaustion: ```cpp -#if FMT_FUZZ +#ifdef FMT_FUZZ if(spec.precision>100000) { throw std::runtime_error("fuzz mode - avoiding large precision"); }