Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

satisfy some signed vs unsigned comparison warnings #809

Merged
merged 5 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions source/arch/intel/encoding_avx2.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,13 @@ static inline bool decode(const unsigned char *in, unsigned char *out) {

size_t aws_common_private_base64_decode_sse41(const unsigned char *in, unsigned char *out, size_t len) {
if (len % 4) {
return (size_t)-1;
return SIZE_MAX;
}

size_t outlen = 0;
while (len > 32) {
if (!decode(in, out)) {
return (size_t)-1;
return SIZE_MAX;
}
len -= 32;
in += 32;
Expand Down Expand Up @@ -230,13 +230,13 @@ size_t aws_common_private_base64_decode_sse41(const unsigned char *in, unsigned
}

if (!decode(tmp_in, tmp_out)) {
return (size_t)-1;
return SIZE_MAX;
}

/* Check that there are no trailing ones bits */
for (size_t i = final_out; i < sizeof(tmp_out); i++) {
if (tmp_out[i]) {
return (size_t)-1;
return SIZE_MAX;
}
}

Expand Down
4 changes: 2 additions & 2 deletions source/encoding.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ static inline size_t aws_common_private_base64_decode_sse41(const unsigned char
(void)out;
(void)len;
AWS_ASSERT(false);
return (size_t)-1; /* unreachable */
return SIZE_MAX; /* unreachable */
}
static inline void aws_common_private_base64_encode_sse41(const unsigned char *in, unsigned char *out, size_t len) {
(void)in;
Expand Down Expand Up @@ -361,7 +361,7 @@ int aws_base64_decode(const struct aws_byte_cursor *AWS_RESTRICT to_decode, stru

if (aws_common_private_has_avx2()) {
size_t result = aws_common_private_base64_decode_sse41(to_decode->ptr, output->buffer, to_decode->len);
if (result == -1) {
if (result == SIZE_MAX) {
return aws_raise_error(AWS_ERROR_INVALID_BASE64_STR);
}

Expand Down
2 changes: 1 addition & 1 deletion source/posix/device_random.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static int s_fallback_device_random_buffer(struct aws_byte_buf *output) {

ssize_t amount_read = read(s_rand_fd, output->buffer + output->len, diff);

if (amount_read != diff) {
if (amount_read < 0 || (size_t)amount_read != diff) {
return aws_raise_error(AWS_ERROR_RANDOM_GEN_FAILED);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/atomics_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ static int run_races(
int *participant_indexes = alloca(n_participants_local * sizeof(*participant_indexes));
struct aws_thread *threads = alloca(n_participants_local * sizeof(struct aws_thread));

*last_race = (size_t)-1;
*last_race = SIZE_MAX;
n_participants = n_participants_local;
done_racing = false;
aws_atomic_init_int(&last_race_index, 0);
Expand All @@ -293,7 +293,7 @@ static int run_races(
*last_race = n_races;
} else {
*last_race = (size_t)aws_atomic_load_int_explicit(&last_race_index, aws_memory_order_relaxed);
if (*last_race == (size_t)-1) {
if (*last_race == SIZE_MAX) {
/* We didn't even see the first race complete */
*last_race = 0;
}
Expand Down