Verified Commit 67126748 authored by A. Wilcox's avatar A. Wilcox

string: check NULL before using variables everywhere

parent 12ecdf5c
......@@ -145,11 +145,13 @@ char *__stpncpy_chk(char *dest, const char *src, size_t n, size_t destlen)
*/
char *__strcat_chk(char *dest, const char *src, size_t destlen)
{
size_t n = strlen(src) + 1;
size_t total = strnlen(dest, destlen) + n;
size_t n;
size_t total;
assert(dest != NULL);
assert(src != NULL);
n = strlen(src) + 1;
total = strnlen(dest, destlen) + n;
assert(destlen >= total);
if (dest < src) {
assert(dest + total <= src);
......@@ -215,10 +217,11 @@ char *__strdup(const char *string)
*/
char *__strncat_chk(char *dest, const char *src, size_t n, size_t destlen)
{
size_t total = strnlen(dest, destlen) + n + 1;
size_t total;
assert(dest != NULL);
assert(src != NULL);
total = strnlen(dest, destlen) + n + 1;
assert(destlen >= total);
if (dest < src) {
assert(dest + total <= src);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment