ugorji / go

idiomatic codec and rpc lib for msgpack, cbor, json, etc. msgpack.org[Go]
MIT License
1.87k stars 295 forks source link

msgpack: SignedInteger broken #117

Closed methane closed 9 years ago

methane commented 9 years ago

Input:

package main

import (
    "fmt"
    "github.com/ugorji/go/codec"
)

func main() {
    h := codec.MsgpackHandle{}
    h.BasicHandle.SignedInteger = true
    data := []byte{0xcc, 0x05}
    dec := codec.NewDecoderBytes(data, &h)
    var x interface{}
    dec.MustDecode(&x)
    fmt.Printf("%T %#v\n", x, x)
}

expect: int64 5

actual: int64 2

methane commented 9 years ago

https://github.com/ugorji/go/blob/master/codec/msgpack.go#L375-L378

    if n.v == valueTypeUint && d.h.SignedInteger {
        n.v = valueTypeInt
        n.i = int64(n.v)
    }

The third line should be n.i = int64(n.u).

ugorji commented 9 years ago

Damn!!!!! That's terrible. Let me get on it once I get off work. Or if u send a pull request, will accept right away.