From c72c185f579b6dc4bf36047a5a3a182d0f52a910 Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 26 Apr 2007 08:44:41 +0000 Subject: [PATCH] Fix memory overwrite when increasing display width in mid-editing. (That operation increases the amount of data displayed on screen, but failed to trigger a realloc of the buffer used to hold that data during display.) git-svn-id: svn://svn.tartarus.org/sgt/tweak@7478 cda61777-01e9-0310-a592-d414129be87e --- main.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/main.c b/main.c index 7394454..ae9e491 100644 --- a/main.c +++ b/main.c @@ -469,7 +469,7 @@ int backup_file (void) { } static unsigned char *scrbuf = NULL; -static int scrbuflines = 0; +static int scrbufsize = 0; /* * Draw the screen, for normal usage. @@ -484,16 +484,15 @@ void draw_scr (void) { char *linebuf; scrlines = display_rows - 2; - if (scrlines > scrbuflines) { - scrbuf = (scrbuf ? - realloc(scrbuf, scrlines*width) : - malloc(scrlines*width)); + scrsize = scrlines * width; + if (scrsize > scrbufsize) { + scrbuf = (scrbuf ? realloc(scrbuf, scrsize) : malloc(scrsize)); if (!scrbuf) { done(); fprintf(stderr, "%s: out of memory!\n", pname); exit (2); } - scrbuflines = scrlines; + scrbufsize = scrsize; } linebuf = malloc(width*4+20); @@ -509,7 +508,8 @@ void draw_scr (void) { scroff = width - offset; else scroff = 0; - scrsize = scrlines * width - scroff; + + scrsize -= scroff; if (scrsize > file_size - top_pos) scrsize = file_size - top_pos; -- 2.11.0