summaryrefslogtreecommitdiff
path: root/gnu/lib
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2004-03-03 16:40:47 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2004-03-03 16:40:47 +0000
commit40a6f2816fac141cc3c48b2f413058c574d830dd (patch)
tree117fb944241094f81bd8f445a8ffe7bab5b585d0 /gnu/lib
parent34bb01291145f1cdc91f2f62972e50990b4781d3 (diff)
Do not segfault writing an empty history list to a file. Resolves PR 3690.
ok tdeval@ markus@
Diffstat (limited to 'gnu/lib')
-rw-r--r--gnu/lib/libreadline/histfile.c4
1 files 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);
}