mirror of
https://github.com/apache/nuttx.git
synced 2026-05-30 13:27:01 +08:00
sscanf() bug fixes from David Sidrane
This commit is contained in:
+18
-4
@@ -51,11 +51,19 @@
|
|||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Definitions
|
* Pre-processor Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#define MAXLN 128
|
#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
|
* 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 */
|
/* 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) */
|
/* Copy the string (if we are making an assignment) */
|
||||||
|
|
||||||
if (!noassign)
|
if (!noassign)
|
||||||
{
|
{
|
||||||
strncpy(tv, buf, width);
|
if (width > 0)
|
||||||
|
{
|
||||||
|
strncpy(tv, buf, width);
|
||||||
|
}
|
||||||
|
|
||||||
tv[width] = '\0';
|
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 */
|
/* 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
|
/* Copy the numeric string into a temporary working
|
||||||
|
|||||||
Reference in New Issue
Block a user