Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: mergesort code segfaulting on smallish arrays Date: Sat, 09 Nov 2019 12:43:46 -0800 Organization: None to speak of Lines: 18 Message-ID: References: <87mud63p3b.fsf@bsb.me.uk> <%QBxF.59077$VR.21809@fx39.iad> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="04d7f252c942ed664178d1ace563d1fb"; logging-data="26670"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/9pPJyXUgiFGi+Tj7zierp" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:fYAsxSZHT7oeVzhZGGrhjOZ8unY= sha1:9hgH8FcacOMG7XHit3U81Oi1AG0= Xref: csiph.com comp.lang.c:147850 Richard Damon writes: [...] > The code also assume (perhaps acceptably) that RAND_MAX fits in 32 bits. > One weakness in C is that there is no simple way to get a type twice as > big as another type to make sure that a multiply doesn't overflow. Supporting that in general would of course require infinitely wide types. A way to get a type twice as wide as a given type *if such a type exists* could be a nice feature. One reasonable approach that doesn't *quite* do that is to try [u]intmax_t and check whether it's wide enough. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for Philips Healthcare void Void(void) { Void(); } /* The recursive call of the void */