diff options
author | Elliott Hughes <enh@google.com> | 2016-02-12 16:00:53 -0800 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2016-02-12 16:00:53 -0800 |
commit | cac2908b08f517802e719ddafe39f45c85c96a33 (patch) | |
tree | 7bea048743bbf54843f6c84493353508c918e4b4 /tests/regex_test.cpp | |
parent | 9750a77b31f2fc6d548a02b3a9750c2794648fea (diff) |
Fix regerror(..., nullptr, 0).
Found by passing a bad regular expression to the Google benchmark
code (https://github.com/google/benchmark).
Change-Id: I475db71c25706bbf02091b754acabe8254062f3a
Diffstat (limited to 'tests/regex_test.cpp')
-rw-r--r-- | tests/regex_test.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/regex_test.cpp b/tests/regex_test.cpp index 4a4409ef3..0e7f8dd7f 100644 --- a/tests/regex_test.cpp +++ b/tests/regex_test.cpp @@ -46,3 +46,14 @@ TEST(regex, match_offsets) { ASSERT_EQ(2, matches[0].rm_eo); regfree(&re); } + +TEST(regex, regerror_NULL_0) { + regex_t re; + int error = regcomp(&re, "*", REG_EXTENDED); + ASSERT_NE(0, error); + + // Passing a null pointer and a size of 0 is a legitimate way to ask + // how large a buffer we would need for the error message. + int error_length = regerror(error, &re, nullptr, 0); + ASSERT_GT(error_length, 0); +} |