Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
LSH
lsh
Commits
8a0cc32f
Commit
8a0cc32f
authored
Oct 02, 2014
by
Niels Möller
Browse files
Fixed bugs in replacement strndup, spotted by Avner BenHanoch.
parent
59f8d39f
Changes
2
Hide whitespace changes
Inline
Side-by-side
argp/ChangeLog
View file @
8a0cc32f
2014-10-02 Niels Möller <nisse@lysator.liu.se>
* strndup.c (strndup): Fixed off-by-one error, and failure check.
Spotted by Avner BenHanoch.
2008-08-26 Niels Möller <nisse@lysator.liu.se>
* testsuite/Makefile.in (tags): Put TAGS file in the source
...
...
argp/strndup.c
View file @
8a0cc32f
...
...
@@ -17,15 +17,15 @@ strndup (const char *s, size_t size)
char
*
end
=
memchr
(
s
,
0
,
size
);
if
(
end
)
/*
Length + 1
*/
size
=
end
-
s
+
1
;
/*
strlen, i.e., excluding the terminating NUL.
*/
size
=
end
-
s
;
r
=
malloc
(
size
);
r
=
malloc
(
size
+
1
);
if
(
size
)
if
(
r
)
{
memcpy
(
r
,
s
,
size
-
1
);
r
[
size
-
1
]
=
'\0'
;
memcpy
(
r
,
s
,
size
);
r
[
size
]
=
'\0'
;
}
return
r
;
}
Niels Möller
@nisse
mentioned in commit b782b3
·
Oct 06, 2014
mentioned in commit b782b3
mentioned in commit b782b3
Toggle commit list
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment