Skip to content

Commit 4d8a743

Browse files
committed
vsprintf: add infrastructure support for extended '%p' specifiers
This expands the kernel '%p' handling with an arbitrary alphanumberic specifier extension string immediately following the '%p'. Right now it's just being ignored, but the next commit will start adding some specific pointer type extensions. NOTE! The reason the extension is appended to the '%p' is to allow minimal gcc type checking: gcc will still see the '%p' and will check that the argument passed in is indeed a pointer, and yet will not complain about the extended information that gcc doesn't understand about (on the other hand, it also won't actually check that the pointer type and the extension are compatible). Alphanumeric characters were chosen because there is no sane existing use for a string format with a hex pointer representation immediately followed by alphanumerics (which is what such a format string would have traditionally resulted in). Signed-off-by: Linus Torvalds <[email protected]>
1 parent 78a8bf6 commit 4d8a743

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

lib/vsprintf.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,14 @@ static char *string(char *buf, char *end, char *s, int field_width, int precisio
511511
return buf;
512512
}
513513

514-
static char *pointer(char *buf, char *end, void *ptr, int field_width, int precision, int flags)
514+
/*
515+
* Show a '%p' thing. A kernel extension is that the '%p' is followed
516+
* by an extra set of alphanumeric characters that are extended format
517+
* specifiers.
518+
*
519+
* Right now don't actually handle any such, but we will..
520+
*/
521+
static char *pointer(const char *fmt, char *buf, char *end, void *ptr, int field_width, int precision, int flags)
515522
{
516523
flags |= SMALL;
517524
if (field_width == -1) {
@@ -663,7 +670,12 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
663670
continue;
664671

665672
case 'p':
666-
str = pointer(str, end, va_arg(args, void *), field_width, precision, flags);
673+
str = pointer(fmt+1, str, end,
674+
va_arg(args, void *),
675+
field_width, precision, flags);
676+
/* Skip all alphanumeric pointer suffixes */
677+
while (isalnum(fmt[1]))
678+
fmt++;
667679
continue;
668680

669681
case 'n':

0 commit comments

Comments
 (0)