projects
/
platform
/
upstream
/
toybox.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
ce8aae4
)
Change strlcpy not to use strncpy. (Adds 24 bytes, but doesn't memset the
author
Rob Landley
<rob@landley.net>
Thu, 15 Nov 2007 22:18:33 +0000
(16:18 -0600)
committer
Rob Landley
<rob@landley.net>
Thu, 15 Nov 2007 22:18:33 +0000
(16:18 -0600)
unused portion of the buffer to 0, which can touch and allocate physical
pages for a large virtual mapping.)
lib/lib.c
patch
|
blob
|
history
diff --git
a/lib/lib.c
b/lib/lib.c
index
ad84dff
..
eed7296
100644
(file)
--- a/
lib/lib.c
+++ b/
lib/lib.c
@@
-18,8
+18,12
@@
// Like strncpy but always null terminated.
void strlcpy(char *dest, char *src, size_t size)
{
- strncpy(dest,src,size);
- dest[size-1] = 0;
+ int len = strlen(src);
+ if (size--) {
+ if (len > size) len=size;
+ memcpy(dest,src, len);
+ dest[len] = 0;
+ }
}
#endif