From cac2908b08f517802e719ddafe39f45c85c96a33 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Fri, 12 Feb 2016 16:00:53 -0800 Subject: Fix regerror(..., nullptr, 0). Found by passing a bad regular expression to the Google benchmark code (https://github.com/google/benchmark). Change-Id: I475db71c25706bbf02091b754acabe8254062f3a --- tests/regex_test.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests/regex_test.cpp') 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); +} -- cgit v1.2.3