mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-09-07 20:08:13 +00:00
Fixed printf formatting for "%p" and added a unit test to check it
This commit is contained in:
@@ -1774,6 +1774,20 @@ static size_t SDL_PrintFloat(char *text, size_t maxlen, SDL_FormatInfo *info, do
|
||||
return length;
|
||||
}
|
||||
|
||||
static size_t SDL_PrintPointer(char *text, size_t maxlen, SDL_FormatInfo *info, const void *value)
|
||||
{
|
||||
char num[130];
|
||||
size_t length;
|
||||
|
||||
if (!value) {
|
||||
return SDL_PrintString(text, maxlen, info, NULL);
|
||||
}
|
||||
|
||||
SDL_ulltoa((unsigned long long)(uintptr_t)value, num, 16);
|
||||
length = SDL_PrintString(text, maxlen, info, "0x");
|
||||
return length + SDL_PrintString(TEXT_AND_LEN_ARGS, info, num);
|
||||
}
|
||||
|
||||
/* NOLINTNEXTLINE(readability-non-const-parameter) */
|
||||
int SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, va_list ap)
|
||||
{
|
||||
@@ -1906,6 +1920,9 @@ int SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *f
|
||||
done = SDL_TRUE;
|
||||
break;
|
||||
case 'p':
|
||||
info.force_case = SDL_CASE_LOWER;
|
||||
length += SDL_PrintPointer(TEXT_AND_LEN_ARGS, &info, va_arg(ap, void *));
|
||||
break;
|
||||
case 'x':
|
||||
info.force_case = SDL_CASE_LOWER;
|
||||
SDL_FALLTHROUGH;
|
||||
|
Reference in New Issue
Block a user