Skip to content

Commit

Permalink
lib/alg-yescrypt-platform.c: Fix -Werror=sign-conversion.
Browse files Browse the repository at this point in the history
This is a more elegant approach of the previous commit.
  • Loading branch information
besser82 committed Nov 18, 2022
1 parent 05e5705 commit 53cff4b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/alg-yescrypt-platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static void *alloc_region(yescrypt_region_t *region, size_t size)
size_t base_size = size;
uint8_t *base, *aligned;
#ifdef MAP_ANON
int flags =
unsigned int flags =
#ifdef MAP_NOCORE
MAP_NOCORE |
#endif
Expand All @@ -47,24 +47,24 @@ static void *alloc_region(yescrypt_region_t *region, size_t size)
size_t new_size = size;
const size_t hugepage_mask = (size_t)HUGEPAGE_SIZE - 1;
if (size >= HUGEPAGE_THRESHOLD && size + hugepage_mask >= size) {
flags |= (int)(MAP_HUGETLB | MAP_HUGE_2MB);
flags |= MAP_HUGETLB | MAP_HUGE_2MB;
/*
* Linux's munmap() fails on MAP_HUGETLB mappings if size is not a multiple of
* huge page size, so let's round up to huge page size here.
*/
new_size = size + hugepage_mask;
new_size &= ~hugepage_mask;
}
base = mmap(NULL, new_size, PROT_READ | PROT_WRITE, flags, -1, 0);
base = mmap(NULL, new_size, PROT_READ | PROT_WRITE, (int)flags, -1, 0);
if (base != MAP_FAILED) {
base_size = new_size;
} else if (flags & MAP_HUGETLB) {
flags &= ~(int)(MAP_HUGETLB | MAP_HUGE_2MB);
base = mmap(NULL, size, PROT_READ | PROT_WRITE, flags, -1, 0);
flags &= (unsigned int)~(MAP_HUGETLB | MAP_HUGE_2MB);
base = mmap(NULL, size, PROT_READ | PROT_WRITE, (int)flags, -1, 0);
}

#else
base = mmap(NULL, size, PROT_READ | PROT_WRITE, flags, -1, 0);
base = mmap(NULL, size, PROT_READ | PROT_WRITE, (int)flags, -1, 0);
#endif
if (base == MAP_FAILED)
base = NULL;
Expand Down

2 comments on commit 53cff4b

@solardiz
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, in place of:

		flags &= (unsigned int)~(MAP_HUGETLB | MAP_HUGE_2MB);

in the upstream fix I'm likely to do:

		flags &= ~(unsigned int)(MAP_HUGETLB | MAP_HUGE_2MB);

So that the ~ is definitely applied to an unsigned type regardless of how MAP_* are defined.

@besser82
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@solardiz, ok, I've changed it that way in 9d5e7b7.

Please sign in to comment.