Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news1.tnib.de!feed.news.tnib.de!news.tnib.de!newsfeed.freenet.ag!ecngs!feeder2.ecngs.de!proxad.net!feeder1-1.proxad.net!198.186.194.247.MISMATCH!news-out.readnews.com!transit3.readnews.com!nx02.iad01.newshosting.com!newshosting.com!69.16.185.21.MISMATCH!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Thu, 28 Jul 2011 20:05:50 -0500 Message-ID: <4E320772.2024@mindspring.com> Date: Thu, 28 Jul 2011 21:05:54 -0400 From: pete Reply-To: pfiland@mindspring.com Organization: PF X-Mailer: Mozilla 3.04Gold (WinNT; I) MIME-Version: 1.0 Newsgroups: comp.lang.c Subject: Re: is there anything unstandard in the c part here References: <996dhnFhnlU1@mid.individual.net> <068a92bb-d2ff-41e4-a8a0-5156cc856f42@w24g2000yqw.googlegroups.com> <99c3j6Fdj7U1@mid.individual.net> <0.31b962284a303df15978.20110728121953BST.87vcumps86.fsf@bsb.me.uk> <4E31FE08.4910@mindspring.com> <1bhb65rkeg.fsf@snowball.wb.pfeifferfamily.net> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 39 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 4.154.219.238 X-Trace: sv3-XLpkbDTrQfw/R6mPsTOF2C50EUk5H2weNNAX4UFeg0P86eUIQPHrNhyghpblIE779jDhNGPnWQDO8rv!kTbkEamucgtoXaPfzZz6qYHnTwmxZ9cvfj9zmtzWUt5ZIkzS3hc5wgCMiz6mIx6CD3ZZqTjmVA39!Uc3YIR2GyvA= X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2360 Xref: x330-a1.tempe.blueboxinc.net comp.lang.c:8853 Joe Pfeiffer wrote: > > pete writes: > > > Ben Bacarisse wrote: > > > >> If you have a utility function: > >> > >> void *malloc_or_bust(size_t sz) > >> { > >> void *p = malloc(sz); > >> if (p == NULL) { > >> fprintf(stderr, "malloc failed.\n"); > >> exit(EXIT_FAILURE); > >> } > >> return p; > >> } > >> > >> then you can simply write > >> > >> char *testc(void) > >> { > >> return strcpy(malloc_or_bust(50), > >> "this sentence is less than fifty bytes."); > >> } > > > > If malloc_or_bust(50) returns a null pointer within testc, > > then you have undefined behavior in the strcpy call; > > and then maybe testc will return a null pointer > > or maybe it will return "this sentence is less than fifty bytes." > > or maybe something else will happen. > > How can malloc_bust() return a null pointer? > If the pointer is null the program exits. Oops. I read it wrong. -- pete