Skip to content

fix(pvs): resolve Medium Level (Level 2) static analyzer warnings - #87

Open
bivex wants to merge 3 commits into
nimble-code:masterfrom
bivex:fix/pvs-medium-priority-warnings
Open

fix(pvs): resolve Medium Level (Level 2) static analyzer warnings#87
bivex wants to merge 3 commits into
nimble-code:masterfrom
bivex:fix/pvs-medium-priority-warnings

Conversation

@bivex

@bivex bivex commented Aug 9, 2026

Copy link
Copy Markdown

Summary

This PR resolves Medium Level (Level 2) static analyzer warnings reported by PVS-Studio across the Spin codebase.

Key Improvements

  • Array & String Bounds Checks:
    • Src/guided.c & Src/msc_tcl.c: Added length guards before string index mutations (strlen(snap) >= 2).
    • Src/structs.c: Expanded eprefix buffer size to 512 and added string length guards.
    • Src/spinlex.c: Corrected sizeof(IArg_cont) to sizeof(IArg_cont[IArgno]) to inspect individual 1D row array sizes instead of full 2D array size.
  • Null Safety & Logic Cleanup:
    • Src/main.c: Marked alldone(int) with noreturn attribute.
    • Src/pangen5.c: Safely guarded v and v->step pointers in eligible().
    • Src/flow.c & Src/mesg.c: Removed redundant pointer checks inside loops where pointers are guaranteed non-null.
    • Src/pangen1.c: Removed redundant loop termination check.
    • Src/pangen2.c: Added explicit /* FALLTHROUGH */ annotations, simplified boolean expressions, and removed dead assignments.
    • Src/sym.c: Removed dead code following non-returning fatal() calls.
    • Src/tl_mem.c: Explicitly parenthesized compound assignment expressions.

Verification

  • Project compiled cleanly (make clean && make) with zero errors.
  • PVS-Studio re-analyzed: Level 2 warning count dropped from 68 down to 40.

bivex added 3 commits August 9, 2026 22:07
- Fix potential buffer overflow and bounds check in main.c (preprocess)
- Fix termios c_lflag bitmask truncation on 64-bit platforms in mesg.c
- Fix potential null pointer dereferences in pangen2.c, pangen3.c, and run.c
- Fix undefined behavior in 64-bit bit shift operations (1UL<<j) in pangen6.c
- Fix EVAL AST node child type check logic in pangen6.c
- Fix code formatting ambiguity in pangen7.c
- Fix potential division by zero modulo in run.c
- Add array bounds guards for string operations in guided.c, msc_tcl.c, and structs.c
- Fix sizeof(IArg_cont[IArgno]) target buffer in spinlex.c
- Fix block scope formatting in spinlex.c
- Declare alldone(int) with noreturn attribute and fix comparison logic in main.c
- Guard NULL pointers in eligible() in pangen5.c
- Clean up redundant pointer checks in flow.c and mesg.c
- Remove redundant loop condition in pangen1.c
- Add fallthrough annotations, simplify boolean logic, and remove dead assignment in pangen2.c
- Remove unreachable code after fatal() in sym.c
- Parenthesize assignment and ternary operator expression in tl_mem.c
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