From 19158a21183d28f4c2abfa5ddbcd30a86bd17c47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Thu, 11 Sep 2014 10:32:31 +0200 Subject: Avoid segfault if no previous search has been performed --- text.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/text.c b/text.c index 39d47cc..92a0644 100644 --- a/text.c +++ b/text.c @@ -1048,7 +1048,11 @@ const char *text_filename(Text *txt) { } Regex *text_regex_new(void) { - return calloc(1, sizeof(Regex)); + Regex *r = calloc(1, sizeof(Regex)); + if (!r) + return NULL; + regcomp(&r->regex, "\0\0", 0); /* this should not match anything */ + return r; } int text_regex_compile(Regex *regex, const char *string, int cflags) { -- cgit v1.2.3