Skip to content
Snippets Groups Projects
Commit 927ec9c7 authored by Gregory Nutt's avatar Gregory Nutt
Browse files

sscanf() bug fixes from David Sidrane

parent 662622b5
No related branches found
No related tags found
No related merge requests found
......@@ -51,11 +51,19 @@
#include <debug.h>
/****************************************************************************
* Definitions
* Pre-processor Definitions
****************************************************************************/
#define MAXLN 128
#ifndef MIN
# define MIN(a,b) (a < b ? a : b)
#endif
#ifndef MAX
# define MAX(a,b) (a > b ? a : b)
#endif
/****************************************************************************
* Private Type Declarations
****************************************************************************/
......@@ -287,14 +295,19 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
{
/* No... Guess a field width using some heuristics */
width = findwidth(buf, fmt);
int tmpwidth = findwidth(buf, fmt);
width = MIN(sizeof(tmp) - 1, tmpwidth);
}
/* Copy the string (if we are making an assignment) */
if (!noassign)
{
strncpy(tv, buf, width);
if (width > 0)
{
strncpy(tv, buf, width);
}
tv[width] = '\0';
}
......@@ -425,7 +438,8 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
{
/* No... Guess a field width using some heuristics */
width = findwidth(buf, fmt);
int tmpwidth = findwidth(buf, fmt)
width = MIN(sizeof(tmp) - 1, tmpwidth);
}
/* Copy the numeric string into a temporary working
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment