Change common to_string implementations to use snprintf instead of itoa
This commit is contained in:
parent
4e56cb5269
commit
1b48b5ec80
@ -172,8 +172,15 @@ public:
|
|||||||
num_char = mtl_itostr(x, str.data());
|
num_char = mtl_itostr(x, str.data());
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
itoa(x, str.data(), hex ? 16 : 10);
|
if (hex) {
|
||||||
num_char = strlen(str.data());
|
if (x > 0) {
|
||||||
|
num_char = snprintf(str.data(), str.capacity() + 1, "%#x", x);
|
||||||
|
} else {
|
||||||
|
num_char = snprintf(str.data(), str.capacity() + 1, "-%#x", -x);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
num_char = snprintf(str.data(), str.capacity() + 1, "%i", x);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
str.m_size = num_char;
|
str.m_size = num_char;
|
||||||
return str;
|
return str;
|
||||||
@ -198,8 +205,11 @@ public:
|
|||||||
num_char = mtl_utostr(x, str.data());
|
num_char = mtl_utostr(x, str.data());
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
utoa(x, str.data(), hex ? 16 : 10);
|
if (hex) {
|
||||||
num_char = strlen(str.data());
|
num_char = snprintf(str.data(), str.capacity() + 1, "%#x", x);
|
||||||
|
} else {
|
||||||
|
num_char = snprintf(str.data(), str.capacity() + 1, "%u", x);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
str.m_size = num_char;
|
str.m_size = num_char;
|
||||||
return str;
|
return str;
|
||||||
@ -243,8 +253,7 @@ public:
|
|||||||
#ifdef __ARM_ARCH_4T__
|
#ifdef __ARM_ARCH_4T__
|
||||||
num_char = mtl_utostrx(reinterpret_cast<uint32_t>(x), str.data());
|
num_char = mtl_utostrx(reinterpret_cast<uint32_t>(x), str.data());
|
||||||
#else
|
#else
|
||||||
utoa(x, str.data(), 16);
|
num_char = snprintf(str.data(), str.capacity() + 1, "%#x", x);
|
||||||
num_char = strlen(str.data());
|
|
||||||
#endif
|
#endif
|
||||||
str.m_size = num_char;
|
str.m_size = num_char;
|
||||||
return str;
|
return str;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user