Fix regerror(..., nullptr, 0).
Found by passing a bad regular expression to the Google benchmark
code (https://github.com/google/benchmark).
Change-Id: I475db71c25706bbf02091b754acabe8254062f3a
diff --git a/tests/regex_test.cpp b/tests/regex_test.cpp
index 4a4409e..0e7f8dd 100644
--- a/tests/regex_test.cpp
+++ b/tests/regex_test.cpp
@@ -46,3 +46,14 @@
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);
+}