diff --git a/libc/stdio/lib_sscanf.c b/libc/stdio/lib_sscanf.c
index a4802b2c5d8b56e237f80d40ac55f19edc39694e..611a0edc0c30dede07b0f20bc59e690988ab58f1 100644
--- a/libc/stdio/lib_sscanf.c
+++ b/libc/stdio/lib_sscanf.c
@@ -405,6 +405,10 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
 
               if (*buf)
                 {
+                  FAR char *endptr;
+                  int       errsave;
+                  long      tmplong;
+
                   /* Skip over any white space before the integer string */
 
                   while (isspace(*buf))
@@ -459,35 +463,32 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
                   lvdbg("vsscanf: tmp[]=\"%s\"\n", tmp);
 
                   /* Perform the integer conversion */
+                  /* Preserve the errno value */
 
-                  buf += width;
-                  if (!noassign)
+                  errsave = get_errno();
+                  set_errno(0);
+                  if (sign)
                     {
-                      FAR char *endptr;
-                      int       errsave;
-                      long      tmplong;
-
-                      /* Preserve the errno value */
+                      tmplong = strtol(tmp, &endptr, base);
+                    }
+                  else
+                    {
+                      tmplong = strtoul(tmp, &endptr, base);
+                    }
 
-                      errsave = get_errno();
-                      set_errno(0);
-                      if (sign)
-                        {
-                          tmplong = strtol(tmp, &endptr, base);
-                        }
-                      else
-                        {
-                          tmplong = strtoul(tmp, &endptr, base);
-                        }
+                  /* Check if the number was successfully converted */
 
-                      /* Check if the number was successfully converted */
+                  if (tmp == endptr || get_errno() == ERANGE)
+                    {
+                      return count;
+                    }
 
-                      if (tmp == endptr || get_errno() == ERANGE)
-                        {
-                          return count;
-                        }
+                  /* Move by the actual number of characters converted */
 
-                      set_errno(errsave);
+                  buf += (endptr - tmp);
+                  set_errno(errsave);
+                  if (!noassign)
+                    {
 
                       /* We have to check whether we need to return a long
                        * or an int.