buf[0] = 0;
chunks++;
sprintf(buf+1, "%5d %5d %5d\n", chunks, a, acnt);
- memcpy(r1.body+r1.len, buf, 19);
- r1.len += 19;
+ memcpy(r1.body+r1.len, buf, 20);
+ r1.len += 20;
}
if (state==2 || state == 3) {
char buf[20];
buf[0] = 0;
sprintf(buf+1, "%5d %5d %5d\n", chunks, c, bcnt);
- memcpy(r2.body+r2.len, buf, 19);
- r2.len += 19;
+ memcpy(r2.body+r2.len, buf, 20);
+ r2.len += 20;
}
break;
case 1:
for (i=0; i<cnt ; i++)
len += list[i].len;
- c = realloc(list[0].body, len);
+ c = realloc(list[0].body, len+1);
if (c == NULL)
die();
c += list[i].len;
list[i].len = 0;
}
+ c[0] = 0;
}
static struct stream load_regular(int fd)
fstat(fd, &stb);
s.len = stb.st_size;
- s.body = malloc(s.len);
+ s.body = malloc(s.len+1);
if (s.body) {
if (read(fd, s.body, s.len) != s.len) {
free(s.body);
s.body = NULL;
}
} else die();
+ s.body[s.len] = 0;
return s;
}
while (start < end) {
char *cp = start;
- if (*cp == '\0' && cp+16 < end && cp[18] == '\n') {
+ if (*cp == '\0' && cp+19 < end && cp[18] == '\n') {
/* special word */
- cp += 19;
+ cp += 20;
} else switch(type) {
case ByLine:
while (cp < end && *cp != '\n')
static inline int ends_line(struct elmnt e)
{
+ if (e.len == 20 && e.start[0] == 0)
+ return 1;
return e.len && e.start[e.len-1] == '\n';
}