mirror of
https://github.com/X11Libre/xserver.git
synced 2026-09-24 20:55:49 +00:00
os: support pnprintf length modifiers for integers
Mainly for %ld, smaller than int is propagated anyway, and %lld isn't really used. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Keith Packard <keithp@keithp.com>
This commit is contained in:
parent
d3d4af5f9e
commit
5ea21560dd
2 changed files with 155 additions and 13 deletions
|
|
@ -158,6 +158,8 @@ static void logging_format(void)
|
|||
char buf[1024];
|
||||
int i;
|
||||
unsigned int ui;
|
||||
long li;
|
||||
unsigned long lui;
|
||||
FILE *f;
|
||||
char read_buf[2048];
|
||||
char *logmsg;
|
||||
|
|
@ -207,6 +209,14 @@ static void logging_format(void)
|
|||
LogMessageVerbSigSafe(X_ERROR, -1, "\n");
|
||||
fseek(f, 0, SEEK_END);
|
||||
|
||||
#warning Ignore compiler warning below "unknown conversion type character". This is intentional.
|
||||
/* %hld is bogus */
|
||||
LogMessageVerbSigSafe(X_ERROR, -1, "%hld\n", 4);
|
||||
read_log_msg(logmsg);
|
||||
assert(strstr(logmsg, "BUG") != NULL);
|
||||
LogMessageVerbSigSafe(X_ERROR, -1, "\n");
|
||||
fseek(f, 0, SEEK_END);
|
||||
|
||||
/* number substitution */
|
||||
ui = 0;
|
||||
do {
|
||||
|
|
@ -215,12 +225,47 @@ static void logging_format(void)
|
|||
LogMessageVerbSigSafe(X_ERROR, -1, "%u\n", ui);
|
||||
read_log_msg(logmsg);
|
||||
assert(strcmp(logmsg, expected) == 0);
|
||||
|
||||
sprintf(expected, "(EE) %x\n", ui);
|
||||
LogMessageVerbSigSafe(X_ERROR, -1, "%x\n", ui);
|
||||
read_log_msg(logmsg);
|
||||
assert(strcmp(logmsg, expected) == 0);
|
||||
|
||||
if (ui == 0)
|
||||
ui = 1;
|
||||
else
|
||||
ui <<= 1;
|
||||
} while(ui);
|
||||
|
||||
lui = 0;
|
||||
do {
|
||||
char expected[30];
|
||||
sprintf(expected, "(EE) %lu\n", lui);
|
||||
LogMessageVerbSigSafe(X_ERROR, -1, "%lu\n", lui);
|
||||
read_log_msg(logmsg);
|
||||
|
||||
sprintf(expected, "(EE) %lld\n", (unsigned long long)ui);
|
||||
LogMessageVerbSigSafe(X_ERROR, -1, "%lld\n", (unsigned long long)ui);
|
||||
read_log_msg(logmsg);
|
||||
assert(strcmp(logmsg, expected) == 0);
|
||||
|
||||
sprintf(expected, "(EE) %lx\n", lui);
|
||||
printf("%s\n", expected);
|
||||
LogMessageVerbSigSafe(X_ERROR, -1, "%lx\n", lui);
|
||||
read_log_msg(logmsg);
|
||||
assert(strcmp(logmsg, expected) == 0);
|
||||
|
||||
sprintf(expected, "(EE) %llx\n", (unsigned long long)ui);
|
||||
LogMessageVerbSigSafe(X_ERROR, -1, "%llx\n", (unsigned long long)ui);
|
||||
read_log_msg(logmsg);
|
||||
assert(strcmp(logmsg, expected) == 0);
|
||||
|
||||
if (lui == 0)
|
||||
lui = 1;
|
||||
else
|
||||
lui <<= 1;
|
||||
} while(lui);
|
||||
|
||||
/* signed number substitution */
|
||||
i = 0;
|
||||
do {
|
||||
|
|
@ -230,7 +275,6 @@ static void logging_format(void)
|
|||
read_log_msg(logmsg);
|
||||
assert(strcmp(logmsg, expected) == 0);
|
||||
|
||||
|
||||
sprintf(expected, "(EE) %d\n", i | INT_MIN);
|
||||
LogMessageVerbSigSafe(X_ERROR, -1, "%d\n", i | INT_MIN);
|
||||
read_log_msg(logmsg);
|
||||
|
|
@ -242,19 +286,35 @@ static void logging_format(void)
|
|||
i <<= 1;
|
||||
} while(i > INT_MIN);
|
||||
|
||||
/* hex number substitution */
|
||||
ui = 0;
|
||||
li = 0;
|
||||
do {
|
||||
char expected[30];
|
||||
sprintf(expected, "(EE) %x\n", ui);
|
||||
LogMessageVerbSigSafe(X_ERROR, -1, "%x\n", ui);
|
||||
sprintf(expected, "(EE) %ld\n", li);
|
||||
LogMessageVerbSigSafe(X_ERROR, -1, "%ld\n", li);
|
||||
read_log_msg(logmsg);
|
||||
assert(strcmp(logmsg, expected) == 0);
|
||||
if (ui == 0)
|
||||
ui = 1;
|
||||
|
||||
sprintf(expected, "(EE) %ld\n", li | LONG_MIN);
|
||||
LogMessageVerbSigSafe(X_ERROR, -1, "%ld\n", li | LONG_MIN);
|
||||
read_log_msg(logmsg);
|
||||
assert(strcmp(logmsg, expected) == 0);
|
||||
|
||||
sprintf(expected, "(EE) %lld\n", (long long)li);
|
||||
LogMessageVerbSigSafe(X_ERROR, -1, "%lld\n", (long long)li);
|
||||
read_log_msg(logmsg);
|
||||
assert(strcmp(logmsg, expected) == 0);
|
||||
|
||||
sprintf(expected, "(EE) %lld\n", (long long)(li | LONG_MIN));
|
||||
LogMessageVerbSigSafe(X_ERROR, -1, "%lld\n", (long long)(li | LONG_MIN));
|
||||
read_log_msg(logmsg);
|
||||
assert(strcmp(logmsg, expected) == 0);
|
||||
|
||||
if (li == 0)
|
||||
li = 1;
|
||||
else
|
||||
ui <<= 1;
|
||||
} while(ui);
|
||||
li <<= 1;
|
||||
} while(li > LONG_MIN);
|
||||
|
||||
|
||||
/* pointer substitution */
|
||||
/* we print a null-pointer differently to printf */
|
||||
|
|
|
|||
Loading…
Reference in a new issue