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

2024-05-20 Thread Andreas Schwab
On Mai 17 2024, 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. In the case of globsort_sizecmp, since off_t is wider

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

2024-05-20 Thread Chet Ramey
On 5/20/24 10:07 AM, alex xmb sw ratchev wrote: > 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

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

2024-05-20 Thread alex xmb sw ratchev
On Mon, May 20, 2024, 15:58 Chet Ramey wrote: > On 5/17/24 5:56 PM, Grisha Levit wrote: > > On Fri, May 17, 2024 at 3:06 PM Chet Ramey 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

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

2024-05-20 Thread Chet Ramey
On 5/17/24 5:56 PM, Grisha Levit wrote: On Fri, May 17, 2024 at 3:06 PM Chet Ramey 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

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

2024-05-17 Thread Grisha Levit
On Fri, May 17, 2024 at 3:06 PM Chet Ramey 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

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

2024-05-17 Thread Chet Ramey
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

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

2024-05-17 Thread Robert Elz
Date:Fri, 17 May 2024 12:57:25 -0400 From:Grisha Levit Message-ID: <20240517165738.8896-1-grishale...@gmail.com> | The current cmp implementation for size and blocks subtracts the two | values and returns the difference as an int. This subtraction can |

[PATCH] globsort: handle int overflow in cmp functions

2024-05-17 Thread Grisha Levit
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