[ https://issues.apache.org/jira/browse/THRIFT-2047?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Henrique Mendonça closed THRIFT-2047. ------------------------------------- Resolution: Fixed Fix Version/s: 0.9.1 > Thrift.Protocol.TCompactProtocol, intToZigZag data lost (TCompactProtocol.cs) > ----------------------------------------------------------------------------- > > Key: THRIFT-2047 > URL: https://issues.apache.org/jira/browse/THRIFT-2047 > Project: Thrift > Issue Type: Bug > Components: C# - Library > Affects Versions: 0.9 > Environment: Win7, amd64 > Reporter: LuHan > Priority: Critical > Labels: TCompactProtocol, intToZigZag > Fix For: 0.9.1 > > Original Estimate: 12h > Remaining Estimate: 12h > > In TCompactProtocol.cs, the function: > /** > * Convert n into a zigzag int. This allows negative numbers to be > * represented compactly as a varint. > */ > private uint intToZigZag(int n) > { > return (uint)(((uint)n << 1) ^ ((uint)n >> 31)); > } > will make wrong number while the integer is negative. Check the test code > below: (so do longToZigZag.) > =============== > using System; > using System.Collections.Generic; > using System.Linq; > using System.Text; > namespace Test > { > class Program > { > static void Main(string[] args) > { > unchecked > { > int num = -1; > if (num != zigzagToInt(intToZigZag(num))) > { > Console.WriteLine("Transform failed!"); > } > else > { > Console.WriteLine("Transform passed!"); > } > if (num != zigzagToInt(intToZigZagNew(num))) > { > Console.WriteLine("Transform failed!"); > } > else > { > Console.WriteLine("Transform passed!"); > } > Console.ReadLine(); > } > } > static int zigzagToInt(uint n) > { > return (int)(n >> 1) ^ (-(int)(n & 1)); > } > static uint intToZigZag(int n) > { > return (uint)(((uint)n << 1) ^ ((uint)n >> 31)); > } > static uint intToZigZagNew(int n) > { > return (uint)((n << 1) ^ (n >> 31)); > } > } > } -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators For more information on JIRA, see: http://www.atlassian.com/software/jira