diff options
| author | Eugene Triguba <eugenetriguba@gmail.com> | 2025-07-12 11:06:35 -0400 |
|---|---|---|
| committer | Eugene Triguba <eugenetriguba@gmail.com> | 2025-07-12 11:06:35 -0400 |
| commit | 7816b122ef8806e212e716d32a88a4eaab5476a5 (patch) | |
| tree | 043e99a2f80fb05749250f01bb1e5fbc77ebc54a /src/main.c | |
| parent | Refactor main to delegate to a `justify` function (diff) | |
| download | cli-7816b122ef8806e212e716d32a88a4eaab5476a5.zip | |
Add handling for zero or negative values for -w
Diffstat (limited to 'src/main.c')
| -rw-r--r-- | src/main.c | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -17,16 +17,18 @@ void print_usage(const char *prog) { int main(int argc, char *argv[]) { int opt; + int width; size_t linebuffer_capacity = DEFAULT_LINEBUFFER_CAPACITY; while ((opt = getopt(argc, argv, "w:h")) != -1) { switch (opt) { case 'w': - linebuffer_capacity = (size_t)atoi(optarg); - if (linebuffer_capacity == 0) { + width = atoi(optarg); + if (width <= 0) { print_usage(argv[0]); return EXIT_FAILURE; } + linebuffer_capacity= (size_t) width; break; case 'h': default: |