summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2019-05-08 20:33:19 -0500
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2019-05-08 20:33:19 -0500
commit67126748f76b2417c0cdc0bd5772aac4aa1b4eb5 (patch)
tree207dbe404cc052101d9dc61bbbb4df401eb981a4
parent12ecdf5c20fcfc0ab7f597e9ebe2ce1f9bf63b1a (diff)
downloadgcompat-67126748f76b2417c0cdc0bd5772aac4aa1b4eb5.tar.gz
gcompat-67126748f76b2417c0cdc0bd5772aac4aa1b4eb5.tar.bz2
gcompat-67126748f76b2417c0cdc0bd5772aac4aa1b4eb5.tar.xz
gcompat-67126748f76b2417c0cdc0bd5772aac4aa1b4eb5.zip
string: check NULL before using variables everywhere
-rw-r--r--libgcompat/string.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/libgcompat/string.c b/libgcompat/string.c
index 1b3673b..9852bea 100644
--- a/libgcompat/string.c
+++ b/libgcompat/string.c
@@ -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);