Fix sorting by file size for sizes bigger than INT_MAX

Instead of directly return the difference of the sizes from the
comparison functions, use the relational operators, as suggested by
Chris Young (thanks!).

Fixes #74
pull/81/head
Adrian Perez de Castro 7 years ago committed by Adrian Perez
parent b21ec45790
commit c1b1be3615

@ -2,6 +2,10 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
## [Unreleased] ## [Unreleased]
### Fixed
- Sorting by file size now also works correctly for directories which contain
files of sizes bigger than `INT_MAX`. (Bug report by and fix suggestion by
Chris Young.)
## [0.4.1] - 2016-08-18 ## [0.4.1] - 2016-08-18
### Added ### Added

@ -1229,7 +1229,7 @@ ngx_http_fancyindex_cmp_entries_size_desc(const void *one, const void *two)
ngx_http_fancyindex_entry_t *first = (ngx_http_fancyindex_entry_t *) one; ngx_http_fancyindex_entry_t *first = (ngx_http_fancyindex_entry_t *) one;
ngx_http_fancyindex_entry_t *second = (ngx_http_fancyindex_entry_t *) two; ngx_http_fancyindex_entry_t *second = (ngx_http_fancyindex_entry_t *) two;
return (int) (second->size - first->size); return (first->size > second->size) - (first->size < second->size);
} }
@ -1259,7 +1259,7 @@ ngx_http_fancyindex_cmp_entries_size_asc(const void *one, const void *two)
ngx_http_fancyindex_entry_t *first = (ngx_http_fancyindex_entry_t *) one; ngx_http_fancyindex_entry_t *first = (ngx_http_fancyindex_entry_t *) one;
ngx_http_fancyindex_entry_t *second = (ngx_http_fancyindex_entry_t *) two; ngx_http_fancyindex_entry_t *second = (ngx_http_fancyindex_entry_t *) two;
return (int) (first->size - second->size); return (first->size > second->size) - (first->size < second->size);
} }

Loading…
Cancel
Save