Skip to contentSkip to conversation

mallopt.3: fix program source to match behaviour example

PATCH In review Simon Paillard 2 participants 2 messages Apr 29, 2012 1 message not in the archive Man-pages: manual pages for Linux -- Sections 2, 3, 4, 5, and 7

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mallopt.3: fix program source to match behaviour example

Call mallopt with argv[1] only if a parameter is given

---
 man3/mallopt.3 |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
man3/mallopt.3 +4 -4
index ddb1aed..03f1e9a 100644
@@ -543,11 +543,11 @@ main(int argc, char *argv[])
             fprintf(stderr, "%s <M_CHECK_ACTION\-value>\\n", argv[0]);
             exit(EXIT_FAILURE);
         }
-    }
 
-    if (mallopt(M_CHECK_ACTION, atoi(argv[1])) != 1) {
-        fprintf(stderr, "mallopt() failed");
-        exit(EXIT_FAILURE);
+        if (mallopt(M_CHECK_ACTION, atoi(argv[1])) != 1) {
+            fprintf(stderr, "mallopt() failed");
+            exit(EXIT_FAILURE);
+        }
     }
 
     p = malloc(1000);
Signature · 6 lines
1.7.2.5

--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 1335701271-10490-1-git-send-email-spaillard-8fiUuRrzOP0dnm+yROfE0A@public.gmane.org

#2 lore raw
Quoted 16 lines · Simon Paillard

Call mallopt with argv[1] only if a parameter is given
---
 man3/mallopt.3 |    8 ++++----

 1 files changed, 4 insertions(+), 4 deletions(-)
man3/mallopt.3 +0 -2
index ddb1aed..03f1e9a 100644
@@ -543,11 +543,11 @@ main(int argc, char *argv[])
             fprintf(stderr, "%s <M_CHECK_ACTION\-value>\\n", argv[0]);
             exit(EXIT_FAILURE);
         }
-    }
 
-    if (mallopt(M_CHECK_ACTION, atoi(argv[1])) != 1) {

man3/mallopt.3 main(int argc, char *argv[])

Quoted 10 lines
man3/mallopt.3 +4 -3
-        fprintf(stderr, "mallopt() failed");
-        exit(EXIT_FAILURE);
+        if (mallopt(M_CHECK_ACTION, atoi(argv[1])) != 1) {
+            fprintf(stderr, "mallopt() failed");
+            exit(EXIT_FAILURE);
+        }
     }
 
     p = malloc(1000);
--

Hi Simon,

Thanks for this. Somewhere along the way I included the wrong source in the EXAMPLE section. However, the intended code was as per this patch:

==

man3/mallopt.3 +2 -7
@@ -540,17 +540,12 @@ main(int argc, char *argv[])
     char *p;
 
     if (argc > 1) {
-        if (argc != 2) {
-            fprintf(stderr, "%s <M_CHECK_ACTION\-value>\\n", argv[0]);
+        if (mallopt(M_CHECK_ACTION, atoi(argv[1])) != 1) {
+            fprintf(stderr, "mallopt() failed");
             exit(EXIT_FAILURE);
         }
     }
 
-    if (mallopt(M_CHECK_ACTION, atoi(argv[1])) != 1) {
-        fprintf(stderr, "mallopt() failed");
-        exit(EXIT_FAILURE);
-    }
-
     p = malloc(1000);
     if (p == NULL) {
         fprintf(stderr, "malloc() failed");

==

The complete example is shown below. I've applied the above patch.

Cheers,

Michael

=====

#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>

int
main(int argc, char *argv[])

{
    char *p;

    if (argc > 1) {
        if (mallopt(M_CHECK_ACTION, atoi(argv[1])) != 1) {
            fprintf(stderr, "mallopt() failed");
            exit(EXIT_FAILURE);
        }
    }

    p = malloc(1000);
    if (p == NULL) {
        fprintf(stderr, "malloc() failed");
        exit(EXIT_FAILURE);
    }

    free(p);
    printf("main(): returned from first free() call\n");

    free(p);
    printf("main(): returned from second free() call\n");

    exit(EXIT_SUCCESS);
}
Signature · 7 lines
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Author of "The Linux Programming Interface"; http://man7.org/tlpi/
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html