Thanks a lot for tracking this down. For reference, here it is in our bug 

On Thursday, February 11, 2016 at 3:28:33 AM UTC-8, Ron Ben-Yosef wrote:
> Hi,
> I'm using the proto3 C++ library compiled in MSVC, and noticed some pretty 
> strange behavior - using the JsonToBinaryString or JsonToBinaryStream 
> functions, values in the upper half of the uint32 range get lost in the 
> transition from JSON to binary.
> After some investigation, it seems the issue's root cause is in the 
> MathUtil::Sign function (called from NumberConvertAndCheck, which is called 
> from DataPiece::GenericConvert, which gets called 
> from DataPiece::ToUint32...)
> When compiled in Release mode (with optimizations) it seems, the ternary 
> condition operator in that function gets optimized incorrectly (the 
> assembly code generated looks as if it's treated as int32 instead of 
> uint32), causing the Sign function to return an incorrect result in the 
> case of those larger uint32 values, which in turn causes a condition in 
> some if statement in NumberConvertAndCheck to evaluate to false when it 
> should be true, thus causing the value to be dropped.
> Now obviously this is not really a protobuf issue, but more likely a 
> compiler bug (opened an issue regarding this with Microsoft 
> <>),
> but since it's likely to be a while until the compiler issue is addressed 
> (if at all) and since protobuf does support MSVC compilers, I would suggest 
> that until then the issue should probably be handled with a workaround in 
> the protobuf code in the meantime, for instance by changing that ternary 
> condition operator to a simple if-else statement (seems to compile 
> correctly, without this issue), or simply removing optimization flags when 
> compiling with VS2010/VS2012/VS2013/VS2015, although this is probably a 
> less desirable solution.
> Thanks,
> Ron

You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
To post to this group, send email to
Visit this group at
For more options, visit

Reply via email to