Commit e346b933 authored by miloyip's avatar miloyip

Try to fix a potential set fault on some compiler

Merge the fix from https://github.com/miloyip/itoa-benchmark/issues/8
parent cb59a5a9
...@@ -109,12 +109,13 @@ inline char* u32toa(uint32_t value, char* buffer) { ...@@ -109,12 +109,13 @@ inline char* u32toa(uint32_t value, char* buffer) {
} }
inline char* i32toa(int32_t value, char* buffer) { inline char* i32toa(int32_t value, char* buffer) {
uint32_t u = static_cast<uint32_t>(value);
if (value < 0) { if (value < 0) {
*buffer++ = '-'; *buffer++ = '-';
value = -value; u = ~u + 1;
} }
return u32toa(static_cast<uint32_t>(value), buffer); return u32toa(u, buffer);
} }
inline char* u64toa(uint64_t value, char* buffer) { inline char* u64toa(uint64_t value, char* buffer) {
...@@ -286,12 +287,13 @@ inline char* u64toa(uint64_t value, char* buffer) { ...@@ -286,12 +287,13 @@ inline char* u64toa(uint64_t value, char* buffer) {
} }
inline char* i64toa(int64_t value, char* buffer) { inline char* i64toa(int64_t value, char* buffer) {
uint64_t u = static_cast<uint64_t>(value);
if (value < 0) { if (value < 0) {
*buffer++ = '-'; *buffer++ = '-';
value = -value; u = ~u + 1;
} }
return u64toa(static_cast<uint64_t>(value), buffer); return u64toa(u, buffer);
} }
} // namespace internal } // namespace internal
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment