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); 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; }