From: Fletcher T. Penney Date: Sat, 23 Sep 2017 01:09:42 +0000 (-0400) Subject: FIXED: Add NULL check on my strdup functions X-Git-Tag: 6.2.2^2~4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=02c83e83fd9e6101e96c9b4c5c97d58918877e28;p=multimarkdown FIXED: Add NULL check on my strdup functions --- diff --git a/Sources/libMultiMarkdown/epub.c b/Sources/libMultiMarkdown/epub.c index 495eb22..d878599 100644 --- a/Sources/libMultiMarkdown/epub.c +++ b/Sources/libMultiMarkdown/epub.c @@ -81,6 +81,10 @@ /// strdup() not available on all platforms static char * my_strdup(const char * source) { + if (source == NULL) { + return NULL; + } + char * result = malloc(strlen(source) + 1); if (result) { diff --git a/Sources/libMultiMarkdown/fodt.c b/Sources/libMultiMarkdown/fodt.c index ebfd32f..5158174 100644 --- a/Sources/libMultiMarkdown/fodt.c +++ b/Sources/libMultiMarkdown/fodt.c @@ -76,6 +76,10 @@ /// strdup() not available on all platforms static char * my_strdup(const char * source) { + if (source == NULL) { + return NULL; + } + char * result = malloc(strlen(source) + 1); if (result) { diff --git a/Sources/libMultiMarkdown/html.c b/Sources/libMultiMarkdown/html.c index 740dd43..156f333 100644 --- a/Sources/libMultiMarkdown/html.c +++ b/Sources/libMultiMarkdown/html.c @@ -78,6 +78,10 @@ /// strdup() not available on all platforms static char * my_strdup(const char * source) { + if (source == NULL) { + return NULL; + } + char * result = malloc(strlen(source) + 1); if (result) { diff --git a/Sources/libMultiMarkdown/latex.c b/Sources/libMultiMarkdown/latex.c index 3858d64..6b31942 100644 --- a/Sources/libMultiMarkdown/latex.c +++ b/Sources/libMultiMarkdown/latex.c @@ -73,6 +73,10 @@ /// strdup() not available on all platforms static char * my_strdup(const char * source) { + if (source == NULL) { + return NULL; + } + char * result = malloc(strlen(source) + 1); if (result) { diff --git a/Sources/libMultiMarkdown/mmd.c b/Sources/libMultiMarkdown/mmd.c index 830d615..c1e8259 100644 --- a/Sources/libMultiMarkdown/mmd.c +++ b/Sources/libMultiMarkdown/mmd.c @@ -86,6 +86,10 @@ void mmd_pair_tokens_in_block(token * block, token_pair_engine * e, stack * s); /// strdup() not available on all platforms static char * my_strdup(const char * source) { + if (source == NULL) { + return NULL; + } + char * result = malloc(strlen(source) + 1); if (result) { diff --git a/Sources/libMultiMarkdown/opendocument-content.c b/Sources/libMultiMarkdown/opendocument-content.c index 595fb45..467c630 100644 --- a/Sources/libMultiMarkdown/opendocument-content.c +++ b/Sources/libMultiMarkdown/opendocument-content.c @@ -122,6 +122,10 @@ /// strdup() not available on all platforms static char * my_strdup(const char * source) { + if (source == NULL) { + return NULL; + } + char * result = malloc(strlen(source) + 1); if (result) { diff --git a/Sources/libMultiMarkdown/opendocument.c b/Sources/libMultiMarkdown/opendocument.c index 49ad763..5ea74af 100644 --- a/Sources/libMultiMarkdown/opendocument.c +++ b/Sources/libMultiMarkdown/opendocument.c @@ -122,6 +122,10 @@ /// strdup() not available on all platforms static char * my_strdup(const char * source) { + if (source == NULL) { + return NULL; + } + char * result = malloc(strlen(source) + 1); if (result) { diff --git a/Sources/libMultiMarkdown/transclude.c b/Sources/libMultiMarkdown/transclude.c index fa473ab..8f4942f 100644 --- a/Sources/libMultiMarkdown/transclude.c +++ b/Sources/libMultiMarkdown/transclude.c @@ -68,6 +68,10 @@ /// strndup not available on all platforms static char * my_strndup(const char * source, size_t n) { + if (source == NULL) { + return NULL; + } + size_t len = 0; char * result; const char * test = source; diff --git a/Sources/libMultiMarkdown/writer.c b/Sources/libMultiMarkdown/writer.c index e6d9c55..d1087f6 100644 --- a/Sources/libMultiMarkdown/writer.c +++ b/Sources/libMultiMarkdown/writer.c @@ -91,6 +91,10 @@ void store_abbreviation(scratch_pad * scratch, footnote * a); /// strndup not available on all platforms static char * my_strndup(const char * source, size_t n) { + if (source == NULL) { + return NULL; + } + size_t len = 0; char * result; const char * test = source; @@ -117,6 +121,10 @@ static char * my_strndup(const char * source, size_t n) { /// strdup() not available on all platforms static char * my_strdup(const char * source) { + if (source == NULL) { + return NULL; + } + char * result = malloc(strlen(source) + 1); if (result) { diff --git a/Sources/multimarkdown/main.c b/Sources/multimarkdown/main.c index fe4a36a..9797ec4 100644 --- a/Sources/multimarkdown/main.c +++ b/Sources/multimarkdown/main.c @@ -84,6 +84,10 @@ struct arg_rem *a_rem1, *a_rem2, *a_rem3, *a_rem4, *a_rem5, *a_rem6; /// strdup() not available on all platforms static char * my_strdup(const char * source) { + if (source == NULL) { + return NULL; + } + char * result = malloc(strlen(source) + 1); if (result) {