Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Reason for segmentation violation Date: Fri, 12 Jun 2015 08:29:07 -0700 Organization: None to speak of Lines: 33 Message-ID: <87r3phgd30.fsf@kst-u.example.com> References: <869bae8d-e318-4e1c-865b-3c5890304279@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="9be37d943435275679235b07c7947eef"; logging-data="31974"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+mli2OgWdBFx5LoUfQkgHy" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:HCbWLNsEow2wYogGT57VPMkfAGM= sha1:Aqg9Z6/SpzNltymbfQ3fyaSqqSs= Xref: csiph.com comp.lang.c:63215 glen herrmannsfeldt writes: > Morten W. Petersen wrote: > (snip) >> When it comes to realloc, looking at that function one can tell >> that realloc will keep the memory segment at the same size or >> reduce it. >> What are the chances that such a call to realloc will fail? > > If I tell you, will you program differently? > > If it is 1% or 10%? > > As far as I know, most unix-like systems have the ability to reduce > the size of an allocated block. > > C tries to be general enough, and it might be that some systems > have to allocate new space and copy the data, even to reduce the > size, and it could fail on those systems. Do you know that your > program will never run on one of those? Or an implementation of realloc() might want to store the new smaller block at a different location because it makes its internal bookkeeping easier, and if there isn't enough room to do that it might fail rather than keeping the original location. (For example, it might maintain one chunk of memory for large blocks and another for small blocks.) I have no idea whether any actual implementations do this. -- 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"