9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: erik quanstrom <quanstro@coraid.com>
To: 9fans@cse.psu.edu
Subject: Re: [9fans] memory woes
Date: Fri,  5 Jan 2007 09:44:06 -0500	[thread overview]
Message-ID: <687643a97ce7ba1e1f4c5ab24eeb5959@coraid.com> (raw)
In-Reply-To: <329de470156ae34054ae5f9314a37c49@mail.gmx.net>

you are forgetting +1 for the null.  you need strlen("Hello World")+1.

- erik

> #include <u.h>
> #include <libc.h>
>
>
> void main(int argc, char **argv) {
> 	int i;
> 	char *m00;
>
> 	for(i=0; i<=5; i++) {
> 		if((m00 = malloc(strlen("Hello World"))) == nil) {
> 			print("drama! [%d]\n",i);
> 			exits("malloc");
> 		}
> 		strcpy(m00,"Hello World");
> 		print("%d> %s\n",i,m00);
> 		free(m00);
> 	}
> 	exits(nil);
> }


  reply	other threads:[~2007-01-05 14:44 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-05 14:36 sretzki
2007-01-05 14:44 ` erik quanstrom [this message]
2007-01-05 14:51   ` sretzki
2007-01-05 14:53 ` Axel Belinfante
2007-01-05 14:54 erik quanstrom

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=687643a97ce7ba1e1f4c5ab24eeb5959@coraid.com \
    --to=quanstro@coraid.com \
    --cc=9fans@cse.psu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).