Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!rutgers!seismo!ll-xn!cit-vax!usc-oberon!sdcrdcf!trwrb!ries From: ries@trwrb.UUCP Newsgroups: comp.lang.c Subject: Linting Malloc (Was: Re: Need help with pointer to array[][]) Message-ID: <1661@trwrb.UUCP> Date: Wed, 11-Mar-87 13:45:03 EST Article-I.D.: trwrb.1661 Posted: Wed Mar 11 13:45:03 1987 Date-Received: Fri, 13-Mar-87 05:33:27 EST References: <132@batcomputer.tn.cornell.edu> <1911@utah-gr.UUCP> <5347@mimsy.UUCP> Reply-To: ries@trwrb.UUCP (Marc Ries) Organization: TRW Operations and Support Group Lines: 56 Keywords: "warning: possible pointer alignment problem" In article <5347@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes: [... discussions on dynamically allocating arrays deleted ...] >> >> fnames = (char (*)[16][32])malloc(16*32*sizeof(char)); >> [.. more deletions ...] >Of course, proper paranoia also includes checking the return >value from malloc(): > > if ((fnames = (char (*)[32]) malloc(16 * sizeof (char [32))) == NULL) > ... /* handle out of memory error */ > >Another annoying nit is that malloc() takes an unsigned argument, >while sizeof has type `size_t', which is not necessarily unsigned >(it is signed in 4BSD), requiring yet more casts. (I would rather >have an unsigned `size_t'.) >-- >In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept I have followed the discussion because of the comments on de- linting and portability. Maybe one of the linting experts can comment on the following case. I noticed that while practicing de-linting the "filter" code in the latest release of Dave Taylor's "ELM" mailer, the "parse.c" code has several lines of the type: if ((cond = (struct condition_rec *) malloc(sizeof(struct condition_rec))) == NULL) { (void) fprintf(stderr,"couldn't malloc first condition rec!\n"); return(-1); } where: char *malloc(); struct condition_rec *cond; lint (Pyramid 98X, 3.1 DualOSx, BSD Universe): "warning: possible pointer alignment problem" llib-lc: char * malloc(n) unsigned n; {static char c; return(&c);} Summary: Several gyrations of trying to get lint to shut up hasn't. I there a way to get lint to pass this, make this "more" portable, or ?. Marc A. Ries sdcrdcf!---\ ihnp4!------\----- trwrb! --- ries -- Marc A. Ries sdcrdcf!---\ ihnp4!------\----- trwrb! --- ries