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 11:57:43 -0800 Organization: None to speak of Lines: 22 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="U2FsdGVkX19+npTgQc/OC5unrnUhVxcw" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:eG6T/FcIBCXDsrPW6vzySvKSWZo= sha1:uyjVfKpSpcPSSrY61NodC1l/8yU= Xref: csiph.com comp.lang.c:99387 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.) -- 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"