summaryrefslogtreecommitdiff
path: root/lib/vsprintf.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@athlon.transmeta.com>2002-02-04 20:23:54 -0800
committerLinus Torvalds <torvalds@athlon.transmeta.com>2002-02-04 20:23:54 -0800
commitad8dcf57e93e8e5f9b815e786da35ef03fc70f89 (patch)
treef3394afd32c183a41ccbc649859ad505c5e8c09c /lib/vsprintf.c
parent4c7ed1860c0d21292284fb044c465ba00ce89b7f (diff)
v2.4.12 -> v2.4.12.1
- Trond Myklebust: deadlock checking in lockd server - Tim Waugh: fix up parport wrong #define - Christoph Hellwig: i2c update, ext2 cleanup - Al Viro: fix partition handling sanity check. - Trond Myklebust: make NFS use SLAB_NOFS, and not play games with PF_MEMALLOC - Ben Fennema: UDF update - Alan Cox: continued merging - Chris Mason: get /proc buffer memory sizes right after buf-in-page-cache
Diffstat (limited to 'lib/vsprintf.c')
-rw-r--r--lib/vsprintf.c41
1 files changed, 30 insertions, 11 deletions
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 3f8e0a763698..5a0152e46a8b 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -18,6 +18,7 @@
#include <linux/types.h>
#include <linux/string.h>
#include <linux/ctype.h>
+#include <linux/kernel.h>
#include <asm/div64.h>
@@ -519,36 +520,44 @@ int vsscanf(const char * buf, const char * fmt, va_list args)
int num = 0;
int qualifier;
int base;
- unsigned int field_width;
+ int field_width = -1;
int is_sign = 0;
- for (; *fmt; fmt++) {
+ while(*fmt && *str) {
/* skip any white space in format */
+ /* white space in format matchs any amount of
+ * white space, including none, in the input.
+ */
if (isspace(*fmt)) {
- continue;
+ while (isspace(*fmt))
+ ++fmt;
+ while (isspace(*str))
+ ++str;
}
/* anything that is not a conversion must match exactly */
- if (*fmt != '%') {
+ if (*fmt != '%' && *fmt) {
if (*fmt++ != *str++)
- return num;
+ break;
continue;
}
+
+ if (!*fmt)
+ break;
++fmt;
/* skip this conversion.
* advance both strings to next white space
*/
if (*fmt == '*') {
- while (!isspace(*fmt))
+ while (!isspace(*fmt) && *fmt)
fmt++;
- while(!isspace(*str))
+ while (!isspace(*str) && *str)
str++;
continue;
}
/* get field width */
- field_width = 0xffffffffUL;
if (isdigit(*fmt))
field_width = skip_atoi(&fmt);
@@ -561,25 +570,32 @@ int vsscanf(const char * buf, const char * fmt, va_list args)
base = 10;
is_sign = 0;
- switch(*fmt) {
+ if (!*fmt || !*str)
+ break;
+
+ switch(*fmt++) {
case 'c':
{
char *s = (char *) va_arg(args,char*);
+ if (field_width == -1)
+ field_width = 1;
do {
*s++ = *str++;
- } while(field_width-- > 0);
+ } while(field_width-- > 0 && *str);
num++;
}
continue;
case 's':
{
char *s = (char *) va_arg(args, char *);
+ if(field_width == -1)
+ field_width = INT_MAX;
/* first, skip leading white space in buffer */
while (isspace(*str))
str++;
/* now copy until next white space */
- while (!isspace(*str) && field_width--) {
+ while (*str && !isspace(*str) && field_width--) {
*s++ = *str++;
}
*s = '\0';
@@ -621,6 +637,9 @@ int vsscanf(const char * buf, const char * fmt, va_list args)
while (isspace(*str))
str++;
+ if (!*str || !isdigit(*str))
+ break;
+
switch(qualifier) {
case 'h':
if (is_sign) {