]> git.ipfire.org Git - thirdparty/man-pages.git/commitdiff
execve.2, pipe.2, tee.2, fmemopen.3, mq_notify.3, qsort.3: Replace use of assert...
authorMichael Kerrisk <mtk.manpages@gmail.com>
Tue, 15 Sep 2009 04:46:16 +0000 (06:46 +0200)
committerMichael Kerrisk <mtk.manpages@gmail.com>
Mon, 28 Sep 2009 10:46:19 +0000 (12:46 +0200)
See http://bugzilla.kernel.org/show_bug.cgi?id=13569

As noted by Andrey:
The purpose of the assert macro, defined in <assert.h>,
is to provide a tool to check for programming mistakes
or program logic errors. However, the assert macro must
never be used to perform checks for run time errors,
since, with the NDEBUG macro defined, expressions within
the assert macro invocations are not evaluated/checked
for, resulting in behavior that was not originally intended.
...
The pages affected in the core package are

execve(2)
pipe(2)
tee(2)
fmemopen(3)
mq_notify(3)
qsort(3)

Reported-by: Andrey Vihrov <vihrov@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
man2/execve.2
man2/pipe.2
man2/tee.2
man3/fmemopen.3
man3/mq_notify.3
man3/qsort.3

index b9611f4d71a842338f0f13707be590f817b3cb8d..0ea50db1526dc76ff104e774c04209bc15406c04 100644 (file)
@@ -34,7 +34,7 @@
 .\" 2007-09-14 Ollie Wild <aaw@google.com>, mtk
 .\"     Add text describing limits on command-line arguments + environment
 .\"
-.TH EXECVE 2 2009-04-21 "Linux" "Linux Programmer's Manual"
+.TH EXECVE 2 2009-09-15 "Linux" "Linux Programmer's Manual"
 .SH NAME
 execve \- execute program
 .SH SYNOPSIS
@@ -555,7 +555,6 @@ argument:
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include <assert.h>
 
 int
 main(int argc, char *argv[])
@@ -563,8 +562,11 @@ main(int argc, char *argv[])
     char *newargv[] = { NULL, "hello", "world", NULL };
     char *newenviron[] = { NULL };
 
-    assert(argc == 2);  /* argv[1] identifies
-                           program to exec */
+    if (argc != 2) {
+       fprintf(stderr, "Usage: %s <file-to-exec>\\n", argv[0]);
+       exit(EXIT_FAILURE);
+    }
+
     newargv[0] = argv[1];
 
     execve(argv[1], newargv, newenviron);
index 731ab962eea2432b1938faf7f28b3efe8c07e694..67fb1f4458e68a5ed35880339c108e9745b12842 100644 (file)
@@ -33,7 +33,7 @@
 .\"     to EXAMPLE text.
 .\" 2008-10-10, mtk: add description of pipe2()
 .\"
-.TH PIPE 2 2008-11-04 "Linux" "Linux Programmer's Manual"
+.TH PIPE 2 2009-09-15 "Linux" "Linux Programmer's Manual"
 .SH NAME
 pipe, pipe2 \- create pipe
 .SH SYNOPSIS
@@ -139,7 +139,6 @@ and echoes it on standard output.
 .nf
 
 #include <sys/wait.h>
-#include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -152,7 +151,10 @@ main(int argc, char *argv[])
     pid_t cpid;
     char buf;
 
-    assert(argc == 2);
+    if (argc != 2) {
+       fprintf(stderr, "Usage: %s <string>\\n", argv[0]);
+       exit(EXIT_FAILURE);
+    }
 
     if (pipe(pipefd) == \-1) {
         perror("pipe");
index 9863ac74f32152e6c9d4142a300b20f5b8e89961..23ffab2c0fa549fb7dc5de63f2b98ed051fed110 100644 (file)
@@ -139,7 +139,6 @@ system call.
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include <assert.h>
 #include <errno.h>
 #include <limits.h>
 
@@ -149,7 +148,10 @@ main(int argc, char *argv[])
     int fd;
     int len, slen;
 
-    assert(argc == 2);
+    if (argc != 2) {
+       fprintf(stderr, "Usage: %s <file>\\n", argv[0]);
+       exit(EXIT_FAILURE);
+    }
 
     fd = open(argv[1], O_WRONLY | O_CREAT | O_TRUNC, 0644);
     if (fd == \-1) {
index 0eb263ef290313d3d388da2375c66e448bcff0d3..c92924f9590d0617a1153a02d534d2aad27020f8 100644 (file)
@@ -3,7 +3,7 @@
 .\" Distributed under the GPL.
 .\" 2008-12-04, Petr Baudis <pasky@suse.cz>: Document open_wmemstream()
 .\"
-.TH FMEMOPEN 3 2009-04-21 "GNU" "Linux Programmer's Manual"
+.TH FMEMOPEN 3 2009-09-15 "GNU" "Linux Programmer's Manual"
 .SH NAME
 fmemopen, open_memstream, open_wmemstream \-  open memory as stream
 .SH SYNOPSIS
@@ -206,7 +206,6 @@ size=11; ptr=1 529 1849
 \&
 .nf
 #define _GNU_SOURCE
-#include <assert.h>
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -222,7 +221,10 @@ main(int argc, char *argv[])
     size_t size;
     char *ptr;
 
-    assert(argc == 2);
+    if (argc != 2) {
+       fprintf(stderr, "Usage: %s <file>\\n", argv[0]);
+       exit(EXIT_FAILURE);
+    }
 
     in = fmemopen(argv[1], strlen(argv[1]), "r");
     if (in == NULL)
index ad4410edae2bf5554493fb5c4ae25e8538545226..b17a7bb7ed1f2b72d770d39de4d037b9f1696b39 100644 (file)
@@ -23,7 +23,7 @@
 .\" Formatted or processed versions of this manual, if unaccompanied by
 .\" the source, must acknowledge the copyright and authors of this work.
 .\"
-.TH MQ_NOTIFY 3 2009-03-31 "Linux" "Linux Programmer's Manual"
+.TH MQ_NOTIFY 3 2009-09-15 "Linux" "Linux Programmer's Manual"
 .SH NAME
 mq_notify \- register for notification when a message is available
 .SH SYNOPSIS
@@ -215,7 +215,6 @@ queue and then terminates the process.
 
 #include <pthread.h>
 #include <mqueue.h>
-#include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -254,7 +253,10 @@ main(int argc, char *argv[])
     mqd_t mqdes;
     struct sigevent not;
 
-    assert(argc == 2);
+    if (argc != 2) {
+       fprintf(stderr, "Usage: %s <mq-name>\\n", argv[0]);
+       exit(EXIT_FAILURE);
+    }
 
     mqdes = mq_open(argv[1], O_RDONLY);
     if (mqdes == (mqd_t) \-1)
index e29ed28b26b3f7b50005e539b9af15e2b821e0dc..87ef129402276edd95e7717957fb90f9c692a324 100644 (file)
@@ -31,7 +31,7 @@
 .\"
 .\" FIXME glibc 2.8 added qsort_r(), which needs to be documented.
 .\"
-.TH QSORT 3 2009-02-01 "" "Linux Programmer's Manual"
+.TH QSORT 3 2009-09-15 "" "Linux Programmer's Manual"
 .SH NAME
 qsort \- sorts an array
 .SH SYNOPSIS
@@ -85,7 +85,6 @@ which sorts the strings given in its command-line arguments:
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <assert.h>
 
 static int
 cmpstringp(const void *p1, const void *p2)
@@ -102,7 +101,10 @@ main(int argc, char *argv[])
 {
     int j;
 
-    assert(argc > 1);
+    if (argc < 2) {
+       fprintf(stderr, "Usage: %s <string>...\\n", argv[0]);
+       exit(EXIT_FAILURE);
+    }
 
     qsort(&argv[1], argc \- 1, sizeof(char *), cmpstringp);