cmd/libsnap-confine-private: fix TICS CS coding-standard return-statement violations - #1
Open
Rnfudge02 wants to merge 2 commits into
Open
cmd/libsnap-confine-private: fix TICS CS coding-standard return-statement violations#1Rnfudge02 wants to merge 2 commits into
Rnfudge02 wants to merge 2 commits into
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.csc_init_apparmor_supportelsebranch instead of early returnsc_maybe_aa_change_onexecSC_AA_NOT_APPLICABLEguard so body runs only when applicable_sc_cleanup_v2_device_keysc_device_cgroup_cleanupCommit 2 — rule 6.8.6.4.a: return at nesting level > 1
Files:
feature.c,cgroup-support.c,classic.csc_feature_enabledfstatat()error check to positive-path with result variablesc_cgroup_is_v2errnocheck to movereturn falsefrom depth 2 to depth 1sc_classify_distrosc_is_debian_likeforloop withbreak+ result variableVerification
gcc -fsyntax-onlypasses on all five modified filesgit diff --checkreports no whitespace issuesTICS_LOCAL_PROJECT(not configured in dev environment); CI TICS run will confirm resolutionGenerated with claude-sonnet-4.6