Skip to content

refactor HexToBin to reduce code paths#241

Open
aidankeefe2022 wants to merge 1 commit into
wolfSSL:mainfrom
aidankeefe2022:refactor-HexToBin-to-decrease-code-paths
Open

refactor HexToBin to reduce code paths#241
aidankeefe2022 wants to merge 1 commit into
wolfSSL:mainfrom
aidankeefe2022:refactor-HexToBin-to-decrease-code-paths

Conversation

@aidankeefe2022

@aidankeefe2022 aidankeefe2022 commented Jun 2, 2026

Copy link
Copy Markdown
Member

refactored hexToBin function to reduce code paths and increase code coverage. Previous function had 75% of it never hit causing code branches to not be called this new version removes those and allows for the same logic to be used for all of the function arguments. previous version was also a little harder to read * personal opinion.

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenrir Automated Review — PR #241

Scan targets checked: wolfclu-bugs, wolfclu-src

No new issues found in the changed files. ✅

@aidankeefe2022 aidankeefe2022 force-pushed the refactor-HexToBin-to-decrease-code-paths branch from 0952756 to 26666e9 Compare June 2, 2026 18:42

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenrir Automated Review — PR #241

Scan targets checked: wolfclu-bugs, wolfclu-src

Findings: 1
1 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Findings are non-blocking.

@aidankeefe2022 aidankeefe2022 force-pushed the refactor-HexToBin-to-decrease-code-paths branch from 26666e9 to 750f158 Compare June 2, 2026 22:34

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenrir Automated Review — PR #241

Scan targets checked: wolfclu-bugs, wolfclu-src

No new issues found in the changed files. ✅

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors wolfCLU_hexToBin to remove repeated per-argument decode blocks and consolidate the logic into a single loop, aiming to reduce unreachable branches and improve coverage for the shared conversion path.

Changes:

  • Replaced four near-identical hex-to-binary conversion blocks with an indexed loop over the four possible inputs/outputs.
  • Centralized error handling and cleanup into a single post-loop failure path.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/tools/clu_hex_to_bin.c
@cconlon cconlon assigned aidankeefe2022 and unassigned cconlon Jun 8, 2026
@aidankeefe2022 aidankeefe2022 changed the title refactored hexToBin function to reduct code paths and increase code c… refactor HexToBin to reduce code paths Jun 8, 2026
@aidankeefe2022 aidankeefe2022 force-pushed the refactor-HexToBin-to-decrease-code-paths branch from 750f158 to 1f5915e Compare June 8, 2026 21:15
Comment thread src/tools/clu_hex_to_bin.c Outdated
if (ret != 0) {
wolfCLU_freeBins(*b1, NULL, NULL, NULL, NULL);
return ret;
for (;i < 4; i++) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have a space after the ;

Comment thread src/tools/clu_hex_to_bin.c Outdated
for (;i < 4; i++) {
if (hex[i] && bs[i] && bSz[i]) {
*bSz[i] = (int)XSTRLEN(hex[i]) / 2;
*bs[i] = XMALLOC(*bSz[i], NULL, DYNAMIC_TYPE_TMP_BUFFER);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was pre-existing, but can we cast XMALLOC back to the type being allocated? That will align us to our coding standards.

@cconlon cconlon assigned aidankeefe2022 and unassigned cconlon Jun 9, 2026
@aidankeefe2022 aidankeefe2022 force-pushed the refactor-HexToBin-to-decrease-code-paths branch from 1f5915e to 653b342 Compare June 9, 2026 21:32
@aidankeefe2022 aidankeefe2022 removed their assignment Jun 9, 2026
@aidankeefe2022 aidankeefe2022 requested a review from cconlon June 9, 2026 22:29
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.

5 participants