aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEugene Triguba <eugenetriguba@gmail.com>2024-07-04 11:31:09 -0400
committerEugene Triguba <eugenetriguba@gmail.com>2024-07-04 11:31:09 -0400
commitd17ff4773bf258a5e56f25734064c53c6e7d07b4 (patch)
tree93807bd1e1c7a9bc079f065f7711f56bb5320c52 /src
parentTweak clang format and tests (diff)
downloadcli-d17ff4773bf258a5e56f25734064c53c6e7d07b4.zip
Tweak linebuffer
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);