diff --git a/src/search.c b/src/search.c
index 2d5e2cc1da086a8d72d6416c223aa18905db1d8e..894d4ab6fc7cc5fb6b80e2593444ec76baa4ea81 100644
--- a/src/search.c
+++ b/src/search.c
@@ -99,8 +99,7 @@ void search_init(bool replacing, bool keep_the_answer)
 	static char *sofar = NULL;
 		/* What the user has typed so far, before toggling something. */
 
-	if (keep_the_answer)
-		sofar = mallocstrcpy(sofar, answer);
+	sofar = mallocstrcpy(sofar, keep_the_answer ? answer : "");
 
 	/* If something was searched for earlier, include it in the prompt. */
 	if (*last_search != '\0') {