ed

simple ed
git clone git://git.2f30.org/ed.git
Log | Files | Refs

commit e2cd1586e3ca95c3d634d3350e7e00922b1b426e
parent a109a4ad3ad34d3318ebca644595fbd261c4980b
Author: FRIGN <dev@frign.de>
Date:   Tue Dec  1 17:01:57 +0100

Use size_t for memory-offsets

instead of doing a nasty overflow check. size_t guarantees to be able
to hold the largest possible memory-object-size, so we're good.

Diffstat:
ed.c | 22++++++++--------------
1 file changed, 8 insertions(+), 14 deletions(-)
diff --git a/ed.c b/ed.c @@ -34,11 +34,11 @@ int nlines, line1, line2; int curln, lastln; jmp_buf savesp; char *lasterr; -unsigned idxsize, lastidx; +size_t idxsize, lastidx; struct hline *zero; char *text; char *savfname; -unsigned sizetxt, memtxt; +size_t sizetxt, memtxt; int scratch; int pflag, modflag, uflag; size_t csize; @@ -72,14 +72,11 @@ static void addchar(char c) { char *p; - unsigned n; if (sizetxt >= memtxt) { - if ((n = memtxt+LINESIZE) < memtxt || - (p = realloc(text, n)) == NULL) { + if (!(p = realloc(text, memtxt + LINESIZE))) error("out of memory"); - } - memtxt = n; + memtxt += LINESIZE; text = p; } text[sizetxt++] = c; @@ -88,20 +85,17 @@ addchar(char c) static int makeline(char *s, int *off) { - char c, *begin = s; struct hline *lp; - unsigned n; size_t len; + char c, *begin = s; if (lastidx >= idxsize) { - if ((n = idxsize+NUMLINES) < idxsize || - (lp = realloc(zero, n * sizeof(*lp))) == NULL) { + if (!(lp = realloc(zero, (idxsize + NUMLINES) * sizeof(*lp)))) error("out of memory"); - } + idxsize += NUMLINES; zero = lp; - idxsize = idxsize + NUMLINES; } - lp = &zero[lastidx]; + lp = zero + lastidx; while ((c = *s) && *s != '\n') ++s;