aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/linebuffer.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/linebuffer.c b/src/linebuffer.c
index 7d00dc6..14592ef 100644
--- a/src/linebuffer.c
+++ b/src/linebuffer.c
@@ -10,6 +10,7 @@ LineBuffer *linebuffer_create(size_t buffer_capacity) {
}
lb->_buffer = malloc(sizeof(buffer_capacity) + 1);
if (lb->_buffer == NULL) {
+ free(lb);
return NULL;
}
lb->_num_words = 0;
@@ -64,14 +65,14 @@ int linebuffer_write_justified(LineBuffer *lb, FILE *fp) {
}
} else {
spaces_to_insert = extra_spaces / (words_remaining - 1);
+ extra_spaces -= spaces_to_insert;
for (size_t j = 1; j <= spaces_to_insert + 1; j++) {
return_code = fputc(' ', fp);
if (return_code == EOF) {
return EOF;
}
- extra_spaces -= spaces_to_insert;
- words_remaining--;
}
+ words_remaining--;
}
}
return_code = fputc('\n', fp);