The second assert in _upb_EncodeRoundTripFloat is raised if val is a nan. This fix just returns the output of first spnprintf. I am not sure how changes to this repo are made so feel free to ignore this CL. To test this, you could 1. Define a proto with a float field message Test { float val = 1; } 2. In a python script, import the library and then set the val to nan and try to print it. proto = Test(val=float('nan')) print(proto) This will cause a coredump due to assertion error: assert.h assertion failed at third_party/upb/upb/lex/round_trip.c:46 in void _upb_EncodeRoundTripFloat(float, char *, size_t): strtof(buf, NULL) == val Added the corresponding change to double too PiperOrigin-RevId: 637127851pull/16941/head
parent
ee98ba2c18
commit
f65108072b
4 changed files with 65 additions and 0 deletions
@ -0,0 +1,35 @@ |
||||
#include "upb/lex/round_trip.h" |
||||
|
||||
#include <math.h> |
||||
|
||||
#include <gtest/gtest.h> |
||||
|
||||
namespace { |
||||
|
||||
TEST(RoundTripTest, Double) { |
||||
char buf[32]; |
||||
|
||||
_upb_EncodeRoundTripDouble(0.123456789, buf, sizeof(buf)); |
||||
EXPECT_STREQ(buf, "0.123456789"); |
||||
|
||||
_upb_EncodeRoundTripDouble(0.0, buf, sizeof(buf)); |
||||
EXPECT_STREQ(buf, "0"); |
||||
|
||||
_upb_EncodeRoundTripDouble(nan(""), buf, sizeof(buf)); |
||||
EXPECT_STREQ(buf, "nan"); |
||||
} |
||||
|
||||
TEST(RoundTripTest, Float) { |
||||
char buf[32]; |
||||
|
||||
_upb_EncodeRoundTripFloat(0.123456, buf, sizeof(buf)); |
||||
EXPECT_STREQ(buf, "0.123456"); |
||||
|
||||
_upb_EncodeRoundTripFloat(0.0, buf, sizeof(buf)); |
||||
EXPECT_STREQ(buf, "0"); |
||||
|
||||
_upb_EncodeRoundTripFloat(nan(""), buf, sizeof(buf)); |
||||
EXPECT_STREQ(buf, "nan"); |
||||
} |
||||
|
||||
} // namespace
|
Loading…
Reference in new issue