Skip to content

fix: return correct exit code on unit conversion - #44

Merged
jarun merged 1 commit into
jarun:masterfrom
pro-laxmi:fix/exit-code-unit-conversion
Nov 25, 2026
Merged

jarun merged 1 commit into
jarun:masterfrom
pro-laxmi:fix/exit-code-unit-conversion

Conversation

@pro-laxmi

Copy link
Copy Markdown
Contributor

Summary of Changes

When running bcal <val> <unit> (e.g. bcal 1024 B), unit conversion succeeded and printed results to stdout properly, but the process exited with status 255 (-1) instead of 0.

Root Cause

In src/bcal.c:

if ((argc - optind == 2) && (convertunit(argv[optind], argv[optind + 1], sectorsz) == -1))
    return -1;

When convertunit() returned 0 (success), the if condition was false, causing execution to drop through and return -1 at the end of main().

Fix

Return the status of convertunit() directly when two arguments are provided:

if (argc - optind == 2)
    return convertunit(argv[optind], argv[optind + 1], sectorsz);

Verification & Testing

  • Tested bcal 1024 B: exit code is now 0.
  • Tested bcal 1024 invalid: exit code is 255 (-1, error).
  • Compiled with -Wall -Wextra -Werror cleanly.

@jarun
jarun merged commit c078060 into jarun:master Nov 25, 2026
2 checks passed
@jarun

jarun commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants