Skip to content

Conversation

@No0ne558
Copy link
Contributor

@No0ne558 No0ne558 commented Jan 8, 2026

Summary

This PR fixes critical segmentation faults in the User Edit Zone when saving employee records and expands the test suite with 26 new test cases covering time operations, error handling, and sales tax calculations.

Changes

🐛 Bug Fixes

User Edit Zone - Multiple Crash Fixes (Commits: 5160ede, c259bcf)

  • Fixed SIGSEGV when saving employee records caused by NULL/dangling user pointers
  • Added user pointer validation before SaveRecord calls in Signal() and Update() methods
  • Enhanced SaveRecord field iteration with proper null checks and early breaks
  • Added dangling pointer detection to catch freed memory access
  • Improved error logging for better debugging

Root Causes Identified:

  1. SaveRecord() called without validating user pointer when toggling Active/Inactive views
  2. SaveRecord() called without validation during job filter updates
  3. Field pointer advanced without null checks in job info iteration loop

Crash Details:

  • Signal: SIGSEGV (Segmentation Fault)
  • Location: user_edit_zone.cc - UserEditZone::SaveRecord()
  • Stack: TextField::Get(int&) <- UserEditZone::SaveRecord()
  • Detection: AddressSanitizer identified access to freed memory (0xbebebebebebebebe)

✅ Testing

Test Suite Expansion (Commit: 96b0300)

  • Added test_time_operations.cc with TimeInfo class tests (time arithmetic, comparisons, business logic)
  • Added test_error_handler.cc with error management tests (severity levels, categories, context tracking)
  • Added test_sales_tax_calculations.cc with 43 test cases (US, Canadian, European VAT)
  • Fixed floating-point comparison precision issues with Catch::Approx()
  • Fixed RAII scoping issue in test_memory_modernization.cc

Test Results:

  • 80 test cases, 568 assertions
  • 100% pass rate
  • All existing functionality validated

Files Modified

  • user_edit_zone.cc (SaveRecord, Signal, Update methods)
  • changelog.md
  • test_time_operations.cc (new)
  • test_error_handler.cc (new)
  • test_sales_tax_calculations.cc (new)
  • CMakeLists.txt

Testing Performed

  • Validated with AddressSanitizer in Debug build
  • All unit tests passing (80/80)
  • Manual testing of User Edit save operations:
    • Toggle Active/Inactive employee lists
    • Job filter changes
    • Add/remove employee jobs
    • Save employee records

Impact

  • High - Fixes critical crashes affecting employee management
  • Stability - Prevents segfaults during common User Edit operations
  • Quality - Expanded test coverage for time operations and error handling

- Add test_time_operations.cc with TimeInfo class tests
  * Time arithmetic operations (seconds, minutes, days, weeks, months, years)
  * Comparison operators and date ordering
  * Business logic scenarios (shift scheduling)
  * Operator overloads and edge cases

- Add test_error_handler.cc with error management tests
  * ErrorInfo construction and severity levels
  * Error categories (9 types: GENERAL, SYSTEM, NETWORK, etc.)
  * Context tracking (file, line, function, error code)
  * Real-world error scenarios

- Add test_sales_tax_calculations.cc with 43 test cases
  * US tax calculations, Canadian GST/PST/HST/QST
  * European VAT, discounts, coupons, modifiers
  * Quantity pricing and rounding

- Fix floating-point comparison precision issues
  * Apply Catch::Approx() to all float equality checks
  * Fix RAII scoping issue in test_memory_modernization.cc

- Update CMakeLists.txt to include new test files

Test suite now contains 80 test cases with 568 assertions (100% passing)
Fixes segmentation fault (SIGSEGV) when saving employee records in the
User Edit Zone. The crash occurred during form field iteration when the
field pointer became NULL.

Root Cause:
- Loop condition checked 'f != nullptr' but immediately dereferenced
  f->next without revalidation on the first line of the loop body
- This caused a segfault when f was NULL at loop entry or became NULL
  during iteration

Changes:
- Add explicit NULL check before dereferencing f->next in job info loop
- Add early validation for user pointer and FieldList() return value
- Add error logging with ReportError() for easier debugging
- Return error code 1 instead of continuing with NULL pointers

Crash Stack Trace Reference:
  TextField::Get(int&) <- UserEditZone::SaveRecord()
  Signal: SIGSEGV at zone/user_edit_zone.cc line 440

Tested: Compiles successfully, prevents crash on employee save operation
- Fixed SIGSEGV when saving employee records caused by NULL/dangling user pointers
- Added user pointer validation before SaveRecord calls in Signal() and Update()
- Enhanced SaveRecord field iteration with proper null checks and early breaks
- Added dangling pointer detection to catch freed memory access
- Improved error logging for better debugging

Root causes:
1. SaveRecord called without validating user pointer when toggling Active/Inactive
2. SaveRecord called without validation during job filter updates
3. Field pointer advanced without null checks in job info iteration loop

Testing: Validated with AddressSanitizer in Debug build
Fixes: User Edit button type save crashes
@No0ne558 No0ne558 merged commit c829b02 into ViewTouch:dev Jan 8, 2026
1 check passed
@GeneMosher
Copy link
Member

GeneMosher commented Jan 8, 2026

It is scary (scary good !) watching you fix bugs and refactor the code. In email I get these information laden summaries every time a commit is made, even if in your 'dev' and not in 'master'; the summaries are positively overwhelming in every way. In the old days such a level of professionalism and skill was unheard of because it was simply impossible to expect such results from anyone fixing, refactoring, enhancing and testing code. Congratulations, Ariel.

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.

2 participants