mirror of
https://github.com/amadvance/snapraid.git
synced 2026-11-30 03:47:05 -05:00
Fix undefined behavior in extent file comparison by casting pointers to uintptr_t
This commit is contained in:
parent
bd856b456b
commit
3185e1bf34
1 changed files with 10 additions and 4 deletions
|
|
@ -701,10 +701,13 @@ int extent_file_compare(const void* void_a, const void* void_b)
|
||||||
{
|
{
|
||||||
const struct snapraid_extent* arg_a = void_a;
|
const struct snapraid_extent* arg_a = void_a;
|
||||||
const struct snapraid_extent* arg_b = void_b;
|
const struct snapraid_extent* arg_b = void_b;
|
||||||
|
uintptr_t file_a = (uintptr_t)arg_a->file;
|
||||||
|
uintptr_t file_b = (uintptr_t)arg_b->file;
|
||||||
|
|
||||||
if (arg_a->file < arg_b->file)
|
/* cast to uintptr_t to avoid undefined behavior when comparing pointers to distinct heap allocations */
|
||||||
|
if (file_a < file_b)
|
||||||
return -1;
|
return -1;
|
||||||
if (arg_a->file > arg_b->file)
|
if (file_a > file_b)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (arg_a->file_pos < arg_b->file_pos)
|
if (arg_a->file_pos < arg_b->file_pos)
|
||||||
|
|
@ -1293,10 +1296,13 @@ static int extent_file_inside_compare_unlock(const void* void_a, const void* voi
|
||||||
{
|
{
|
||||||
const struct extent_file_inside* arg_a = void_a;
|
const struct extent_file_inside* arg_a = void_a;
|
||||||
const struct snapraid_extent* arg_b = void_b;
|
const struct snapraid_extent* arg_b = void_b;
|
||||||
|
uintptr_t file_a = (uintptr_t)arg_a->file;
|
||||||
|
uintptr_t file_b = (uintptr_t)arg_b->file;
|
||||||
|
|
||||||
if (arg_a->file < arg_b->file)
|
/* cast to uintptr_t to avoid undefined behavior when comparing pointers to distinct heap allocations */
|
||||||
|
if (file_a < file_b)
|
||||||
return -1;
|
return -1;
|
||||||
if (arg_a->file > arg_b->file)
|
if (file_a > file_b)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (arg_a->file_pos < arg_b->file_pos)
|
if (arg_a->file_pos < arg_b->file_pos)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue