Skip to content

Conversation

@dushaoshuai
Copy link
Contributor

  • Do only one thing
  • Non breaking API changes
  • Tested

What did this pull request do?

This pull request fixes a panic caused by calling Int() on uint values in UnixSecondSerializer.Value(), and adds a corresponding unit test to ensure the serializer handles unsigned integers safely.

User Case Description

nil.

@propel-code-bot
Copy link
Contributor

propel-code-bot bot commented Oct 10, 2025

Fix Panic in UnixSecondSerializer.Value() When Handling Unsigned Integers and Add Overflow Handling

This pull request addresses a runtime panic in the UnixSecondSerializer.Value() function that previously occurred when handling unsigned integer values. The implementation now safely manages both signed and unsigned integers, explicitly checking for integer overflow when converting large unsigned values to int64 and returning an error if the value exceeds math.MaxInt64. The changes also introduce comprehensive unit tests to verify correct behavior across all integer types, pointer variants, invalid types, and corner cases such as overflow conditions and nil pointers. Updates in the test suite improve safety by handling type assertions robustly.

Key Changes

• Refactored UnixSecondSerializer.Value() in schema/serializer.go to safely handle signed and unsigned integers, including pointer types
• Added explicit integer overflow checks for unsigned integers to prevent conversion errors and potential panics
• Improved error handling for invalid field types and overflow cases
• Enhanced test coverage in schema/serializer_test.go for all integer and pointer types, nil pointers, invalid types, and overflow edge cases
• Updated imports in schema/serializer.go to include math
• Added type assertion safety checks in tests to prevent runtime panics

Affected Areas

schema/serializer.go (serializer logic for time serialization)
schema/serializer_test.go (unit test coverage for serializer behavior)

This summary was automatically generated by @propel-code-bot

@propel-code-bot propel-code-bot bot changed the title fix(UnixSecondSerializer.Value): avoid panic when calling Int() on uint values fix(UnixSecondSerializer.Value): Avoid panic when handling unsigned integer values Oct 10, 2025
dushaoshuai and others added 2 commits October 10, 2025 18:33
Co-authored-by: propel-code-bot[bot] <203372662+propel-code-bot[bot]@users.noreply.github.com>
@jinzhu jinzhu merged commit d9372f5 into go-gorm:master Oct 26, 2025
25 checks passed
@dushaoshuai dushaoshuai deleted the fix/UnixSecondSerializer_Value branch October 26, 2025 13:30
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