Skip to content

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

Open
pro-laxmi wants to merge 1 commit into
jarun:masterfrom
pro-laxmi:fix/exit-code-unit-conversion
Open

pro-laxmi wants to merge 1 commit into
jarun:masterfrom
pro-laxmi:fix/exit-code-unit-conversion

Conversation

@pro-laxmi

Copy link
Copy Markdown

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.

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.

1 participant