Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Why is this outputting alternate blank lines? Date: Wed, 14 Dec 2016 12:15:22 -0800 Organization: None to speak of Lines: 26 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="f4d023dc7368ee832f7340f59496ea26"; logging-data="26492"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19QCciIrO0xWIcWMgZUWl7g" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:WoEv06mio2rDACea6AF7FZMC/NM= sha1:Ki4O/DyVrEbRlgxmDRAjEu5/9YM= Xref: csiph.com comp.lang.c:99399 Keith Thompson writes: > Richard Heathfield writes: >> On 14/12/16 17:53, DFS wrote: > [...] >>> Any idea why it crashes above 1 million? >> >> Do you remember when I suggested checking the return value of malloc? >> >> I again suggest that you check the return value of malloc. >> >> The malloc function returns NULL when it fails to allocate memory. Since >> you're not checking for this, if ever it /does/ return NULL you will be >> scribbling all over memory you don't own, hence the segfault. > > On the other hand, on some systems malloc() generally doesn't report > failure; rather if you allocate too much memory, a crash occurs when you > try to access it. (This is arguably non-conforming.) Which is not to say you shouldn't check the value returned by malloc(), even on systems that behave this way. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"