From f1165785af5af6b0eb29b739b232858c8b1f82ba Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Sun, 28 Feb 2016 12:06:20 +0100 Subject: [PATCH 4/5] Allocate enough space for printing out the line and column numbers. (This is revision 5639 from SVN. This avoids a segfault with huge files.) Signed-off-by: Benno Schulenberg --- src/files.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/src/files.c b/src/files.c index 9df472f..0282cb3 100644 --- a/src/files.c +++ b/src/files.c @@ -3174,7 +3174,9 @@ void save_poshistory(void) chmod(poshist, S_IRUSR | S_IWUSR); for (posptr = position_history; posptr != NULL; posptr = posptr->next) { - statusstr = charalloc(strlen(posptr->filename) + 2 * sizeof(ssize_t) + 4); + /* Assume 20 decimal positions each for line and column number, + * plus two spaces, plus the line feed, plus the null byte. */ + statusstr = charalloc(strlen(posptr->filename) + 44); sprintf(statusstr, "%s %ld %ld\n", posptr->filename, (long)posptr->lineno, (long)posptr->xno); if (fwrite(statusstr, sizeof(char), strlen(statusstr), hist) < strlen(statusstr)) -- 1.7.0.4