X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/tweak/blobdiff_plain/c856a9abcbb017f9ae7831d26c66e7980e34dd50..c72c185f579b6dc4bf36047a5a3a182d0f52a910:/main.c?ds=sidebyside 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;