From 942eea21743cee5c9b85ac6df5f90debb569d24d Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Wed, 15 Feb 2023 14:10:09 -0800 Subject: [PATCH 1/2] Add aws_min_non_0_64() --- include/aws/common/math.h | 1 + include/aws/common/math.inl | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/include/aws/common/math.h b/include/aws/common/math.h index 2473dcf5e..198155c56 100644 --- a/include/aws/common/math.h +++ b/include/aws/common/math.h @@ -186,6 +186,7 @@ AWS_STATIC_IMPL uint32_t aws_max_u32(uint32_t a, uint32_t b); AWS_STATIC_IMPL int32_t aws_min_i32(int32_t a, int32_t b); AWS_STATIC_IMPL int32_t aws_max_i32(int32_t a, int32_t b); AWS_STATIC_IMPL uint64_t aws_min_u64(uint64_t a, uint64_t b); +AWS_STATIC_IMPL uint64_t aws_min_non_0_u64(uint64_t a, uint64_t b); AWS_STATIC_IMPL uint64_t aws_max_u64(uint64_t a, uint64_t b); AWS_STATIC_IMPL int64_t aws_min_i64(int64_t a, int64_t b); AWS_STATIC_IMPL int64_t aws_max_i64(int64_t a, int64_t b); diff --git a/include/aws/common/math.inl b/include/aws/common/math.inl index 2081fbcca..65d53ba2f 100644 --- a/include/aws/common/math.inl +++ b/include/aws/common/math.inl @@ -244,6 +244,18 @@ AWS_STATIC_IMPL uint64_t aws_min_u64(uint64_t a, uint64_t b) { return a < b ? a : b; } +AWS_STATIC_IMPL uint64_t aws_min_non_0_u64(uint64_t a, uint64_t b) { + if (a == 0) { + return b; + } + + if (b == 0) { + return a; + } + + return aws_min_u64(a, b); +} + AWS_STATIC_IMPL uint64_t aws_max_u64(uint64_t a, uint64_t b) { return a > b ? a : b; } From 9c597de661ed1eb514ed274c04c634c1d7836b19 Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Wed, 15 Feb 2023 16:35:57 -0800 Subject: [PATCH 2/2] fixed description of aws_byte_cursor_advance --- include/aws/common/byte_buf.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/aws/common/byte_buf.h b/include/aws/common/byte_buf.h index 7df579ec4..f71967944 100644 --- a/include/aws/common/byte_buf.h +++ b/include/aws/common/byte_buf.h @@ -597,13 +597,13 @@ AWS_COMMON_API struct aws_byte_cursor aws_byte_cursor_from_array(const void *con /** * Tests if the given aws_byte_cursor has at least len bytes remaining. If so, - * *buf is advanced by len bytes (incrementing ->ptr and decrementing ->len), - * and an aws_byte_cursor referring to the first len bytes of the original *buf + * *cursor is advanced by len bytes (incrementing ->ptr and decrementing ->len), + * and an aws_byte_cursor referring to the first len bytes of the original *cursor * is returned. Otherwise, an aws_byte_cursor with ->ptr = NULL, ->len = 0 is * returned. * * Note that if len is above (SIZE_MAX / 2), this function will also treat it as - * a buffer overflow, and return NULL without changing *buf. + * a buffer overflow, and return NULL without changing *cursor. */ AWS_COMMON_API struct aws_byte_cursor aws_byte_cursor_advance(struct aws_byte_cursor *const cursor, const size_t len);