Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!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 19:25:42 -0500 Message-ID: <4E31FE08.4910@mindspring.com> Date: Thu, 28 Jul 2011 20:25:44 -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> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 30 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 4.154.219.238 X-Trace: sv3-v5cIuu4Bglwzur0De/CAltT3ul47hxto6V0vnPyeLr+cIwbpeZR5x9WpeISH/I5d2thyLvxlJZfzeYr!FP+5O81ZeuqOaJEy7AF/Y2gKRbGVWZcagUEF5UFRz7EAFt85fDvcGIYja0df5R2nTuJeOMmE5i/t!FlI5cgt75KE= 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: 1997 Xref: x330-a1.tempe.blueboxinc.net comp.lang.c:8850 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. -- pete