Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
NuttX RTOS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
f4grx
NuttX RTOS
Commits
a0b330bd
Commit
a0b330bd
authored
11 years ago
by
Gregory Nutt
Browse files
Options
Downloads
Patches
Plain Diff
strncpy would fail if n==0
parent
f12e37ca
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
libc/stdio/lib_sscanf.c
+16
-18
16 additions, 18 deletions
libc/stdio/lib_sscanf.c
libc/string/lib_strncpy.c
+8
-4
8 additions, 4 deletions
libc/string/lib_strncpy.c
with
24 additions
and
22 deletions
libc/stdio/lib_sscanf.c
+
16
−
18
View file @
a0b330bd
...
...
@@ -72,23 +72,23 @@
* Private Function Prototypes
****************************************************************************/
/**************************************************************************
/**************************************************************************
**
* Global Function Prototypes
****************************************************************************/
int
vsscanf
(
FAR
const
char
*
buf
,
FAR
const
char
*
fmt
,
va_list
ap
);
/**************************************************************************
/**************************************************************************
**
* Global Constant Data
**************************************************************************/
**************************************************************************
**
/
/****************************************************************************
* Global Variables
****************************************************************************/
/**************************************************************************
/**************************************************************************
**
* Private Constant Data
**************************************************************************/
**************************************************************************
**
/
static
const
char
spaces
[]
=
"
\t\n\r\f\v
"
;
...
...
@@ -136,14 +136,14 @@ static int findwidth(FAR const char *buf, FAR const char *fmt)
}
}
/* No... the format has no
t
delimiter and is back-to-back with the next
* format
s
(or
no
is follow
ing
by a delimiter that does not exist in the
/* No... the format has no delimiter and is back-to-back with the next
* format (or is follow
ed
by a delimiter that does not exist in the
* input string). At this point we just bail and Use the input up until
* the first white space is encountered.
*
* NOTE: This means that values from the following format may be
* concatenated with the first. This is a bug. We have no generic way of
* determining the width of the data if there is no fieldwith, no space
* determining the width of the data if there is no fieldwi
d
th, no space
* separating the input, and no usable delimiter character.
*/
...
...
@@ -284,6 +284,8 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
if
(
*
buf
)
{
/* Skip over white space */
while
(
isspace
(
*
buf
))
{
buf
++
;
...
...
@@ -303,11 +305,7 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
if
(
!
noassign
)
{
if
(
width
>
0
)
{
strncpy
(
tv
,
buf
,
width
);
}
strncpy
(
tv
,
buf
,
width
);
tv
[
width
]
=
'\0'
;
}
...
...
@@ -456,9 +454,9 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
buf
+=
width
;
if
(
!
noassign
)
{
char
*
endptr
;
int
errsave
;
long
tmplong
;
FAR
char
*
endptr
;
int
errsave
;
long
tmplong
;
errsave
=
errno
;
set_errno
(
0
);
...
...
This diff is collapsed.
Click to expand it.
libc/string/lib_strncpy.c
+
8
−
4
View file @
a0b330bd
/************************************************************
* libc/string/lib_strncpy.c
*
* Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved.
* Copyright (C) 2007, 2011
, 2014
Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
...
...
@@ -42,16 +42,20 @@
#include
<string.h>
/************************************************************
* Global Functions
* Public Functions
************************************************************/
/************************************************************
* Name: strncpy
************************************************************/
#ifndef CONFIG_ARCH_STRNCPY
char
*
strncpy
(
char
*
dest
,
const
char
*
src
,
size_t
n
)
char
*
strncpy
(
FAR
char
*
dest
,
FAR
const
char
*
src
,
size_t
n
)
{
char
*
ret
=
dest
;
/* Value to be returned */
char
*
end
=
dest
+
n
;
/* End of dest buffer + 1 byte */
while
((
*
dest
++
=
*
src
++
)
!=
'\0'
&&
dest
!=
end
);
while
(
dest
!=
end
&&
(
*
dest
++
=
*
src
++
)
!=
'\0'
);
return
ret
;
}
#endif
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment