Skip to content

Commit

Permalink
Make aws_byte_cursor_from_string NULL tolerant (#1187)
Browse files Browse the repository at this point in the history
  • Loading branch information
waahm7 authored Feb 12, 2025
1 parent bfa6c85 commit 6401c83
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/aws/common/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ bool aws_byte_buf_write_from_whole_string(

/**
* Creates an aws_byte_cursor from an existing string.
* If the src is NULL, it returns an empty cursor
*/
AWS_COMMON_API
struct aws_byte_cursor aws_byte_cursor_from_string(const struct aws_string *src);
Expand Down
7 changes: 6 additions & 1 deletion source/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,12 @@ bool aws_byte_buf_write_from_whole_string(
* Creates an aws_byte_cursor from an existing string.
*/
struct aws_byte_cursor aws_byte_cursor_from_string(const struct aws_string *src) {
AWS_PRECONDITION(aws_string_is_valid(src));
if (!src) {
struct aws_byte_cursor cursor;
AWS_ZERO_STRUCT(cursor);
return cursor;
}

return aws_byte_cursor_from_array(aws_string_bytes(src), src->len);
}

Expand Down

0 comments on commit 6401c83

Please sign in to comment.