~mdw
/
sgt
/
tweak
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix memory overwrite when increasing display width in mid-editing.
[sgt/tweak]
/
main.c
diff --git
a/main.c
b/main.c
index
7394454
..
ae9e491
100644
(file)
--- a/
main.c
+++ b/
main.c
@@
-469,7
+469,7
@@
int backup_file (void) {
}
static unsigned char *scrbuf = NULL;
}
static unsigned char *scrbuf = NULL;
-static int scrbuf
lines
= 0;
+static int scrbuf
size
= 0;
/*
* Draw the screen, for normal usage.
/*
* Draw the screen, for normal usage.
@@
-484,16
+484,15
@@
void draw_scr (void) {
char *linebuf;
scrlines = display_rows - 2;
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);
}
if (!scrbuf) {
done();
fprintf(stderr, "%s: out of memory!\n", pname);
exit (2);
}
- scrbuf
lines = scrlines
;
+ scrbuf
size = scrsize
;
}
linebuf = malloc(width*4+20);
}
linebuf = malloc(width*4+20);
@@
-509,7
+508,8
@@
void draw_scr (void) {
scroff = width - offset;
else
scroff = 0;
scroff = width - offset;
else
scroff = 0;
- scrsize = scrlines * width - scroff;
+
+ scrsize -= scroff;
if (scrsize > file_size - top_pos)
scrsize = file_size - top_pos;
if (scrsize > file_size - top_pos)
scrsize = file_size - top_pos;