提交 4d8a743c 编写于 作者: L Linus Torvalds

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: NLinus Torvalds <torvalds@linux-foundation.org>
上级 78a8bf69
...@@ -511,7 +511,14 @@ static char *string(char *buf, char *end, char *s, int field_width, int precisio ...@@ -511,7 +511,14 @@ static char *string(char *buf, char *end, char *s, int field_width, int precisio
return buf; return buf;
} }
static char *pointer(char *buf, char *end, void *ptr, int field_width, int precision, int flags) /*
* Show a '%p' thing. A kernel extension is that the '%p' is followed
* by an extra set of alphanumeric characters that are extended format
* specifiers.
*
* Right now don't actually handle any such, but we will..
*/
static char *pointer(const char *fmt, char *buf, char *end, void *ptr, int field_width, int precision, int flags)
{ {
flags |= SMALL; flags |= SMALL;
if (field_width == -1) { if (field_width == -1) {
...@@ -663,7 +670,12 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) ...@@ -663,7 +670,12 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
continue; continue;
case 'p': case 'p':
str = pointer(str, end, va_arg(args, void *), field_width, precision, flags); str = pointer(fmt+1, str, end,
va_arg(args, void *),
field_width, precision, flags);
/* Skip all alphanumeric pointer suffixes */
while (isalnum(fmt[1]))
fmt++;
continue; continue;
case 'n': case 'n':
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册