From 40a6f2816fac141cc3c48b2f413058c574d830dd Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Wed, 3 Mar 2004 16:40:47 +0000 Subject: Do not segfault writing an empty history list to a file. Resolves PR 3690. ok tdeval@ markus@ --- gnu/lib/libreadline/histfile.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gnu/lib/libreadline/histfile.c b/gnu/lib/libreadline/histfile.c index ad200d3051b..180f20ea3e2 100644 --- a/gnu/lib/libreadline/histfile.c +++ b/gnu/lib/libreadline/histfile.c @@ -339,7 +339,7 @@ history_do_write (filename, nelements, overwrite) the_history = history_list (); /* Calculate the total number of bytes to write. */ - for (buffer_size = 0, i = history_length - nelements; i < history_length; i++) + for (buffer_size = 1, i = history_length - nelements; i < history_length; i++) buffer_size += 1 + strlen (the_history[i]->line); /* Allocate the buffer, and fill it. */ @@ -352,7 +352,7 @@ history_do_write (filename, nelements, overwrite) strlcat (buffer, "\n", buffer_size); } - write (file, buffer, buffer_size); + write (file, buffer, buffer_size - 1); free (buffer); } -- cgit v1.2.3