diff --git a/.clang-format b/.clang-format index 20bf2b2..d1b9171 100644 --- a/.clang-format +++ b/.clang-format @@ -1,131 +1,314 @@ --- -BasedOnStyle: Google -AlignConsecutiveBitFields: - Enabled: true - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: true - PadOperators: true +Language: Cpp +AccessModifierOffset: -1 AlignAfterOpenBracket: BlockIndent AlignArrayOfStructures: Right AlignConsecutiveAssignments: - Enabled: true + Enabled: true + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: true + AlignFunctionDeclarations: false + + PadOperators: true +AlignConsecutiveBitFields: + Enabled: true AcrossEmptyLines: false - AcrossComments: false - PadOperators: true - AlignCompound: true + AcrossComments: false + AlignCompound: true + AlignFunctionDeclarations: false + + PadOperators: true AlignConsecutiveDeclarations: - Enabled: true + Enabled: true AcrossEmptyLines: false - AcrossComments: false - AlignCompound: true - PadOperators: true -AlignOperands: AlignAfterOperator -AlignEscapedNewlines: Right + AcrossComments: false + AlignCompound: true + AlignFunctionDeclarations: true + + PadOperators: true AlignConsecutiveMacros: - Enabled: true + Enabled: true + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: true + AlignFunctionDeclarations: false + + PadOperators: true +AlignConsecutiveTableGenBreakingDAGArgColons: + Enabled: false AcrossEmptyLines: false - AcrossComments: false - AlignCompound: true - PadOperators: true -AlignConsecutiveShortCaseStatements: - Enabled: true + AcrossComments: false + AlignCompound: false + AlignFunctionDeclarations: false + + PadOperators: false +AlignConsecutiveTableGenCondOperatorColons: + Enabled: false AcrossEmptyLines: false - AcrossComments: false - AlignCaseColons: true + AcrossComments: false + AlignCompound: false + AlignFunctionDeclarations: false + + PadOperators: false +AlignConsecutiveTableGenDefinitionColons: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionDeclarations: false + + PadOperators: false +AlignEscapedNewlines: Right +AlignOperands: AlignAfterOperator AlignTrailingComments: - Kind: Always - OverEmptyLines: 2 + Kind: Always + OverEmptyLines: 2 AllowAllArgumentsOnNextLine: false AllowAllParametersOfDeclarationOnNextLine: false +AllowBreakBeforeNoexceptSpecifier: Never AllowShortBlocksOnASingleLine: Empty -AllowShortFunctionsOnASingleLine: Empty +AllowShortCaseExpressionOnASingleLine: true AllowShortCaseLabelsOnASingleLine: false +AllowShortCompoundRequirementOnASingleLine: true AllowShortEnumsOnASingleLine: false +AllowShortFunctionsOnASingleLine: Empty AllowShortIfStatementsOnASingleLine: Never +AllowShortLambdasOnASingleLine: All AllowShortLoopsOnASingleLine: false -AlwaysBreakAfterReturnType: None +AllowShortNamespacesOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakBeforeMultilineStrings: true AttributeMacros: - FORCE_INLINE - PACKED BinPackArguments: false -BinPackParameters: false +BinPackParameters: OnePerLine +BitFieldColonSpacing: Both +BracedInitializerIndentWidth: 4 BraceWrapping: - AfterCaseLabel: false - AfterClass: false + AfterCaseLabel: false + AfterClass: false AfterControlStatement: Never - AfterEnum: false - AfterFunction: false - AfterNamespace: false - AfterObjCDeclaration: false - AfterStruct: false - AfterUnion: false + AfterEnum: false AfterExternBlock: false - BeforeElse: false - BeforeWhile: false - IndentBraces: true -BracedInitializerIndentWidth: 4 -BreakArrays: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakAdjacentStringLiterals: true +BreakAfterAttributes: Leave +BreakAfterJavaFieldAnnotations: false +BreakAfterReturnType: None +BreakArrays: false BreakBeforeBinaryOperators: None +BreakBeforeConceptDeclarations: Always BreakBeforeBraces: Attach BreakBeforeInlineASMColon: Always BreakBeforeTernaryOperators: false +BreakBinaryOperations: Never +BreakConstructorInitializers: BeforeColon +BreakFunctionDefinitionParameters: false +BreakInheritanceList: BeforeColon BreakStringLiterals: true -ColumnLimit: 120 +BreakTemplateDeclarations: Yes +ColumnLimit: 120 +CommentPragmas: '.*' +CompactNamespaces: false +ConstructorInitializerIndentWidth: 4 ContinuationIndentWidth: 4 -IncludeBlocks: Regroup +Cpp11BracedListStyle: true +DerivePointerAlignment: true +DisableFormat: false +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: LogicalBlock +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IfMacros: + - KJ_IF_MAYBE +IncludeBlocks: Regroup +IncludeCategories: + - Regex: '^' + Priority: 2 + SortPriority: 0 + CaseSensitive: false + - Regex: '^<.*\.h>' + Priority: 1 + SortPriority: 0 + CaseSensitive: false + - Regex: '^<.*' + Priority: 2 + SortPriority: 0 + CaseSensitive: false + - Regex: '.*' + Priority: 3 + SortPriority: 0 + CaseSensitive: false +IncludeIsMainRegex: '([-_](test|unittest))?$' +IncludeIsMainSourceRegex: '' +IndentAccessModifiers: false IndentCaseBlocks: false IndentCaseLabels: true +IndentExportBlock: true IndentExternBlock: Indent IndentGotoLabels: false IndentPPDirectives: AfterHash -IndentWidth: 4 +IndentRequiresClause: true +IndentWidth: 4 IndentWrappedFunctionNames: true -InsertBraces: false -KeepEmptyLinesAtEOF: false -KeepEmptyLinesAtTheStartOfBlocks: false -LineEnding: LF +InsertBraces: false +InsertNewlineAtEOF: false +InsertTrailingCommas: None +IntegerLiteralSeparator: + Binary: 0 + BinaryMinDigits: 0 + Decimal: 0 + DecimalMinDigits: 0 + Hex: 0 + HexMinDigits: 0 +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLines: + AtEndOfFile: false + AtStartOfBlock: false + AtStartOfFile: true +KeepFormFeed: false +LambdaBodyIndentation: Signature +LineEnding: LF +MacroBlockBegin: '' +MacroBlockEnd: '' Macros: - - ALLOCATE(type, n) (type*)calloc(sizeof(type), n) - - FREE(x) free((void*)x) - - REALLOCATE(oldptr, type, n) (type*)realloc(oldptr, sizeof(type)*n) + - 'ALLOCATE(type, n) (type*)calloc(sizeof(type), n)' + - 'FREE(x) free((void*)x)' + - 'REALLOCATE(oldptr, type, n) (type*)realloc(oldptr, sizeof(type)*n)' +MainIncludeChar: Quote MaxEmptyLinesToKeep: 4 -PPIndentWidth: 4 +NamespaceIndentation: None +ObjCBinPackProtocolList: Never +ObjCBlockIndentWidth: 2 +ObjCBreakBeforeNestedBlockParam: true +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PackConstructorInitializers: NextLine +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 1 +PenaltyBreakBeforeMemberAccess: 150 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakOpenParenthesis: 0 +PenaltyBreakScopeResolution: 500 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyIndentedWhitespace: 0 +PenaltyReturnTypeOnItsOwnLine: 200 PointerAlignment: Right +PPIndentWidth: 4 QualifierAlignment: Leave +RawStringFormats: + - Language: Cpp + Delimiters: + - cc + - CC + - cpp + - Cpp + - CPP + - 'c++' + - 'C++' + CanonicalDelimiter: '' + BasedOnStyle: google + - Language: TextProto + Delimiters: + - pb + - PB + - proto + - PROTO + EnclosingFunctions: + - EqualsProto + - EquivToProto + - PARSE_PARTIAL_TEXT_PROTO + - PARSE_TEST_PROTO + - PARSE_TEXT_PROTO + - ParseTextOrDie + - ParseTextProtoOrDie + - ParseTestProto + - ParsePartialTestProto + CanonicalDelimiter: pb + BasedOnStyle: google ReferenceAlignment: Right -ReflowComments: true -RemoveParentheses: Leave -SortIncludes: Never +ReflowComments: Always +RemoveBracesLLVM: false +RemoveEmptyLinesInUnwrappedLines: false +RemoveSemicolon: false +RequiresClausePosition: OwnLine +RequiresExpressionIndentation: OuterScope +SeparateDefinitionBlocks: Leave +ShortNamespaceLines: 1 +SkipMacroDefinitionBody: false +SortIncludes: Never +SortJavaStaticImport: Before +SortUsingDeclarations: LexicographicNumeric SpaceAfterCStyleCast: false SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true SpaceAroundPointerQualifiers: Default SpaceBeforeAssignmentOperators: true SpaceBeforeCaseColon: true SpaceBeforeCpp11BracedList: true +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeJsonColon: false SpaceBeforeParens: ControlStatements SpaceBeforeParensOptions: AfterControlStatements: true AfterForeachMacros: true - AfterFunctionDeclarationName: true - AfterFunctionDefinitionName: true - AfterIfMacros: true + AfterFunctionDefinitionName: false + AfterFunctionDeclarationName: false + AfterIfMacros: true + AfterOverloadedOperator: false + AfterPlacementOperator: true + AfterRequiresInClause: false + AfterRequiresInExpression: false + BeforeNonEmptyParentheses: false +SpaceBeforeRangeBasedForLoopColon: true SpaceBeforeSquareBrackets: false SpaceInEmptyBlock: false SpacesBeforeTrailingComments: 1 -UseTab: Never -TabWidth: 4 -Standard: Latest +SpacesInAngles: Never SpacesInContainerLiterals: true SpacesInLineCommentPrefix: - Maximum: -1 - Minimum: 1 -SpacesInParens: Never + Minimum: 1 + Maximum: -1 +SpacesInParens: Never +SpacesInParensOptions: + ExceptDoubleParentheses: false + InCStyleCasts: false + InConditionalStatements: false + InEmptyParentheses: false + Other: false SpacesInSquareBrackets: false +Standard: Latest StatementAttributeLikeMacros: - PACKED - FORCE_INLINE +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TableGenBreakInsideDAGArg: DontBreak +TabWidth: 4 TypeNames: - Char - ZString @@ -145,5 +328,14 @@ TypeNames: - Addr4 - Addr8 - UintPtr -CommentPragmas: .* -Cpp11BracedListStyle: true +UseTab: Never +VerilogBreakBetweenInstancePorts: true +WhitespaceSensitiveMacros: + - BOOST_PP_STRINGIZE + - CF_SWIFT_NAME + - NS_SWIFT_NAME + - PP_STRINGIZE + - STRINGIZE +WrapNamespaceBodyWithEmptyLines: Leave +... + diff --git a/.github/workflows/format-check.yml b/.github/workflows/format-check.yml deleted file mode 100644 index 3c1dfa1..0000000 --- a/.github/workflows/format-check.yml +++ /dev/null @@ -1,96 +0,0 @@ -name: Format Check - -on: - push: - branches: [ main, master ] - pull_request: - branches: [ main, master ] - -jobs: - format-check: - name: Check code formatting with clang-format - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - with: - submodules: recursive - - - name: Install clang-format 20 - run: | - sudo apt-get update - # Install dependencies for HTTPS transport - sudo apt-get install -y software-properties-common wget gnupg lsb-release - # Add LLVM APT repository for Clang 20 - wget https://apt.llvm.org/llvm.sh - chmod +x llvm.sh - sudo ./llvm.sh 20 - # Cleanup - rm llvm.sh - - - name: Check clang-format version - run: clang-format --version - - - name: Find C/C++ files to format - id: find-files - run: | - FILES=$(find . -type f \( -name "*.c" -o -name "*.h" -o -name "*.cpp" -o -name "*.hpp" \) \ - ! -path "./build*" \ - ! -path "./builddir*" \ - ! -path "./.git/*" \ - ! -path "./demangler/*" \ - ! -path "./.cache/*" \ - -print) - echo "Found files:" - echo "$FILES" - echo "files<> $GITHUB_OUTPUT - echo "$FILES" >> $GITHUB_OUTPUT - echo "EOF" >> $GITHUB_OUTPUT - - - name: Check formatting - run: | - EXIT_CODE=0 - FILES="${{ steps.find-files.outputs.files }}" - - if [ -z "$FILES" ]; then - echo "No C/C++ files found to check" - exit 0 - fi - - echo "Checking formatting for files:" - echo "$FILES" - echo "" - - mkdir -p /tmp/formatted - - for file in $FILES; do - if [ -f "$file" ]; then - echo "Checking $file..." - formatted_file="/tmp/formatted/$file" - mkdir -p "$(dirname "$formatted_file")" - clang-format "$file" > "$formatted_file" - - if ! diff -u "$file" "$formatted_file"; then - echo "❌ $file is not properly formatted" - echo "Expected changes shown above (- original, + formatted)" - echo "" - EXIT_CODE=1 - else - echo "✅ $file is properly formatted" - fi - fi - done - - if [ $EXIT_CODE -eq 0 ]; then - echo "" - echo "🎉 All files are properly formatted!" - else - echo "" - echo "💥 Some files are not properly formatted." - echo "To fix formatting issues, run:" - echo " clang-format -i " - echo "Or format all files:" - echo " find . -name '*.c' -o -name '*.h' | xargs clang-format -i" - fi - - exit $EXIT_CODE diff --git a/.github/workflows/fuzz.yml b/.github/workflows/fuzz.yml index ab3d1b6..674c090 100644 --- a/.github/workflows/fuzz.yml +++ b/.github/workflows/fuzz.yml @@ -10,6 +10,11 @@ on: - cron: '0 2 * * *' workflow_dispatch: +# Automatically cancel any previous workflow on new push. +concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }} + cancel-in-progress: true + jobs: fuzz: runs-on: ubuntu-latest diff --git a/.github/workflows/hugo.yml b/.github/workflows/hugo.yml index e4f34f2..6ee6a4f 100644 --- a/.github/workflows/hugo.yml +++ b/.github/workflows/hugo.yml @@ -12,7 +12,7 @@ permissions: concurrency: group: "pages" - cancel-in-progress: false + cancel-in-progress: true defaults: run: diff --git a/.github/workflows/test-linux.yml b/.github/workflows/test-linux.yml index ad39a65..3f70c7b 100644 --- a/.github/workflows/test-linux.yml +++ b/.github/workflows/test-linux.yml @@ -6,6 +6,11 @@ on: pull_request: branches: [ main, master ] +# Automatically cancel any previous workflow on new push. +concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }} + cancel-in-progress: true + jobs: build-and-test: name: Build and Test on Ubuntu diff --git a/.github/workflows/test-macos.yml b/.github/workflows/test-macos.yml index b05acea..93001a9 100644 --- a/.github/workflows/test-macos.yml +++ b/.github/workflows/test-macos.yml @@ -6,6 +6,11 @@ on: pull_request: branches: [ main, master ] +# Automatically cancel any previous workflow on new push. +concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }} + cancel-in-progress: true + jobs: build-and-test: name: Build and Test on macOS diff --git a/.github/workflows/test-windows-llvm.yml b/.github/workflows/test-windows-llvm.yml index 7070648..37416d1 100644 --- a/.github/workflows/test-windows-llvm.yml +++ b/.github/workflows/test-windows-llvm.yml @@ -1,9 +1,16 @@ name: Windows LLVM Build + on: push: branches: [ master ] pull_request: branches: [ master ] + +# Automatically cancel any previous workflow on new push. +concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }} + cancel-in-progress: true + jobs: build-and-test: name: Build and Test on Windows with LLVM diff --git a/.github/workflows/test-windows-msvc.yml b/.github/workflows/test-windows-msvc.yml index a6f5496..c15eb24 100644 --- a/.github/workflows/test-windows-msvc.yml +++ b/.github/workflows/test-windows-msvc.yml @@ -6,6 +6,11 @@ on: pull_request: branches: [ master ] +# Automatically cancel any previous workflow on new push. +concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }} + cancel-in-progress: true + jobs: build-and-test: name: Build and Test on Windows diff --git a/Fuzz/Harness/ListInt.c b/Fuzz/Harness/ListInt.c index 8cd0d30..53b9542 100644 --- a/Fuzz/Harness/ListInt.c +++ b/Fuzz/Harness/ListInt.c @@ -192,7 +192,7 @@ void fuzz_int_list(IntList *list, ListIntFunction func, const uint8_t *data, siz } case LIST_INT_MERGE : { - IntList temp = ListInitT(temp); + IntList temp = ListInitT(temp); uint8_t count = extract_u8(data, offset, size); count = count % 4; diff --git a/Include/Misra/Std/Container/List/Access.h b/Include/Misra/Std/Container/List/Access.h index 9c02261..68509eb 100644 --- a/Include/Misra/Std/Container/List/Access.h +++ b/Include/Misra/Std/Container/List/Access.h @@ -32,7 +32,7 @@ #define ListPtrAt(l, idx) ((LIST_DATA_TYPE(l) *)item_ptr_at_list(GENERIC_LIST(l), sizeof(LIST_DATA_TYPE(l)), (idx))) #ifdef __cplusplus -#define ListAt(l, idx) (ListPtrAt((l), (idx)) ? *ListPtrAt((l), (idx)) : (LIST_DATA_TYPE(l) {0})) +# define ListAt(l, idx) (ListPtrAt((l), (idx)) ? *ListPtrAt((l), (idx)) : (LIST_DATA_TYPE(l) {0})) #else /// /// Data in node at given index in given list @@ -45,7 +45,7 @@ /// SUCCESS: Data from node in list at given index. /// FAILURE: Emtpy object. /// -#define ListAt(l, idx) (ListPtrAt((l), (idx)) ? *ListPtrAt((l), (idx)) : ((LIST_DATA_TYPE(l)) {0})) +# define ListAt(l, idx) (ListPtrAt((l), (idx)) ? *ListPtrAt((l), (idx)) : ((LIST_DATA_TYPE(l)) {0})) #endif /// diff --git a/Include/Misra/Std/Container/List/Foreach.h b/Include/Misra/Std/Container/List/Foreach.h index 0158386..7a505fc 100644 --- a/Include/Misra/Std/Container/List/Foreach.h +++ b/Include/Misra/Std/Container/List/Foreach.h @@ -23,15 +23,17 @@ /// /// TAGS: Foreach, List, Iteration, Loop /// -#define ListForeach(l, var) \ - for (TYPE_OF(l) UNPL(pl) = (l); UNPL(pl); UNPL(pl) = NULL) \ - if ((ValidateList(UNPL(pl)), 1) && (UNPL(pl)->head)) \ - for (GenericListNode * UNPL(node) = (GenericListNode *)ListNodeBegin(UNPL(pl)); UNPL(node); \ - UNPL(node) = ListNodeNext(UNPL(node))) \ - if (((void *)UNPL(node)->next != (void *)UNPL(node)) && \ - ((void *)UNPL(node)->prev != (void *)UNPL(node)) && (UNPL(node)->data)) \ - for (bool UNPL(_once) = true; UNPL(_once); UNPL(_once) = false) \ - for (LIST_DATA_TYPE(UNPL(pl)) var = *((LIST_DATA_TYPE(UNPL(pl)) *)(UNPL(node)->data)); UNPL(_once); UNPL(_once) = false) +#define ListForeach(l, var) \ + for (TYPE_OF(l) UNPL(pl) = (l); UNPL(pl); UNPL(pl) = NULL) \ + if ((ValidateList(UNPL(pl)), 1) && (UNPL(pl)->head)) \ + for (GenericListNode * UNPL(node) = (GenericListNode *)ListNodeBegin(UNPL(pl)); UNPL(node); \ + UNPL(node) = ListNodeNext(UNPL(node))) \ + if (((void *)UNPL(node)->next != (void *)UNPL(node)) && \ + ((void *)UNPL(node)->prev != (void *)UNPL(node)) && (UNPL(node)->data)) \ + for (bool UNPL(_once) = true; UNPL(_once); UNPL(_once) = false) \ + for (LIST_DATA_TYPE(UNPL(pl)) var = *((LIST_DATA_TYPE(UNPL(pl)) *)(UNPL(node)->data)); \ + UNPL(_once); \ + UNPL(_once) = false) /// /// Iterate over each element var (as a pointer) of the given list l. @@ -48,15 +50,17 @@ /// /// TAGS: Foreach, List, Iteration, Loop, Pointer /// -#define ListForeachPtr(l, var) \ - for (TYPE_OF(l) UNPL(pl) = (l); UNPL(pl); UNPL(pl) = NULL) \ - if ((ValidateList(UNPL(pl)), 1) && (UNPL(pl)->head)) \ - for (GenericListNode * UNPL(node) = (GenericListNode *)ListNodeBegin(UNPL(pl)); UNPL(node); \ - UNPL(node) = ListNodeNext(UNPL(node))) \ - if (((void *)UNPL(node)->next != (void *)UNPL(node)) && \ - ((void *)UNPL(node)->prev != (void *)UNPL(node)) && (UNPL(node)->data)) \ - for (bool UNPL(_once) = true; UNPL(_once); UNPL(_once) = false) \ - for (LIST_DATA_TYPE(UNPL(pl)) *var = (LIST_DATA_TYPE(UNPL(pl)) *)(UNPL(node)->data); UNPL(_once); UNPL(_once) = false) +#define ListForeachPtr(l, var) \ + for (TYPE_OF(l) UNPL(pl) = (l); UNPL(pl); UNPL(pl) = NULL) \ + if ((ValidateList(UNPL(pl)), 1) && (UNPL(pl)->head)) \ + for (GenericListNode * UNPL(node) = (GenericListNode *)ListNodeBegin(UNPL(pl)); UNPL(node); \ + UNPL(node) = ListNodeNext(UNPL(node))) \ + if (((void *)UNPL(node)->next != (void *)UNPL(node)) && \ + ((void *)UNPL(node)->prev != (void *)UNPL(node)) && (UNPL(node)->data)) \ + for (bool UNPL(_once) = true; UNPL(_once); UNPL(_once) = false) \ + for (LIST_DATA_TYPE(UNPL(pl)) *var = (LIST_DATA_TYPE(UNPL(pl)) *)(UNPL(node)->data); \ + UNPL(_once); \ + UNPL(_once) = false) /// /// Iterate over each element var of the given list l in reverse order. @@ -73,15 +77,17 @@ /// /// TAGS: Foreach, List, Iteration, Loop, Reverse /// -#define ListForeachReverse(l, var) \ - for (TYPE_OF(l) UNPL(pl) = (l); UNPL(pl); UNPL(pl) = NULL) \ - if ((ValidateList(UNPL(pl)), 1) && (UNPL(pl)->tail)) \ - for (GenericListNode * UNPL(node) = (GenericListNode *)ListNodeEnd(UNPL(pl)); UNPL(node); \ - UNPL(node) = ListNodePrev(UNPL(node))) \ - if (((void *)UNPL(node)->next != (void *)UNPL(node)) && \ - ((void *)UNPL(node)->prev != (void *)UNPL(node)) && (UNPL(node)->data)) \ - for (bool UNPL(_once) = true; UNPL(_once); UNPL(_once) = false) \ - for (LIST_DATA_TYPE(UNPL(pl)) var = *((LIST_DATA_TYPE(UNPL(pl)) *)(UNPL(node)->data)); UNPL(_once); UNPL(_once) = false) +#define ListForeachReverse(l, var) \ + for (TYPE_OF(l) UNPL(pl) = (l); UNPL(pl); UNPL(pl) = NULL) \ + if ((ValidateList(UNPL(pl)), 1) && (UNPL(pl)->tail)) \ + for (GenericListNode * UNPL(node) = (GenericListNode *)ListNodeEnd(UNPL(pl)); UNPL(node); \ + UNPL(node) = ListNodePrev(UNPL(node))) \ + if (((void *)UNPL(node)->next != (void *)UNPL(node)) && \ + ((void *)UNPL(node)->prev != (void *)UNPL(node)) && (UNPL(node)->data)) \ + for (bool UNPL(_once) = true; UNPL(_once); UNPL(_once) = false) \ + for (LIST_DATA_TYPE(UNPL(pl)) var = *((LIST_DATA_TYPE(UNPL(pl)) *)(UNPL(node)->data)); \ + UNPL(_once); \ + UNPL(_once) = false) /// /// Iterate over each element var (as a pointer) of the given list l in reverse order. @@ -98,15 +104,17 @@ /// /// TAGS: Foreach, List, Iteration, Loop, Reverse, Pointer /// -#define ListForeachPtrReverse(l, var) \ - for (TYPE_OF(l) UNPL(pl) = (l); UNPL(pl); UNPL(pl) = NULL) \ - if ((ValidateList(UNPL(pl)), 1) && (UNPL(pl)->tail)) \ - for (GenericListNode * UNPL(node) = (GenericListNode *)ListNodeEnd(UNPL(pl)); UNPL(node); \ - UNPL(node) = ListNodePrev(UNPL(node))) \ - if (((void *)UNPL(node)->next != (void *)UNPL(node)) && \ - ((void *)UNPL(node)->prev != (void *)UNPL(node)) && (UNPL(node)->data)) \ - for (bool UNPL(_once) = true; UNPL(_once); UNPL(_once) = false) \ - for (LIST_DATA_TYPE(UNPL(pl)) *var = (LIST_DATA_TYPE(UNPL(pl)) *)(UNPL(node)->data); UNPL(_once); UNPL(_once) = false) +#define ListForeachPtrReverse(l, var) \ + for (TYPE_OF(l) UNPL(pl) = (l); UNPL(pl); UNPL(pl) = NULL) \ + if ((ValidateList(UNPL(pl)), 1) && (UNPL(pl)->tail)) \ + for (GenericListNode * UNPL(node) = (GenericListNode *)ListNodeEnd(UNPL(pl)); UNPL(node); \ + UNPL(node) = ListNodePrev(UNPL(node))) \ + if (((void *)UNPL(node)->next != (void *)UNPL(node)) && \ + ((void *)UNPL(node)->prev != (void *)UNPL(node)) && (UNPL(node)->data)) \ + for (bool UNPL(_once) = true; UNPL(_once); UNPL(_once) = false) \ + for (LIST_DATA_TYPE(UNPL(pl)) *var = (LIST_DATA_TYPE(UNPL(pl)) *)(UNPL(node)->data); \ + UNPL(_once); \ + UNPL(_once) = false) /// /// Iterate over each element var of the given list l in the index range [start, end). @@ -126,15 +134,17 @@ /// /// TAGS: Foreach, List, Iteration, Loop, Range /// -#define ListForeachInRange(l, var, start, end) \ - for (TYPE_OF(l) UNPL(pl) = (l); UNPL(pl); UNPL(pl) = NULL) \ - if ((ValidateList(UNPL(pl)), 1) && UNPL(pl)->head) \ - for (GenericListNode * UNPL(node) = (GenericListNode *)ListNodeBegin(UNPL(pl)); UNPL(node); \ - UNPL(node) = ListNodeNext(UNPL(node))) \ +#define ListForeachInRange(l, var, start, end) \ + for (TYPE_OF(l) UNPL(pl) = (l); UNPL(pl); UNPL(pl) = NULL) \ + if ((ValidateList(UNPL(pl)), 1) && UNPL(pl)->head) \ + for (GenericListNode * UNPL(node) = (GenericListNode *)ListNodeBegin(UNPL(pl)); UNPL(node); \ + UNPL(node) = ListNodeNext(UNPL(node))) \ for (u64 UNPL(i) = 0; UNPL(node) && UNPL(i) < (end); UNPL(node) = ListNodeNext(UNPL(node)), ++UNPL(i)) \ if (UNPL(i) >= (start) && (UNPL(node)->data)) \ for (bool UNPL(_once) = true; UNPL(_once); UNPL(_once) = false) \ - for (LIST_DATA_TYPE(UNPL(pl)) var = *((LIST_DATA_TYPE(UNPL(pl)) *)(UNPL(node)->data)); UNPL(_once); UNPL(_once) = false) + for (LIST_DATA_TYPE(UNPL(pl)) var = *((LIST_DATA_TYPE(UNPL(pl)) *)(UNPL(node)->data)); \ + UNPL(_once); \ + UNPL(_once) = false) /// /// This macro performs forward traversal, starting at index start (inclusive) @@ -151,15 +161,17 @@ /// /// TAGS: Foreach, List, Iteration, Loop, Range, Pointer /// -#define ListForeachPtrInRange(l, var, start, end) \ - for (TYPE_OF(l) UNPL(pl) = (l); UNPL(pl); UNPL(pl) = NULL) \ - if ((ValidateList(UNPL(pl)), 1) && UNPL(pl)->head) \ - for (GenericListNode * UNPL(node) = (GenericListNode *)ListNodeBegin(UNPL(pl)); UNPL(node); \ - UNPL(node) = ListNodeNext(UNPL(node))) \ +#define ListForeachPtrInRange(l, var, start, end) \ + for (TYPE_OF(l) UNPL(pl) = (l); UNPL(pl); UNPL(pl) = NULL) \ + if ((ValidateList(UNPL(pl)), 1) && UNPL(pl)->head) \ + for (GenericListNode * UNPL(node) = (GenericListNode *)ListNodeBegin(UNPL(pl)); UNPL(node); \ + UNPL(node) = ListNodeNext(UNPL(node))) \ for (u64 UNPL(i) = 0; UNPL(node) && UNPL(i) < (end); UNPL(node) = ListNodeNext(UNPL(node)), ++UNPL(i)) \ if (UNPL(i) >= (start) && (UNPL(node)->data)) \ for (bool UNPL(_once) = true; UNPL(_once); UNPL(_once) = false) \ - for (LIST_DATA_TYPE(UNPL(pl)) *var = (LIST_DATA_TYPE(UNPL(pl)) *)(UNPL(node)->data); UNPL(_once); UNPL(_once) = false) + for (LIST_DATA_TYPE(UNPL(pl)) *var = (LIST_DATA_TYPE(UNPL(pl)) *)(UNPL(node)->data); \ + UNPL(_once); \ + UNPL(_once) = false) /// /// Iterate over each element var of the given list l in reverse, limited to index range [start, end) @@ -178,15 +190,17 @@ /// /// TAGS: Foreach, List, Iteration, Loop, Reverse, Range /// -#define ListForeachReverseInRange(l, var, start, end) \ - for (TYPE_OF(l) UNPL(pl) = (l); UNPL(pl); UNPL(pl) = NULL) \ - if ((ValidateList(UNPL(pl)), 1) && UNPL(pl)->tail) \ - for (GenericListNode * UNPL(node) = (GenericListNode *)ListNodeEnd(UNPL(pl)); UNPL(node); \ - UNPL(node) = ListNodePrev(UNPL(node))) \ +#define ListForeachReverseInRange(l, var, start, end) \ + for (TYPE_OF(l) UNPL(pl) = (l); UNPL(pl); UNPL(pl) = NULL) \ + if ((ValidateList(UNPL(pl)), 1) && UNPL(pl)->tail) \ + for (GenericListNode * UNPL(node) = (GenericListNode *)ListNodeEnd(UNPL(pl)); UNPL(node); \ + UNPL(node) = ListNodePrev(UNPL(node))) \ for (u64 UNPL(i) = 0; UNPL(node) && UNPL(i) < (end); UNPL(node) = ListNodePrev(UNPL(node)), ++UNPL(i)) \ if (UNPL(i) >= (start) && (UNPL(node)->data)) \ for (bool UNPL(_once) = true; UNPL(_once); UNPL(_once) = false) \ - for (LIST_DATA_TYPE(UNPL(pl)) var = *((LIST_DATA_TYPE(UNPL(pl)) *)(UNPL(node)->data)); UNPL(_once); UNPL(_once) = false) + for (LIST_DATA_TYPE(UNPL(pl)) var = *((LIST_DATA_TYPE(UNPL(pl)) *)(UNPL(node)->data)); \ + UNPL(_once); \ + UNPL(_once) = false) /// /// Iterate over each element var (as a pointer) of the given list l in reverse, @@ -206,15 +220,17 @@ /// /// TAGS: Foreach, List, Iteration, Loop, Reverse, Range, Pointer /// -#define ListForeachPtrReverseInRange(l, var, start, end) \ - for (TYPE_OF(l) UNPL(pl) = (l); UNPL(pl); UNPL(pl) = NULL) \ - if ((ValidateList(UNPL(pl)), 1) && UNPL(pl)->tail) \ - for (GenericListNode * UNPL(node) = (GenericListNode *)ListNodeEnd(UNPL(pl)); UNPL(node); \ - UNPL(node) = ListNodePrev(UNPL(node))) \ +#define ListForeachPtrReverseInRange(l, var, start, end) \ + for (TYPE_OF(l) UNPL(pl) = (l); UNPL(pl); UNPL(pl) = NULL) \ + if ((ValidateList(UNPL(pl)), 1) && UNPL(pl)->tail) \ + for (GenericListNode * UNPL(node) = (GenericListNode *)ListNodeEnd(UNPL(pl)); UNPL(node); \ + UNPL(node) = ListNodePrev(UNPL(node))) \ for (u64 UNPL(i) = 0; UNPL(node) && UNPL(i) < (end); UNPL(node) = ListNodePrev(UNPL(node)), ++UNPL(i)) \ if (UNPL(i) >= (start) && (UNPL(node)->data)) \ for (bool UNPL(_once) = true; UNPL(_once); UNPL(_once) = false) \ - for (LIST_DATA_TYPE(UNPL(pl)) *var = (LIST_DATA_TYPE(UNPL(pl)) *)(UNPL(node)->data); UNPL(_once); UNPL(_once) = false) + for (LIST_DATA_TYPE(UNPL(pl)) *var = (LIST_DATA_TYPE(UNPL(pl)) *)(UNPL(node)->data); \ + UNPL(_once); \ + UNPL(_once) = false) /// /// Iterate over each element `var` of the given list `l`, with index `idx`. @@ -240,21 +256,22 @@ for (TYPE_OF(l) UNPL(pl) = (l); UNPL(pl); UNPL(pl) = NULL) \ if ((ValidateList(UNPL(pl)), 1) && UNPL(pl)->head) \ for (u64 idx = 0, UNPL(pidx) = 0; idx < UNPL(pl)->length;) \ - for (GenericListNode * UNPL(node) = (GenericListNode *)ListNodeBegin(UNPL(pl)), \ - *UNPL(next) = NULL; \ + for (GenericListNode * UNPL(node) = (GenericListNode *)ListNodeBegin(UNPL(pl)), *UNPL(next) = NULL; \ UNPL(node) && \ (UNPL(next) = \ - (UNPL(pidx) ? (GenericListNode *)get_node_random_access( \ + (UNPL(pidx) ? (GenericListNode *)get_node_random_access( \ GENERIC_LIST(UNPL(pl)), \ GENERIC_LIST_NODE(UNPL(node)), \ UNPL(pidx), \ (i64)(idx) - (i64)UNPL(pidx) \ ) : \ - (GenericListNode *)UNPL(pl)->head)) && \ + (GenericListNode *)UNPL(pl)->head)) && \ UNPL(next) && UNPL(next)->data; \ UNPL(pidx) = ++idx, UNPL(node) = UNPL(next)) \ for (bool UNPL(_once) = true; UNPL(_once); UNPL(_once) = false) \ - for (LIST_DATA_TYPE(UNPL(pl)) var = *((LIST_DATA_TYPE(UNPL(pl)) *)(UNPL(next)->data)); UNPL(_once); UNPL(_once) = false) + for (LIST_DATA_TYPE(UNPL(pl)) var = *((LIST_DATA_TYPE(UNPL(pl)) *)(UNPL(next)->data)); \ + UNPL(_once); \ + UNPL(_once) = false) /// /// Iterate over each element `var` (as a pointer) of the given list `l`, with index `idx`. @@ -280,17 +297,16 @@ for (TYPE_OF(l) UNPL(pl) = (l); UNPL(pl); UNPL(pl) = NULL) \ if ((ValidateList(UNPL(pl)), 1) && UNPL(pl)->head) \ for (u64 idx = 0, UNPL(pidx) = 0; idx < UNPL(pl)->length;) \ - for (GenericListNode * UNPL(node) = (GenericListNode *)ListNodeBegin(UNPL(pl)), \ - *UNPL(next) = NULL; \ + for (GenericListNode * UNPL(node) = (GenericListNode *)ListNodeBegin(UNPL(pl)), *UNPL(next) = NULL; \ UNPL(node) && \ (UNPL(next) = \ - (UNPL(pidx) ? (GenericListNode *)get_node_random_access( \ + (UNPL(pidx) ? (GenericListNode *)get_node_random_access( \ GENERIC_LIST(UNPL(pl)), \ GENERIC_LIST_NODE(UNPL(node)), \ UNPL(pidx), \ (i64)(idx) - (i64)UNPL(pidx) \ ) : \ - (GenericListNode *)UNPL(pl)->head)) && \ + (GenericListNode *)UNPL(pl)->head)) && \ UNPL(next) && UNPL(next)->data; \ UNPL(pidx) = ++idx, UNPL(node) = UNPL(next)) \ for (bool UNPL(_once) = true; UNPL(_once); UNPL(_once) = false) \ @@ -317,13 +333,16 @@ #define ListForeachReverseIdx(l, var, idx) \ for (TYPE_OF(l) UNPL(pl) = (l); UNPL(pl); UNPL(pl) = NULL) \ if ((ValidateList(UNPL(pl)), 1) && UNPL(pl)->tail && UNPL(pl)->length > 0) \ - for (u64 idx = UNPL(pl)->length - 1, UNPL(pidx) = UNPL(pl)->length - 1, UNPL(first) = 1, UNPL(user_idx) = 0; \ + for (u64 idx = UNPL(pl)->length - 1, \ + UNPL(pidx) = UNPL(pl)->length - 1, \ + UNPL(first) = 1, \ + UNPL(user_idx) = 0; \ idx < UNPL(pl)->length;) \ - for (GenericListNode * UNPL(node) = (UNPL(first) ? (GenericListNode *)UNPL(pl)->tail : NULL), \ - *UNPL(next) = NULL; \ + for (GenericListNode * UNPL(node) = (UNPL(first) ? (GenericListNode *)UNPL(pl)->tail : NULL), \ + *UNPL(next) = NULL; \ UNPL(node) && idx < UNPL(pl)->length && (UNPL(first) = 0) && \ (UNPL(next) = \ - (UNPL(pidx) != idx ? (GenericListNode *)get_node_random_access( \ + (UNPL(pidx) != idx ? (GenericListNode *)get_node_random_access( \ GENERIC_LIST(UNPL(pl)), \ GENERIC_LIST_NODE(UNPL(node)), \ UNPL(pidx), \ @@ -333,7 +352,9 @@ UNPL(next) && UNPL(next)->data; \ UNPL(node) = UNPL(next), UNPL(pidx) = idx) \ for (bool UNPL(_once) = true; UNPL(_once); UNPL(_once) = false) \ - for (LIST_DATA_TYPE(UNPL(pl)) var = *((LIST_DATA_TYPE(UNPL(pl)) *)(UNPL(next)->data)); UNPL(_once); UNPL(_once) = false) \ + for (LIST_DATA_TYPE(UNPL(pl)) var = *((LIST_DATA_TYPE(UNPL(pl)) *)(UNPL(next)->data)); \ + UNPL(_once); \ + UNPL(_once) = false) \ for (bool UNPL(_update) = true; UNPL(_update); \ UNPL(_update) = false, \ UNPL(user_idx) = idx, \ @@ -362,10 +383,13 @@ #define ListForeachPtrReverseIdx(l, var, idx) \ for (TYPE_OF(l) UNPL(pl) = (l); UNPL(pl); UNPL(pl) = NULL) \ if ((ValidateList(UNPL(pl)), 1) && UNPL(pl)->tail && UNPL(pl)->length > 0) \ - for (u64 idx = UNPL(pl)->length - 1, UNPL(pidx) = UNPL(pl)->length - 1, UNPL(first) = 1, UNPL(user_idx) = 0; \ + for (u64 idx = UNPL(pl)->length - 1, \ + UNPL(pidx) = UNPL(pl)->length - 1, \ + UNPL(first) = 1, \ + UNPL(user_idx) = 0; \ idx < UNPL(pl)->length;) \ - for (GenericListNode * UNPL(node) = (UNPL(first) ? (GenericListNode *)UNPL(pl)->tail : NULL), \ - *UNPL(next) = NULL; \ + for (GenericListNode * UNPL(node) = (UNPL(first) ? (GenericListNode *)UNPL(pl)->tail : NULL), \ + *UNPL(next) = NULL; \ UNPL(node) && idx < UNPL(pl)->length && (UNPL(first) = 0) && \ (UNPL(next) = \ (UNPL(pidx) != idx ? get_node_random_access( \ diff --git a/Include/Misra/Std/Container/List/Remove.h b/Include/Misra/Std/Container/List/Remove.h index 16756e8..bb4fb1e 100644 --- a/Include/Misra/Std/Container/List/Remove.h +++ b/Include/Misra/Std/Container/List/Remove.h @@ -20,7 +20,8 @@ /// SUCCESS : Returns `v` on success. /// FAILURE : Returns NULL otherwise. /// -#define ListRemove(l, val, idx) remove_range_list(GENERIC_LIST(l), (val), sizeof(LIST_DATA_TYPE(l)), ((l)->length - 1), 1) +#define ListRemove(l, val, idx) \ + remove_range_list(GENERIC_LIST(l), (val), sizeof(LIST_DATA_TYPE(l)), ((l)->length - 1), 1) /// /// Remove item from the very beginning of list. diff --git a/Scripts/clang-format.py b/Scripts/clang-format.py index 4a52f22..aefe06a 100644 --- a/Scripts/clang-format.py +++ b/Scripts/clang-format.py @@ -1,90 +1,127 @@ -import os +#!/usr/bin/env python3 +# +# SPDX-FileCopyrightText: 2021 Anton Kochkov +# SPDX-License-Identifier: LGPL-3.0-only + +# Snagged from github.com/rizinorg/rizin +# Thanks for having a reliable script and a workflow! + +import argparse +import glob +import itertools import subprocess -import shutil -from pathlib import Path - -# List of file extensions for C and C++ source files -C_CPP_EXTENSIONS = {'.c', '.cpp', '.h', '.hpp', '.cc', '.cxx', '.hxx'} - -def find_clang_format(): - """Find the path to the clang-format executable.""" - clang_format_path = shutil.which('clang-format') # Works on both Windows and POSIX systems - if clang_format_path: - print(f"Using clang-format at: {clang_format_path}") - return clang_format_path +import sys + +from git import Repo + +dirlist = [ + "Source", + "Include", + "Bin", + "Tests", + "Fuzz", +] + +skiplist = [".clang-format"] + +patterns = ["*.c", "*.cpp", "*.h", "*.hpp", "*.inc"] + +def should_scan(filename): + return any(directory in filename for directory in dirlist) and any( + pattern[1:] in filename for pattern in patterns + ) + + +def skip(filename): + return any(skipfile in filename for skipfile in skiplist) + + +def get_matching_files(): + for directory, pattern in itertools.product(dirlist, patterns): + for filename in glob.iglob(directory + "/**/" + pattern, recursive=True): + if not skip(filename): + yield filename + + +def get_edited_files(args): + repo = Repo() + + for diff in repo.index.diff(args.diff): + filename = diff.a_path + if should_scan(filename) and not skip(filename): + yield filename + + +def build_command(clangformat, check, filenames, verbose): + cmd = [clangformat, "--style=file"] + if verbose: + cmd += ["--verbose"] + if check: + cmd += ["--Werror", "--dry-run"] else: - print("Error: clang-format not found. Please ensure clang-format is installed and in your PATH.") - exit(1) - -def find_clang_format_dir(start_dir): - """Find the nearest directory containing a .clang-format file.""" - current_dir = Path(start_dir).resolve() - - while current_dir != current_dir.parent: - clang_format_path = current_dir / ".clang-format" - if clang_format_path.exists(): - return clang_format_path - current_dir = current_dir.parent - - return None # No .clang-format found up to the root - -def parse_gitignore(root_dir): - """Parse the .gitignore file and return a list of patterns to ignore.""" - gitignore_path = Path(root_dir) / '.gitignore' - ignored_paths = set() - - if gitignore_path.exists(): - with open(gitignore_path, 'r') as f: - lines = f.readlines() - for line in lines: - line = line.strip() - if line and not line.startswith('#'): # Skip comments and empty lines - ignored_paths.add(line) - - return ignored_paths - -def is_ignored(file_path, ignored_paths): - """Check if the file or directory should be ignored based on .gitignore patterns.""" - relative_path = str(file_path.relative_to(os.getcwd())) - - for pattern in ignored_paths: - if relative_path.startswith(pattern): # This assumes a simple matching, ignoring more complex patterns - return True - return False - -def format_file(file_path, clang_format_path): - """Apply clang-format to the file using the specified .clang-format.""" - try: - # Ensure the file path is valid and belongs to C/C++ files - if file_path.suffix.lower() in C_CPP_EXTENSIONS: - subprocess.run([clang_format_path, '-i', '-style=file', str(file_path)], check=True) - except subprocess.CalledProcessError as e: - print(f"Error formatting {file_path}: {e}") - -def traverse_and_format(root_dir, clang_format_path, ignored_paths): - """Traverse all files in the directory tree and apply clang-format.""" - for root, dirs, files in os.walk(root_dir): - # Modify dirs in-place to ignore certain directories (skip traversal in them) - dirs[:] = [d for d in dirs if not is_ignored(Path(root) / d, ignored_paths)] - - for file in files: - file_path = Path(root) / file - if is_ignored(file_path, ignored_paths): - continue # Skip files that are ignored - - clang_format_dir = find_clang_format_dir(file_path) - if clang_format_dir: - format_file(file_path, clang_format_path) + cmd += ["-i"] + return cmd + filenames + + +def format_files(args, files): + if len(files) == 0: + print("No C files to format.") + sys.exit(0) + cmd = build_command(args.clang_format, args.check, files, args.verbose) + r = subprocess.run(cmd, check=False) + sys.exit(r.returncode) + + +def get_file(args): + filename = args.file + if should_scan(filename) and not skip(filename): + return [filename] + + return [] + + +def get_files(args): + if args.diff: + return get_edited_files(args) + + if args.file: + return get_file(args) + + return get_matching_files() + + +def process(args): + files = get_files(args) + format_files(args, list(files)) + + +def parse(): + parser = argparse.ArgumentParser(description="Clang format the rizin project") + + parser.add_argument( + "-C", "--clang-format", default="clang-format", help="path of clang-format" + ) + parser.add_argument( + "-c", "--check", action="store_true", help="enable the check mode" + ) + parser.add_argument( + "-v", "--verbose", action="store_true", help="use verbose output" + ) + parser.add_argument("-f", "--file", help="formats (or checks) only the given file") + parser.add_argument( + "-d", + "--diff", + type=str, + default=None, + help="format all modified file related to branch", + ) + return parser.parse_args() + + +def main(): + args = parse() + process(args) + if __name__ == "__main__": - # Find the clang-format executable - clang_format_path = find_clang_format() - - # Get the current working directory (the directory from which the script is executed) - root_directory = os.getcwd() - - # Parse the .gitignore file - ignored_paths = parse_gitignore(root_directory) - - # Traverse the project directory and format files - traverse_and_format(root_directory, clang_format_path, ignored_paths) + main() \ No newline at end of file diff --git a/Source/Misra/Std/Container/List.c b/Source/Misra/Std/Container/List.c index ac5e98a..c6be8ea 100644 --- a/Source/Misra/Std/Container/List.c +++ b/Source/Misra/Std/Container/List.c @@ -215,7 +215,7 @@ void push_arr_list(GenericList *list, u64 item_size, void *arr, u64 count) { LOG_FATAL("invalid arguments."); } - if(!count) { + if (!count) { return; } @@ -224,11 +224,11 @@ void push_arr_list(GenericList *list, u64 item_size, void *arr, u64 count) { while (count--) { GenericListNode *old_tail = list->tail; GenericListNode *new_tail = malloc(sizeof(GenericListNode)); - + if (!new_tail) { LOG_FATAL("Failed to allocate memory for new node"); } - + new_tail->data = malloc(item_size); if (!new_tail->data) { free(new_tail); @@ -242,12 +242,12 @@ void push_arr_list(GenericList *list, u64 item_size, void *arr, u64 count) { new_tail->prev = old_tail; } else { // List is empty - set as head - list->head = new_tail; + list->head = new_tail; new_tail->prev = NULL; } new_tail->next = NULL; - list->tail = new_tail; + list->tail = new_tail; // insert data if (list->copy_init) {