Skip to content

cmd/libsnap-confine-private: fix TICS CS coding-standard return-statement violations - #1

Open
Rnfudge02 wants to merge 2 commits into
pin-gocoverfrom
tics/cs-return-statements
Open

cmd/libsnap-confine-private: fix TICS CS coding-standard return-statement violations#1
Rnfudge02 wants to merge 2 commits into
pin-gocoverfrom
tics/cs-return-statements

Conversation

@Rnfudge02

Copy link
Copy Markdown
Owner

Summary

Fix two categories of MISRA-C Coding Standards violations in
cmd/libsnap-confine-private/ identified via TICS snapshot analysis.
All changes are behaviour-preserving refactors with no logic changes.

Commit 1 — rule 6.8.6.4.b: return in void functions

Files: apparmor-support.c, device-cgroup-support.c

Function Change
sc_init_apparmor_support Wrap aa_getcon/mode-detection body in else branch instead of early return
sc_maybe_aa_change_onexec Invert SC_AA_NOT_APPLICABLE guard so body runs only when applicable
_sc_cleanup_v2_device_key Replace null guard + return with single positive-condition block
sc_device_cgroup_cleanup Same pattern as above

Commit 2 — rule 6.8.6.4.a: return at nesting level > 1

Files: feature.c, cgroup-support.c, classic.c

Function Change
sc_feature_enabled Invert fstatat() error check to positive-path with result variable
sc_cgroup_is_v2 Invert inner errno check to move return false from depth 2 to depth 1
sc_classify_distro Replace dual nested returns with result variable + ternary
sc_is_debian_like Replace three early returns inside for loop with break + result variable

Verification

  • gcc -fsyntax-only passes on all five modified files
  • git diff --check reports no whitespace issues
  • TICS local verification tools require TICS_LOCAL_PROJECT (not configured in dev environment); CI TICS run will confirm resolution

Generated with claude-sonnet-4.6

…urn in void functions

Replace early bare return; guard clauses with inverted conditions
in four void functions to satisfy MISRA-C rule 6.8.6.4.b (void
function must not contain a return statement):

- sc_init_apparmor_support: wrap the aa_getcon/mode-detection body
  in the else branch of the aa_is_enabled() check instead of
  returning early when AppArmor is unavailable.
- sc_maybe_aa_change_onexec: invert the SC_AA_NOT_APPLICABLE guard
  so the body executes only when AppArmor is applicable.
- _sc_cleanup_v2_device_key: replace null-pointer guard + return
  with a single positive-condition block (no behaviour change).
- sc_device_cgroup_cleanup: same pattern as above.
…urn at nesting level > 1

Remove return statements inside nested control structures to satisfy
MISRA-C rule 6.8.6.4.a (return statement must not occur at a nesting
level greater than 1):

- sc_feature_enabled (feature.c): invert the fstatat() error check
  to a positive-path pattern with a result variable; the ENOENT path
  falls through to return false naturally.
- sc_cgroup_is_v2 (cgroup-support.c): invert the inner errno check
  so die() is called at depth 2 and the return false moves to depth 1.
- sc_classify_distro (classic.c): replace dual nested returns with a
  result variable and a single ternary assignment.
- sc_is_debian_like (classic.c): replace the three early returns
  inside the for loop with break and a result variable; behaviour is
  identical since all early return false cases become break with
  result staying false.
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