Bug 1690167 - Add support for the hh length modifier in Printf.cpp. r=nika,Gankra

Test cases from TestIntegerPrintfMacros will cover this in the next commit.

Differential Revision: https://phabricator.services.mozilla.com/D103729
This commit is contained in:
Mike Hommey 2021-02-12 20:21:49 +00:00
Родитель 6c2fd9938a
Коммит 8207cffcad
1 изменённых файлов: 25 добавлений и 1 удалений

Просмотреть файл

@ -70,6 +70,8 @@ using NumArgStateVector =
#if defined(XP_WIN) #if defined(XP_WIN)
# define TYPE_WSTRING 12 # define TYPE_WSTRING 12
#endif #endif
#define TYPE_SCHAR 14
#define TYPE_UCHAR 15
#define TYPE_UNKNOWN 20 #define TYPE_UNKNOWN 20
#define FLAG_LEFT 0x1 #define FLAG_LEFT 0x1
@ -534,6 +536,10 @@ static bool BuildArgArray(const char* fmt, va_list ap, NumArgStateVector& nas) {
if (c == 'h') { if (c == 'h') {
nas[cn].type = TYPE_SHORT; nas[cn].type = TYPE_SHORT;
c = *p++; c = *p++;
if (c == 'h') {
nas[cn].type = TYPE_SCHAR;
c = *p++;
}
} else if (c == 'L') { } else if (c == 'L') {
nas[cn].type = TYPE_LONGLONG; nas[cn].type = TYPE_LONGLONG;
c = *p++; c = *p++;
@ -642,6 +648,8 @@ static bool BuildArgArray(const char* fmt, va_list ap, NumArgStateVector& nas) {
VARARGS_ASSIGN(nas[cn].ap, ap); VARARGS_ASSIGN(nas[cn].ap, ap);
switch (nas[cn].type) { switch (nas[cn].type) {
case TYPE_SCHAR:
case TYPE_UCHAR:
case TYPE_SHORT: case TYPE_SHORT:
case TYPE_USHORT: case TYPE_USHORT:
case TYPE_INTN: case TYPE_INTN:
@ -821,6 +829,10 @@ bool mozilla::PrintfTarget::vprint(const char* fmt, va_list ap) {
if (c == 'h') { if (c == 'h') {
type = TYPE_SHORT; type = TYPE_SHORT;
c = *fmt++; c = *fmt++;
if (c == 'h') {
type = TYPE_SCHAR;
c = *fmt++;
}
} else if (c == 'L') { } else if (c == 'L') {
type = TYPE_LONGLONG; type = TYPE_LONGLONG;
c = *fmt++; c = *fmt++;
@ -882,8 +894,18 @@ bool mozilla::PrintfTarget::vprint(const char* fmt, va_list ap) {
fetch_and_convert: fetch_and_convert:
switch (type) { switch (type) {
case TYPE_SCHAR:
u.l = (signed char)va_arg(ap, int);
if (u.l < 0) {
u.l = -u.l;
flags |= FLAG_NEG;
}
goto do_long;
case TYPE_UCHAR:
u.l = (unsigned char)va_arg(ap, unsigned int);
goto do_long;
case TYPE_SHORT: case TYPE_SHORT:
u.l = va_arg(ap, int); u.l = (short)va_arg(ap, int);
if (u.l < 0) { if (u.l < 0) {
u.l = -u.l; u.l = -u.l;
flags |= FLAG_NEG; flags |= FLAG_NEG;
@ -1069,6 +1091,8 @@ bool mozilla::PrintfTarget::print(const char* format, ...) {
#undef TYPE_POINTER #undef TYPE_POINTER
#undef TYPE_WSTRING #undef TYPE_WSTRING
#undef TYPE_UNKNOWN #undef TYPE_UNKNOWN
#undef TYPE_SCHAR
#undef TYPE_UCHAR
#undef FLAG_LEFT #undef FLAG_LEFT
#undef FLAG_SIGNED #undef FLAG_SIGNED