Fix regerror(..., nullptr, 0).

Found by passing a bad regular expression to the Google benchmark
code (https://github.com/google/benchmark).

(cherry picked from commit cac2908b08)

Change-Id: I317a7c2ea6535998c0853029023fcefc88cb3750
This commit is contained in:
Elliott Hughes 2016-02-12 16:00:53 -08:00
parent b8e3769067
commit 66c25c360a
3 changed files with 19 additions and 7 deletions

View file

@ -856,7 +856,9 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(libc_upstream_netbsd_src_files) LOCAL_SRC_FILES := $(libc_upstream_netbsd_src_files)
LOCAL_CFLAGS := \ LOCAL_CFLAGS := \
$(libc_common_cflags) \ $(libc_common_cflags) \
-Wno-sign-compare -Wno-uninitialized \ -Wno-sign-compare \
-Wno-uninitialized \
-Wno-unused-parameter \
-DPOSIX_MISTAKE \ -DPOSIX_MISTAKE \
-include netbsd-compat.h \ -include netbsd-compat.h \

View file

@ -20,17 +20,16 @@
#define _BSD_SOURCE #define _BSD_SOURCE
#define _GNU_SOURCE #define _GNU_SOURCE
// NetBSD uses _DIAGASSERT to null-check arguments and the like. // NetBSD uses _DIAGASSERT to null-check arguments and the like,
#include <assert.h> // but it's clear from the number of mistakes in their assertions
#define _DIAGASSERT(e) ((e) ? (void) 0 : __assert2(__FILE__, __LINE__, __func__, #e)) // that they don't actually test or ship with this.
#define _DIAGASSERT(e) /* nothing */
// TODO: update our <sys/cdefs.h> to support this properly.
#define __type_fit(t, a) (0 == 0)
// TODO: we don't yet have thread-safe environment variables. // TODO: we don't yet have thread-safe environment variables.
#define __readlockenv() 0 #define __readlockenv() 0
#define __unlockenv() 0 #define __unlockenv() 0
#include <sys/cdefs.h>
#include <stddef.h> #include <stddef.h>
int reallocarr(void*, size_t, size_t); int reallocarr(void*, size_t, size_t);

View file

@ -46,3 +46,14 @@ TEST(regex, match_offsets) {
ASSERT_EQ(2, matches[0].rm_eo); ASSERT_EQ(2, matches[0].rm_eo);
regfree(&re); 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);
}