summary refs log tree commit diff
path: root/pkgs/test/make-binary-wrapper
diff options
context:
space:
mode:
authorTobias Bergkvist <tobias@bergkv.ist>2021-11-09 02:55:26 +0100
committerTobias Bergkvist <tobias@bergkv.ist>2021-11-09 02:56:32 +0100
commit3a014be2f2230b3228e122b7c74fb7561b495195 (patch)
treee0662cf77dc8cba90e6e8a99bbe55e1080d64a56 /pkgs/test/make-binary-wrapper
parenteb048d8fe26e029d662ee9300ff87c616baf2076 (diff)
downloadnixpkgs-3a014be2f2230b3228e122b7c74fb7561b495195.tar
nixpkgs-3a014be2f2230b3228e122b7c74fb7561b495195.tar.gz
nixpkgs-3a014be2f2230b3228e122b7c74fb7561b495195.tar.bz2
nixpkgs-3a014be2f2230b3228e122b7c74fb7561b495195.tar.lz
nixpkgs-3a014be2f2230b3228e122b7c74fb7561b495195.tar.xz
nixpkgs-3a014be2f2230b3228e122b7c74fb7561b495195.tar.zst
nixpkgs-3a014be2f2230b3228e122b7c74fb7561b495195.zip
Assert that malloc does not return a NULL pointer for better error messages + to satisfy static analysis tools.
Diffstat (limited to 'pkgs/test/make-binary-wrapper')
-rw-r--r--pkgs/test/make-binary-wrapper/add-flags.c2
-rw-r--r--pkgs/test/make-binary-wrapper/combination.c3
-rw-r--r--pkgs/test/make-binary-wrapper/prefix.c2
-rw-r--r--pkgs/test/make-binary-wrapper/suffix.c2
4 files changed, 9 insertions, 0 deletions
diff --git a/pkgs/test/make-binary-wrapper/add-flags.c b/pkgs/test/make-binary-wrapper/add-flags.c
index 70d43e0bec0..fccd5aa9402 100644
--- a/pkgs/test/make-binary-wrapper/add-flags.c
+++ b/pkgs/test/make-binary-wrapper/add-flags.c
@@ -4,9 +4,11 @@
 
 #include <unistd.h>
 #include <stdlib.h>
+#include <assert.h>
 
 int main(int argc, char **argv) {
     char **argv_tmp = malloc(sizeof(*argv_tmp) * (5 + argc));
+    assert(argv_tmp != NULL);
     argv_tmp[0] = argv[0];
     argv_tmp[1] = "-x";
     argv_tmp[2] = "-y";
diff --git a/pkgs/test/make-binary-wrapper/combination.c b/pkgs/test/make-binary-wrapper/combination.c
index 925fdf1ccfb..5e4e1168f4a 100644
--- a/pkgs/test/make-binary-wrapper/combination.c
+++ b/pkgs/test/make-binary-wrapper/combination.c
@@ -9,12 +9,14 @@
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
+#include <assert.h>
 
 char *concat3(char *x, char *y, char *z) {
     int xn = strlen(x);
     int yn = strlen(y);
     int zn = strlen(z);
     char *res = malloc(sizeof(*res)*(xn + yn + zn + 1));
+    assert(res != NULL);
     strncpy(res, x, xn);
     strncpy(res + xn, y, yn);
     strncpy(res + xn + yn, z, zn);
@@ -43,6 +45,7 @@ int main(int argc, char **argv) {
     putenv("MESSAGE2=WORLD");
 
     char **argv_tmp = malloc(sizeof(*argv_tmp) * (4 + argc));
+    assert(argv_tmp != NULL);
     argv_tmp[0] = argv[0];
     argv_tmp[1] = "-x";
     argv_tmp[2] = "-y";
diff --git a/pkgs/test/make-binary-wrapper/prefix.c b/pkgs/test/make-binary-wrapper/prefix.c
index 914fd851bb7..fa333013cd0 100644
--- a/pkgs/test/make-binary-wrapper/prefix.c
+++ b/pkgs/test/make-binary-wrapper/prefix.c
@@ -5,12 +5,14 @@
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
+#include <assert.h>
 
 char *concat3(char *x, char *y, char *z) {
     int xn = strlen(x);
     int yn = strlen(y);
     int zn = strlen(z);
     char *res = malloc(sizeof(*res)*(xn + yn + zn + 1));
+    assert(res != NULL);
     strncpy(res, x, xn);
     strncpy(res + xn, y, yn);
     strncpy(res + xn + yn, z, zn);
diff --git a/pkgs/test/make-binary-wrapper/suffix.c b/pkgs/test/make-binary-wrapper/suffix.c
index 865d76fe34e..a299f1fa0bd 100644
--- a/pkgs/test/make-binary-wrapper/suffix.c
+++ b/pkgs/test/make-binary-wrapper/suffix.c
@@ -5,12 +5,14 @@
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
+#include <assert.h>
 
 char *concat3(char *x, char *y, char *z) {
     int xn = strlen(x);
     int yn = strlen(y);
     int zn = strlen(z);
     char *res = malloc(sizeof(*res)*(xn + yn + zn + 1));
+    assert(res != NULL);
     strncpy(res, x, xn);
     strncpy(res + xn, y, yn);
     strncpy(res + xn + yn, z, zn);