fix bug for mis-converting uint64 to int64 #1647

Merged
lunny merged 1 commits from rosbit/xorm:master into master 2020-04-05 04:49:51 +00:00
Contributor
  • If an uint64 value is greater than 0x7FFFFFFFFFFFFFFF(the max value of int64), the behavior is strange, sometimes a negative value will be stored in db, or an error of "value out of range" occurs.
  • In source files internal/statements/update.go, internal/statements/statement.go, internal/statements/values.go, I found there're strange convertions like this:
    if !requiredField && fieldValue.Uint() == 0 {
       continue
    }
    t := int64(fieldValue.Uint())
    val = reflect.ValueOf(&t).Interface()
    
  • I modify them, it works now.
    if !requiredField && fieldValue.Uint() == 0 {
       continue
    }
    val = fieldValue.Interface()
    
- If an uint64 value is greater than 0x7FFFFFFFFFFFFFFF(the max value of int64), the behavior is strange, sometimes a negative value will be stored in db, or an error of "value out of range" occurs. - In source files internal/statements/update.go, internal/statements/statement.go, internal/statements/values.go, I found there're strange convertions like this: ```golang if !requiredField && fieldValue.Uint() == 0 { continue } t := int64(fieldValue.Uint()) val = reflect.ValueOf(&t).Interface() ``` - I modify them, it works now. ```golang if !requiredField && fieldValue.Uint() == 0 { continue } val = fieldValue.Interface() ```
Owner

@rosbit Thanks for your contirubtion. Could you add some tests for the change?

@rosbit Thanks for your contirubtion. Could you add some tests for the change?
lunny added the
kind
bug
label 2020-04-04 07:44:18 +00:00
Author
Contributor

see issue #1325, same bug found by others months ago, which made me almost give up using xorm. The bug fix passed all the ci test. For old versions, uint64 bigger than MAX_INT64 will make it occur again and again.

see [issue #1325](https://gitea.com/xorm/xorm/issues/1325), same bug found by others months ago, which made me almost give up using xorm. The bug fix passed all the ci test. For old versions, uint64 bigger than MAX_INT64 will make it occur again and again.
lunny closed this pull request 2020-04-05 04:49:51 +00:00
Sign in to join this conversation.
No description provided.