printf: make sure %x are treated unsigned
When using %x, the number must be treated as unsigned as otherwise it would get sign-extended on for example 64bit machines and do wrong output. This problem showed when doing printf("%08x", 0xffeeddcc) on a 64bit host.
This commit is contained in:
parent
d3d5c4a40e
commit
cb1aa8b0e3
@ -380,11 +380,11 @@ static long dprintf_Pass1(const char *format, va_stack_t *vto, char **endpos,
|
|||||||
break;
|
break;
|
||||||
case 'x':
|
case 'x':
|
||||||
vto[i].type = FORMAT_INT;
|
vto[i].type = FORMAT_INT;
|
||||||
flags |= FLAGS_HEX;
|
flags |= FLAGS_HEX|FLAGS_UNSIGNED;
|
||||||
break;
|
break;
|
||||||
case 'X':
|
case 'X':
|
||||||
vto[i].type = FORMAT_INT;
|
vto[i].type = FORMAT_INT;
|
||||||
flags |= FLAGS_HEX|FLAGS_UPPER;
|
flags |= FLAGS_HEX|FLAGS_UPPER|FLAGS_UNSIGNED;
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
vto[i].type = FORMAT_INT;
|
vto[i].type = FORMAT_INT;
|
||||||
@ -633,23 +633,23 @@ static int dprintf_formatf(
|
|||||||
OUTCHAR(' ');
|
OUTCHAR(' ');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(p->flags & FLAGS_UNSIGNED) {
|
|
||||||
/* Decimal unsigned integer. */
|
|
||||||
base = 10;
|
|
||||||
goto unsigned_number;
|
|
||||||
}
|
|
||||||
if(p->flags & FLAGS_OCTAL) {
|
if(p->flags & FLAGS_OCTAL) {
|
||||||
/* Octal unsigned integer. */
|
/* Octal unsigned integer. */
|
||||||
base = 8;
|
base = 8;
|
||||||
goto unsigned_number;
|
goto unsigned_number;
|
||||||
}
|
}
|
||||||
if(p->flags & FLAGS_HEX) {
|
else if(p->flags & FLAGS_HEX) {
|
||||||
/* Hexadecimal unsigned integer. */
|
/* Hexadecimal unsigned integer. */
|
||||||
|
|
||||||
digits = (p->flags & FLAGS_UPPER)? upper_digits : lower_digits;
|
digits = (p->flags & FLAGS_UPPER)? upper_digits : lower_digits;
|
||||||
base = 16;
|
base = 16;
|
||||||
goto unsigned_number;
|
goto unsigned_number;
|
||||||
}
|
}
|
||||||
|
else if(p->flags & FLAGS_UNSIGNED) {
|
||||||
|
/* Decimal unsigned integer. */
|
||||||
|
base = 10;
|
||||||
|
goto unsigned_number;
|
||||||
|
}
|
||||||
|
|
||||||
/* Decimal integer. */
|
/* Decimal integer. */
|
||||||
base = 10;
|
base = 10;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user