public inbox for linux-man@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mallopt.3: fix program source to match behaviour example
@ 2012-04-29 12:07 Simon Paillard
       [not found] ` <1335701271-10490-1-git-send-email-spaillard-8fiUuRrzOP0dnm+yROfE0A@public.gmane.org>
  0 siblings, 1 reply; 2+ messages in thread
From: Simon Paillard @ 2012-04-29 12:07 UTC (permalink / raw)
  To: linux-man-u79uwXL29TY76Z2rM5mHXA; +Cc: Simon Paillard

Call mallopt with argv[1] only if a parameter is given
---
 man3/mallopt.3 |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/man3/mallopt.3 b/man3/mallopt.3
index ddb1aed..03f1e9a 100644
--- a/man3/mallopt.3
+++ b/man3/mallopt.3
@@ -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);
-- 
1.7.2.5

--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] mallopt.3: fix program source to match behaviour example
       [not found] ` <1335701271-10490-1-git-send-email-spaillard-8fiUuRrzOP0dnm+yROfE0A@public.gmane.org>
@ 2012-04-29 18:47   ` Michael Kerrisk (man-pages)
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Kerrisk (man-pages) @ 2012-04-29 18:47 UTC (permalink / raw)
  To: Simon Paillard; +Cc: linux-man-u79uwXL29TY76Z2rM5mHXA

On Mon, Apr 30, 2012 at 12:07 AM, Simon Paillard <spaillard-8fiUuRrzOP0dnm+yROfE0A@public.gmane.org> wrote:
> Call mallopt with argv[1] only if a parameter is given
> ---
>  man3/mallopt.3 |    8 ++++----
>  1 files changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/man3/mallopt.3 b/man3/mallopt.3
> index ddb1aed..03f1e9a 100644
> --- a/man3/mallopt.3
> +++ b/man3/mallopt.3
> @@ -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);
> --

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:

==
--- a/man3/mallopt.3
+++ b/man3/mallopt.3
@@ -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);
}


-- 
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 majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-04-29 18:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-29 12:07 [PATCH] mallopt.3: fix program source to match behaviour example Simon Paillard
     [not found] ` <1335701271-10490-1-git-send-email-spaillard-8fiUuRrzOP0dnm+yROfE0A@public.gmane.org>
2012-04-29 18:47   ` Michael Kerrisk (man-pages)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox