Skip to content

Commit

Permalink
Fix undefined in core-test and printf-test
Browse files Browse the repository at this point in the history
1. The change in include/fmt/core.h fixes "shift exponent -4 is negative" in
   PrintfTest.InvalidArgIndex

   `do_get` is called with index -1 when `basic_printf_context.arg` is called
   with id 4294967295 when basic_printf_context::get_arg subtracts 1 from
   arg_index 0 in the format string "%0$d".

2. The change in test/core-test.cc fixes "reference binding to null pointer" in
   BufferTest.Ctor

   buffer.operator[] attempts to return a reference to `buffer.ptr_[0]` when
   `ptr_` in `mock_buffer<int> buffer` is null.

2. The change in test/printf-test.cc fixes "signed integer overflow" in
   PrintfTest.Length

   This occurs in `TestLength<long long>("ll")`, since its minimum value minus
   one does not fit in long long.
  • Loading branch information
orivej committed Oct 7, 2019
1 parent b601145 commit ad0397e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -1208,6 +1208,7 @@ template <typename Context> class basic_format_args {

format_arg do_get(int index) const {
format_arg arg;
if (index < 0) return arg;
if (!is_packed()) {
auto num_args = max_size();
if (index < num_args) arg = args_[index];
Expand Down
2 changes: 1 addition & 1 deletion test/core-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ template <typename T> struct mock_buffer : buffer<T> {
TEST(BufferTest, Ctor) {
{
mock_buffer<int> buffer;
EXPECT_EQ(nullptr, &buffer[0]);
EXPECT_EQ(nullptr, buffer.data());
EXPECT_EQ(static_cast<size_t>(0), buffer.size());
EXPECT_EQ(static_cast<size_t>(0), buffer.capacity());
}
Expand Down
4 changes: 3 additions & 1 deletion test/printf-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,9 @@ template <typename T> void TestLength(const char* length_spec) {
TestLength<T>(length_spec, -42);
TestLength<T>(length_spec, min);
TestLength<T>(length_spec, max);
TestLength<T>(length_spec, static_cast<long long>(min) - 1);
long long long_long_min = std::numeric_limits<long long>::min();
if (static_cast<long long>(min) > long_long_min)
TestLength<T>(length_spec, static_cast<long long>(min) - 1);
unsigned long long long_long_max = max_value<long long>();
if (static_cast<unsigned long long>(max) < long_long_max)
TestLength<T>(length_spec, static_cast<long long>(max) + 1);
Expand Down

0 comments on commit ad0397e

Please sign in to comment.