Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!decwrl!world!ksr!jfw From: jfw@ksr.com (John F. Woods) Newsgroups: comp.lang.c Subject: Re: Novice question about malloc and pointers Message-ID: <3248@ksr.com> Date: 22 Apr 91 16:48:37 GMT References: <9104171614.AA14362@enuxha.eas.asu.edu> <3182@ksr.com> <1991Apr17.203253.13854@ux1.cso.uiuc.edu> <1991Apr19.001739.5485@athena.mit.edu> Sender: news@ksr.com Lines: 12 scs@adam.mit.edu (Steve Summit) writes: >In article <3182@ksr.com> jfw@ksr.com (John F. Woods) writes: >> /* Treasure the line in a copy */ >> if ((str[i] = malloc(strlen(buf))) == NULL) { >Make that malloc(strlen(buf) + 1). (Side note: never tangle your >fingers and type malloc(strlen(buf + 1)), either.) Oops. Consider that another reason to use strdup() if you've got it. Assuming the library writer didn't screw up, too. :-)