Merge pull request #10784 from kaspar030/fix_fmt_signed_conversion

fmt: fix fmt_s32_dec() and fmt_s64_dec() sign bit handling
This commit is contained in:
Martine Lenders 2019-01-17 11:28:00 +01:00 committed by GitHub
commit aef03e620a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -265,25 +265,33 @@ size_t fmt_u16_dec(char *out, uint16_t val)
size_t fmt_s64_dec(char *out, int64_t val)
{
unsigned negative = (val < 0);
uint64_t sval;
if (negative) {
if (out) {
*out++ = '-';
}
val = -val;
sval = -(uint64_t)(val);
}
return fmt_u64_dec(out, val) + negative;
else {
sval = +(uint64_t)(val);
}
return fmt_u64_dec(out, sval) + negative;
}
size_t fmt_s32_dec(char *out, int32_t val)
{
unsigned negative = (val < 0);
uint32_t sval;
if (negative) {
if (out) {
*out++ = '-';
}
val = -val;
sval = -((uint32_t)(val));
}
return fmt_u32_dec(out, val) + negative;
else {
sval = +((uint32_t)(val));
}
return fmt_u32_dec(out, sval) + negative;
}
size_t fmt_s16_dec(char *out, int16_t val)