[PATCH 2/3] Add some checks for malloc() returning NULL
Tomas Dzik via ltp <[email protected]>
| Newsgroups | gmane.linux.ltp |
|---|---|
| Message-ID | <968d6e9521f63e11931bc80439e38c72903360dc.1783610933.git.tdzik@redhat.com> |
Current code in directory testcases/misc/math/float/ does not check if malloc() returns NULL. Because it was contributing factor to observed core dump I am adding these checks to make debugging failures easier. Signed-off-by: Tomas Dzik <[email protected]> --- testcases/misc/math/float/exp_log/genexp_log.c | 3 +++ testcases/misc/math/float/iperb/geniperb.c | 2 ++ testcases/misc/math/float/power/genpower.c | 3 +++ testcases/misc/math/float/trigo/gentrigo.c | 3 +++ 4 files changed, 11 insertions(+) diff --git a/testcases/misc/math/float/exp_log/genexp_log.c b/testcases/misc/math/float/exp_log/genexp_log.c index 7f26945ec..e02d0d344 100644 --- a/testcases/misc/math/float/exp_log/genexp_log.c +++ b/testcases/misc/math/float/exp_log/genexp_log.c @@ -30,6 +30,7 @@ #include <stdlib.h> #include <string.h> #include <errno.h> +#include <err.h> #include <limits.h> #include <unistd.h> #include <fcntl.h> @@ -76,6 +77,8 @@ int main(int argc, char *argv[]) bin_path = argv[1]; funct = malloc(strlen(bin_path) + MAX_FNAME_LEN); + if (funct == NULL) + err(1, "malloc failed"); sprintf(funct, "%s/genexp", bin_path); child = create_file(funct, 0); waitpid(child, NULL, 0); diff --git a/testcases/misc/math/float/iperb/geniperb.c b/testcases/misc/math/float/iperb/geniperb.c index f7bf55c84..98a6a380a 100644 --- a/testcases/misc/math/float/iperb/geniperb.c +++ b/testcases/misc/math/float/iperb/geniperb.c @@ -78,6 +78,8 @@ int main(int argc, char *argv[]) bin_path = argv[1]; funct = malloc(strlen(bin_path) + MAX_FNAME_LEN); + if (funct == NULL) + err(1, "malloc failed"); sprintf(funct, "%s/gencosh", bin_path); child = create_file(funct, 0); waitpid(child, NULL, 0); diff --git a/testcases/misc/math/float/power/genpower.c b/testcases/misc/math/float/power/genpower.c index 44f7af934..8a8f753a7 100644 --- a/testcases/misc/math/float/power/genpower.c +++ b/testcases/misc/math/float/power/genpower.c @@ -34,6 +34,7 @@ #include <unistd.h> #include <fcntl.h> #include <errno.h> +#include <err.h> #include <sys/signal.h> #include <math.h> @@ -76,6 +77,8 @@ int main(int argc, char *argv[]) bin_path = argv[1]; funct = malloc(strlen(bin_path) + MAX_FNAME_LEN); + if (funct == NULL) + err(1, "malloc failed"); sprintf(funct, "%s/genceil", bin_path); child = create_file(funct, 0); waitpid(child, NULL, 0); diff --git a/testcases/misc/math/float/trigo/gentrigo.c b/testcases/misc/math/float/trigo/gentrigo.c index 5f7e0cbc7..4908d0435 100644 --- a/testcases/misc/math/float/trigo/gentrigo.c +++ b/testcases/misc/math/float/trigo/gentrigo.c @@ -34,6 +34,7 @@ #include <unistd.h> #include <fcntl.h> #include <errno.h> +#include <err.h> #include <sys/signal.h> #include <math.h> @@ -77,6 +78,8 @@ int main(int argc, char *argv[]) bin_path = argv[1]; funct = malloc(strlen(bin_path) + MAX_FNAME_LEN); + if (funct == NULL) + err(1, "malloc failed"); sprintf(funct, "%s/gencos", bin_path); child = create_file(funct, 0); waitpid(child, NULL, 0); -- 2.55.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp