Commit 7f939798 authored by Andrew Morton's avatar Andrew Morton Committed by Paul Mackerras

[PATCH] printk size_t qualifier confusion

My printf manpage says:

       z      A  following  integer  conversion  corresponds to a
              size_t or ssize_t argument. (Linux libc5 has Z with
              this meaning. Don't use it.)

And the opengroup spec says

z Specifies that a following d , i , o , u , x , or X conversion specifier
  applies to a size_t or the corresponding signed integer type argument; or
  that a following n conversion specifier applies to a pointer to a signed
  integer type corresponding to a size_t argument.


yet our vsnprintf implementation has

				/* 'z' support added 23/7/1999 S.H.    */
				/* 'z' changed to 'Z' --davidm 1/25/99 */


I guess the path of least surprise is to support both.  gcc-3.2.1 doesn't
  seem to care.
parent 61b8dae6
......@@ -306,7 +306,8 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
/* get the conversion qualifier */
qualifier = -1;
if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L' || *fmt =='Z') {
if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L' ||
*fmt =='Z' || *fmt == 'z') {
qualifier = *fmt;
++fmt;
if (qualifier == 'l' && *fmt == 'l') {
......@@ -381,7 +382,7 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
if (qualifier == 'l') {
long * ip = va_arg(args, long *);
*ip = (str - buf);
} else if (qualifier == 'Z') {
} else if (qualifier == 'Z' || qualifier == 'z') {
size_t * ip = va_arg(args, size_t *);
*ip = (str - buf);
} else {
......@@ -432,7 +433,7 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
num = va_arg(args, unsigned long);
if (flags & SIGN)
num = (signed long) num;
} else if (qualifier == 'Z') {
} else if (qualifier == 'Z' || qualifier == 'z') {
num = va_arg(args, size_t);
} else if (qualifier == 'h') {
num = (unsigned short) va_arg(args, int);
......@@ -565,7 +566,8 @@ int vsscanf(const char * buf, const char * fmt, va_list args)
/* get conversion qualifier */
qualifier = -1;
if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L' || *fmt == 'Z') {
if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L' ||
*fmt == 'Z' || *fmt == 'z') {
qualifier = *fmt;
fmt++;
}
......@@ -680,6 +682,7 @@ int vsscanf(const char * buf, const char * fmt, va_list args)
}
break;
case 'Z':
case 'z':
{
size_t *s = (size_t*) va_arg(args,size_t*);
*s = (size_t) simple_strtoul(str,&next,base);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment