Thanks a lot for tracking this down. For reference, here it is in our bug 
tracker: https://github.com/google/protobuf/issues/1243

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 
> <https://connect.microsoft.com/VisualStudio/feedback/details/2332293/vc-ternary-conditional-operator-optimization-bug>),
>  
> 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 protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to