aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShav Kinderlehrer <[email protected]>2023-04-17 18:37:39 -0400
committerShav Kinderlehrer <[email protected]>2023-04-17 18:37:39 -0400
commitab10a9c2176faa2f339d4e39ace58b811a6c05be (patch)
tree79e702b6cf339bc98098cb20383b9b212c4fd827
parent15986b04ff7c9a3932f9c752a727ca8af8b80d88 (diff)
downloadlat-ab10a9c2176faa2f339d4e39ace58b811a6c05be.tar.gz
lat-ab10a9c2176faa2f339d4e39ace58b811a6c05be.zip
Process last linev0.7.3
-rw-r--r--src/lib/process.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/lib/process.c b/src/lib/process.c
index 61261d9..674fa59 100644
--- a/src/lib/process.c
+++ b/src/lib/process.c
@@ -28,7 +28,7 @@ void loadlines(struct filedata *f) {
for (size_t i = 0; i < f->buflen; i++) {
char c = f->buf[i];
if (c == '\n') {
- if (offset < linelen) {
+ if (offset < linelen) { // shrink
char *new_line = realloc(line, offset);
if (new_line == NULL)
die("realloc");
@@ -43,7 +43,6 @@ void loadlines(struct filedata *f) {
line = malloc(linelen);
if (line == NULL)
die("malloc");
-
} else {
if (offset == linelen) {
linelen *= 2;
@@ -58,6 +57,19 @@ void loadlines(struct filedata *f) {
line[offset++] = c;
}
}
+
+ // capture last line
+ if (offset < linelen) { // shrink
+ char *new_line = realloc(line, offset);
+ if (new_line == NULL)
+ die("realloc");
+ line = new_line;
+ }
+
+ appendline(f, line, offset);
+ f->lc++;
+
+ free(line);
}
char *linepad(int lc, int total) {