bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] globsort: handle int overflow in cmp functions


From: alex xmb sw ratchev
Subject: Re: [PATCH] globsort: handle int overflow in cmp functions
Date: Mon, 20 May 2024 16:07:50 +0200

On Mon, May 20, 2024, 15:58 Chet Ramey <chet.ramey@case.edu> wrote:

> On 5/17/24 5:56 PM, Grisha Levit wrote:
> > On Fri, May 17, 2024 at 3:06 PM Chet Ramey <chet.ramey@case.edu> wrote:
> >>
> >> On 5/17/24 12:57 PM, Grisha Levit wrote:
> >>> The current cmp implementation for size and blocks subtracts the two
> >>> values and returns the difference as an int. This subtraction can
> >>> overflow, and the returned int can end up having the wrong sign.
> >>>
> >>> This also makes the qsort comparison function non-transitive. (Some
> >>> interesting discussion on that at [1]).
> >>
> >> Thanks for the report. If overflow is a concern, then a guaranteed
> >> transitive comparison function is the right thing. Your solution is
> clever,
> >> but a little obscure; I think I'll make it look more like the other
> >> comparison functions.
> >
> > FWIW, I was copying the approach from coreutils[1] and gnulib[2]:
>
> Sure. I'm going to stick with code clarity and uniformity over micro
> optimizations here. Maybe I could hide it in a macro.
>

an if overflow sounds like an important thing to code , an overall one

-- 
> ``The lyf so short, the craft so long to lerne.'' - Chaucer
>                  ``Ars longa, vita brevis'' - Hippocrates
> Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/
>
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]