diff --git a/.clang-tidy b/.clang-tidy index 16d3b5dcb..c86531a3b 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -10,6 +10,6 @@ CheckOptions: - key: google-runtime-int.TypeSufix value: '_t' - key: fuchsia-restrict-system-includes.Includes - value: '*,-stdint.h,-stdbool.h' + value: '*,-stdint.h,-stdbool.h,-assert.h' ... diff --git a/bin/elasticurl/main.c b/bin/elasticurl/main.c index 8d2268df9..d070a7e51 100644 --- a/bin/elasticurl/main.c +++ b/bin/elasticurl/main.c @@ -378,7 +378,7 @@ static void s_on_client_connection_setup(struct aws_http_connection *connection, request_options.stream_outgoing_body = s_stream_outgoing_body_fn; } - assert(app_ctx->header_line_count <= 10); + AWS_ASSERT(app_ctx->header_line_count <= 10); for (size_t i = 0; i < app_ctx->header_line_count; ++i) { char *delimiter = memchr(app_ctx->header_lines[i], ':', strlen(app_ctx->header_lines[i])); diff --git a/source/connection.c b/source/connection.c index 139f2de3c..7d92abdee 100644 --- a/source/connection.c +++ b/source/connection.c @@ -168,17 +168,17 @@ static struct aws_http_connection *s_connection_new( } void aws_http_connection_close(struct aws_http_connection *connection) { - assert(connection); + AWS_ASSERT(connection); connection->vtable->close(connection); } bool aws_http_connection_is_open(const struct aws_http_connection *connection) { - assert(connection); + AWS_ASSERT(connection); return connection->vtable->is_open(connection); } void aws_http_connection_release(struct aws_http_connection *connection) { - assert(connection); + AWS_ASSERT(connection); size_t prev_refcount = aws_atomic_fetch_sub(&connection->refcount, 1); if (prev_refcount == 1) { AWS_LOGF_TRACE( @@ -192,7 +192,7 @@ void aws_http_connection_release(struct aws_http_connection *connection) { /* When the channel's refcount reaches 0, it destroys its slots/handlers, which will destroy the connection */ aws_channel_release_hold(connection->channel_slot->channel); } else { - assert(prev_refcount != 0); + AWS_ASSERT(prev_refcount != 0); AWS_LOGF_TRACE( AWS_LS_HTTP_CONNECTION, "id=%p: Connection refcount released, %zu remaining.", @@ -210,7 +210,7 @@ static void s_server_bootstrap_on_accept_channel_setup( void *user_data) { (void)bootstrap; - assert(user_data); + AWS_ASSERT(user_data); struct aws_http_server *server = user_data; bool user_cb_invoked = false; @@ -376,7 +376,7 @@ struct aws_http_server *aws_http_server_new(const struct aws_http_server_options } void aws_http_server_destroy(struct aws_http_server *server) { - assert(server); + AWS_ASSERT(server); if (server->socket) { AWS_LOGF_INFO( @@ -400,7 +400,7 @@ static void s_client_bootstrap_on_channel_setup( void *user_data) { (void)bootstrap; - assert(user_data); + AWS_ASSERT(user_data); struct aws_http_client_connection_impl_options *options = user_data; if (error_code) { diff --git a/source/connection_h1.c b/source/connection_h1.c index f5dab9f5b..67decaad8 100644 --- a/source/connection_h1.c +++ b/source/connection_h1.c @@ -350,7 +350,7 @@ static void s_write_headers(struct aws_byte_buf *dst, const struct aws_http_head wrote_all &= aws_byte_buf_write_u8(dst, '\r'); wrote_all &= aws_byte_buf_write_u8(dst, '\n'); } - assert(wrote_all); + AWS_ASSERT(wrote_all); } struct aws_http_stream *s_new_client_request_stream(const struct aws_http_request_options *options) { @@ -446,7 +446,7 @@ struct aws_http_stream *s_new_client_request_stream(const struct aws_http_reques wrote_all &= aws_byte_buf_write_u8(&stream->outgoing_head_buf, '\r'); wrote_all &= aws_byte_buf_write_u8(&stream->outgoing_head_buf, '\n'); (void)wrote_all; - assert(wrote_all); + AWS_ASSERT(wrote_all); /* Insert new stream into pending list, and schedule outgoing_stream_task if it's not already running. */ bool is_shutting_down = false; @@ -634,7 +634,7 @@ static void s_stream_write_outgoing_data(struct h1_stream *stream, struct aws_io bool success = aws_byte_buf_write(dst, src->buffer + src_progress, transferring); (void)success; - assert(success); + AWS_ASSERT(success); stream->outgoing_head_progress += transferring; @@ -785,7 +785,7 @@ static struct h1_stream *s_update_outgoing_stream_ptr(struct h1_connection *conn /* If it's also done receiving data, then it's complete! */ if (current->is_incoming_message_done) { /* Only 1st stream in list could finish receiving before it finished sending */ - assert(¤t->node == aws_linked_list_begin(&connection->thread_data.stream_list)); + AWS_ASSERT(¤t->node == aws_linked_list_begin(&connection->thread_data.stream_list)); /* This removes stream from list */ s_stream_complete(current, AWS_ERROR_SUCCESS); @@ -969,8 +969,8 @@ static int s_decoder_on_request( struct h1_connection *connection = user_data; struct h1_stream *incoming_stream = connection->thread_data.incoming_stream; - assert(incoming_stream->base.incoming_request_method_str.len == 0); - assert(incoming_stream->base.incoming_request_uri.len == 0); + AWS_ASSERT(incoming_stream->base.incoming_request_method_str.len == 0); + AWS_ASSERT(incoming_stream->base.incoming_request_uri.len == 0); AWS_LOGF_TRACE( AWS_LS_HTTP_STREAM, @@ -981,7 +981,7 @@ static int s_decoder_on_request( /* Copy strings to internal buffer */ struct aws_byte_buf *storage_buf = &incoming_stream->incoming_storage_buf; - assert(storage_buf->capacity == 0); + AWS_ASSERT(storage_buf->capacity == 0); size_t storage_size = 0; int err = aws_add_size_checked(uri->len, method_str->len, &storage_size); @@ -1098,7 +1098,7 @@ static int s_decoder_on_body(const struct aws_byte_cursor *data, bool finished, struct h1_connection *connection = user_data; struct h1_stream *incoming_stream = connection->thread_data.incoming_stream; - assert(incoming_stream); + AWS_ASSERT(incoming_stream); int err = s_mark_head_done(incoming_stream); if (err) { @@ -1117,7 +1117,7 @@ static int s_decoder_on_body(const struct aws_byte_cursor *data, bool finished, /* If user reduced window_update_size, reduce how much the connection will update its window. */ if (window_update_size < data->len) { size_t reduce = data->len - window_update_size; - assert(reduce <= connection->thread_data.incoming_message_window_update); + AWS_ASSERT(reduce <= connection->thread_data.incoming_message_window_update); connection->thread_data.incoming_message_window_update -= reduce; AWS_LOGF_DEBUG( @@ -1139,7 +1139,7 @@ static int s_decoder_on_body(const struct aws_byte_cursor *data, bool finished, static int s_decoder_on_done(void *user_data) { struct h1_connection *connection = user_data; struct h1_stream *incoming_stream = connection->thread_data.incoming_stream; - assert(incoming_stream); + AWS_ASSERT(incoming_stream); /* Ensure head was marked done */ int err = s_mark_head_done(incoming_stream); @@ -1150,7 +1150,7 @@ static int s_decoder_on_done(void *user_data) { incoming_stream->is_incoming_message_done = true; if (incoming_stream->outgoing_state == STREAM_OUTGOING_STATE_DONE) { - assert(&incoming_stream->node == aws_linked_list_begin(&connection->thread_data.stream_list)); + AWS_ASSERT(&incoming_stream->node == aws_linked_list_begin(&connection->thread_data.stream_list)); s_stream_complete(incoming_stream, AWS_ERROR_SUCCESS); @@ -1260,8 +1260,8 @@ static void s_handler_destroy(struct aws_channel_handler *handler) { AWS_LOGF_TRACE(AWS_LS_HTTP_CONNECTION, "id=%p: Destroying connection.", (void *)&connection->base); - assert(aws_linked_list_empty(&connection->thread_data.stream_list)); - assert(aws_linked_list_empty(&connection->synced_data.pending_stream_list)); + AWS_ASSERT(aws_linked_list_empty(&connection->thread_data.stream_list)); + AWS_ASSERT(aws_linked_list_empty(&connection->synced_data.pending_stream_list)); aws_http_decoder_destroy(connection->thread_data.incoming_stream_decoder); aws_mutex_clean_up(&connection->synced_data.lock); @@ -1366,7 +1366,7 @@ static int s_handler_process_write_message( (void)handler; (void)slot; (void)message; - assert(false); /* Should not be called until websocket stuff comes along. */ + AWS_ASSERT(false); /* Should not be called until websocket stuff comes along. */ return aws_raise_error(AWS_ERROR_UNIMPLEMENTED); } @@ -1378,7 +1378,7 @@ static int s_handler_increment_read_window( (void)handler; (void)slot; (void)size; - assert(false); /* Should not be called until websocket stuff comes along. */ + AWS_ASSERT(false); /* Should not be called until websocket stuff comes along. */ return aws_raise_error(AWS_ERROR_UNIMPLEMENTED); } diff --git a/source/decode.c b/source/decode.c index fe7c03646..6f9a005ab 100644 --- a/source/decode.c +++ b/source/decode.c @@ -18,8 +18,6 @@ #include #include -#include - AWS_STATIC_STRING_FROM_LITERAL(s_transfer_coding_chunked, "chunked"); AWS_STATIC_STRING_FROM_LITERAL(s_transfer_coding_compress, "compress"); AWS_STATIC_STRING_FROM_LITERAL(s_transfer_coding_x_compress, "x-compress"); @@ -83,7 +81,7 @@ static struct aws_byte_cursor s_trim_whitespace(struct aws_byte_cursor cursor) { } static bool s_scan_for_crlf(struct aws_http_decoder *decoder, struct aws_byte_cursor input, size_t *bytes_processed) { - assert(input.len > 0); + AWS_ASSERT(input.len > 0); /* In a loop, scan for "\n", then look one char back for "\r" */ uint8_t *ptr = input.ptr; @@ -235,7 +233,7 @@ static int s_state_getline(struct aws_http_decoder *decoder, struct aws_byte_cur /* Backup so "\r\n" is not included. */ /* RFC-7230 section 3 Message Format */ - assert(line.len >= 2); + AWS_ASSERT(line.len >= 2); line.len -= 2; return decoder->process_line(decoder, line); @@ -381,7 +379,7 @@ static int s_linestate_chunk_terminator(struct aws_http_decoder *decoder, struct static int s_state_chunk(struct aws_http_decoder *decoder, struct aws_byte_cursor input, size_t *bytes_processed) { size_t processed_bytes = 0; - assert(decoder->chunk_processed < decoder->chunk_size); + AWS_ASSERT(decoder->chunk_processed < decoder->chunk_size); if ((decoder->chunk_processed + input.len) > decoder->chunk_size) { processed_bytes = decoder->chunk_size - decoder->chunk_processed; @@ -735,7 +733,7 @@ static int s_linestate_response(struct aws_http_decoder *decoder, struct aws_byt } struct aws_http_decoder *aws_http_decoder_new(struct aws_http_decoder_params *params) { - assert(params); + AWS_ASSERT(params); struct aws_http_decoder *decoder = aws_mem_acquire(params->alloc, sizeof(struct aws_http_decoder)); if (!decoder) { @@ -761,8 +759,8 @@ void aws_http_decoder_destroy(struct aws_http_decoder *decoder) { } int aws_http_decode(struct aws_http_decoder *decoder, const void *data, size_t data_bytes, size_t *bytes_read) { - assert(decoder); - assert(data); + AWS_ASSERT(decoder); + AWS_ASSERT(data); struct aws_byte_cursor input = aws_byte_cursor_from_array(data, data_bytes); size_t total_bytes_processed = 0; diff --git a/source/hpack.c b/source/hpack.c index 190f4514a..bb5e5128f 100644 --- a/source/hpack.c +++ b/source/hpack.c @@ -23,12 +23,10 @@ #include #include -#include - struct aws_huffman_symbol_coder *hpack_get_coder(void); int aws_hpack_encode_integer(uint64_t integer, uint8_t prefix_size, struct aws_byte_buf *output) { - assert(prefix_size <= 8); + AWS_ASSERT(prefix_size <= 8); const struct aws_byte_buf output_backup = *output; @@ -78,8 +76,8 @@ int aws_hpack_encode_integer(uint64_t integer, uint8_t prefix_size, struct aws_b } int aws_hpack_decode_integer(struct aws_byte_cursor *to_decode, uint8_t prefix_size, uint64_t *integer) { - assert(prefix_size <= 8); - assert(integer); + AWS_ASSERT(prefix_size <= 8); + AWS_ASSERT(integer); const struct aws_byte_cursor to_decode_backup = *to_decode; @@ -91,7 +89,7 @@ int aws_hpack_decode_integer(struct aws_byte_cursor *to_decode, uint8_t prefix_s uint8_t byte = 0; if (!aws_byte_cursor_read_u8(to_decode, &byte)) { - assert(false); /* Look 8 lines up */ + AWS_ASSERT(false); /* Look 8 lines up */ return aws_raise_error(AWS_ERROR_SHORT_BUFFER); } /* Cut the prefix */ @@ -273,7 +271,7 @@ struct aws_http_header *aws_hpack_get_header(struct aws_hpack_context *context, /* Check dynamic table */ index -= s_static_header_table_size; - assert(index < context->dynamic_table.num_elements); + AWS_ASSERT(index < context->dynamic_table.num_elements); return &context->dynamic_table .buffer[(context->dynamic_table.index_0 + index) % context->dynamic_table.max_elements]; } diff --git a/source/hpack_huffman_static.c b/source/hpack_huffman_static.c index d741d35ee..f11e4a460 100644 --- a/source/hpack_huffman_static.c +++ b/source/hpack_huffman_static.c @@ -18,7 +18,6 @@ #include -#include static struct aws_huffman_code code_points[] = { { .pattern = 0x1ff8, .num_bits = 13 }, /* ' ' 0 */ { .pattern = 0x7fffd8, .num_bits = 23 }, /* ' ' 1 */ diff --git a/source/http.c b/source/http.c index 260d329bd..412f3a37e 100644 --- a/source/http.c +++ b/source/http.c @@ -19,7 +19,6 @@ #include #include -#include #include #ifdef _MSC_VER diff --git a/source/request_response.c b/source/request_response.c index 5c08291b8..a81df417d 100644 --- a/source/request_response.c +++ b/source/request_response.c @@ -41,7 +41,7 @@ struct aws_http_stream *aws_http_stream_new_client_request(const struct aws_http } void aws_http_stream_release(struct aws_http_stream *stream) { - assert(stream); + AWS_ASSERT(stream); size_t prev_refcount = aws_atomic_fetch_sub(&stream->refcount, 1); if (prev_refcount == 1) { @@ -53,19 +53,19 @@ void aws_http_stream_release(struct aws_http_stream *stream) { /* Connection needed to outlive stream, but it's free to go now */ aws_http_connection_release(owning_connection); } else { - assert(prev_refcount != 0); + AWS_ASSERT(prev_refcount != 0); AWS_LOGF_TRACE( AWS_LS_HTTP_STREAM, "id=%p: Stream refcount released, %zu remaining.", (void *)stream, prev_refcount - 1); } } struct aws_http_connection *aws_http_stream_get_connection(const struct aws_http_stream *stream) { - assert(stream); + AWS_ASSERT(stream); return stream->owning_connection; } int aws_http_stream_get_incoming_response_status(const struct aws_http_stream *stream, int *out_status) { - assert(stream); + AWS_ASSERT(stream); if (stream->incoming_response_status == (int)AWS_HTTP_STATUS_UNKNOWN) { AWS_LOGF_ERROR(AWS_LS_HTTP_STREAM, "id=%p: Status code not yet received.", (void *)stream); @@ -80,7 +80,7 @@ int aws_http_stream_get_incoming_request_method( const struct aws_http_stream *stream, struct aws_byte_cursor *out_method) { - assert(stream); + AWS_ASSERT(stream); if (!stream->incoming_request_method_str.ptr) { AWS_LOGF_ERROR(AWS_LS_HTTP_STREAM, "id=%p: Request method not yet received.", (void *)stream); @@ -92,7 +92,7 @@ int aws_http_stream_get_incoming_request_method( } int aws_http_stream_get_incoming_request_uri(const struct aws_http_stream *stream, struct aws_byte_cursor *out_uri) { - assert(stream); + AWS_ASSERT(stream); if (!stream->incoming_request_uri.ptr) { AWS_LOGF_ERROR(AWS_LS_HTTP_STREAM, "id=%p: Request URI not yet received.", (void *)stream); diff --git a/source/websocket.c b/source/websocket.c index 4e8f4d977..9c3fa8192 100644 --- a/source/websocket.c +++ b/source/websocket.c @@ -250,8 +250,8 @@ struct aws_channel_handler *aws_websocket_handler_new(const struct aws_websocket static void s_handler_destroy(struct aws_channel_handler *handler) { struct aws_websocket *websocket = handler->impl; - assert(!websocket->thread_data.current_outgoing_frame); - assert(!websocket->thread_data.current_incoming_frame); + AWS_ASSERT(!websocket->thread_data.current_outgoing_frame); + AWS_ASSERT(!websocket->thread_data.current_incoming_frame); AWS_LOGF_TRACE(AWS_LS_HTTP_WEBSOCKET, "id=%p: Destroying websocket.", (void *)websocket); @@ -274,8 +274,8 @@ void aws_websocket_acquire_hold(struct aws_websocket *websocket) { } void aws_websocket_release_hold(struct aws_websocket *websocket) { - assert(websocket); - assert(websocket->channel_slot); + AWS_ASSERT(websocket); + AWS_ASSERT(websocket->channel_slot); size_t prev_refcount = aws_atomic_fetch_sub(&websocket->refcount, 1); if (prev_refcount == 1) { @@ -291,7 +291,7 @@ void aws_websocket_release_hold(struct aws_websocket *websocket) { aws_channel_release_hold(websocket->channel_slot->channel); } else { - assert(prev_refcount != 0); + AWS_ASSERT(prev_refcount != 0); AWS_LOGF_TRACE( AWS_LS_HTTP_WEBSOCKET, @@ -319,8 +319,8 @@ static void s_enqueue_prioritized_frame(struct aws_linked_list *list, struct out int aws_websocket_send_frame(struct aws_websocket *websocket, const struct aws_websocket_send_frame_options *options) { - assert(websocket); - assert(options); + AWS_ASSERT(websocket); + AWS_ASSERT(options); /* Check for bad input. Log about non-obvious errors. */ if (options->high_priority && aws_websocket_is_data_frame(options->opcode)) { @@ -349,7 +349,7 @@ int aws_websocket_send_frame(struct aws_websocket *websocket, const struct aws_w /* BEGIN CRITICAL SECTION */ int err = aws_mutex_lock(&websocket->synced_data.lock); - assert(!err); + AWS_ASSERT(!err); (void)err; if (websocket->synced_data.send_frame_error_code) { @@ -363,7 +363,7 @@ int aws_websocket_send_frame(struct aws_websocket *websocket, const struct aws_w } err = aws_mutex_unlock(&websocket->synced_data.lock); - assert(!err); + AWS_ASSERT(!err); (void)err; /* END CRITICAL SECTION */ @@ -410,7 +410,7 @@ static void s_move_synced_data_to_thread_task(struct aws_channel_task *task, voi /* BEGIN CRITICAL SECTION */ int err = aws_mutex_lock(&websocket->synced_data.lock); - assert(!err); + AWS_ASSERT(!err); (void)err; aws_linked_list_swap_contents(&websocket->synced_data.outgoing_frame_list, &tmp_list); @@ -418,7 +418,7 @@ static void s_move_synced_data_to_thread_task(struct aws_channel_task *task, voi websocket->synced_data.is_move_synced_data_to_thread_task_scheduled = false; err = aws_mutex_unlock(&websocket->synced_data.lock); - assert(!err); + AWS_ASSERT(!err); (void)err; /* END CRITICAL SECTION */ @@ -434,7 +434,7 @@ static void s_move_synced_data_to_thread_task(struct aws_channel_task *task, voi } static void s_try_write_outgoing_frames(struct aws_websocket *websocket) { - assert(aws_channel_thread_is_callers_thread(websocket->channel_slot->channel)); + AWS_ASSERT(aws_channel_thread_is_callers_thread(websocket->channel_slot->channel)); /* Check whether we should be writing data */ if (!websocket->thread_data.current_outgoing_frame && @@ -635,11 +635,11 @@ static void s_try_write_outgoing_frames(struct aws_websocket *websocket) { /* Encoder's outgoing_payload callback invokes current frame's callback */ static int s_encoder_stream_outgoing_payload(struct aws_byte_buf *out_buf, bool *out_done, void *user_data) { struct aws_websocket *websocket = user_data; - assert(aws_channel_thread_is_callers_thread(websocket->channel_slot->channel)); - assert(websocket->thread_data.current_outgoing_frame); + AWS_ASSERT(aws_channel_thread_is_callers_thread(websocket->channel_slot->channel)); + AWS_ASSERT(websocket->thread_data.current_outgoing_frame); struct outgoing_frame *current_frame = websocket->thread_data.current_outgoing_frame; - assert(current_frame->def.stream_outgoing_payload); + AWS_ASSERT(current_frame->def.stream_outgoing_payload); enum aws_websocket_outgoing_payload_state payload_state = current_frame->def.stream_outgoing_payload(websocket, out_buf, current_frame->def.user_data); @@ -659,7 +659,7 @@ static void s_io_message_write_completed( (void)channel; (void)message; struct aws_websocket *websocket = user_data; - assert(aws_channel_thread_is_callers_thread(channel)); + AWS_ASSERT(aws_channel_thread_is_callers_thread(channel)); if (err_code == AWS_ERROR_SUCCESS) { AWS_LOGF_TRACE( @@ -710,8 +710,8 @@ static void s_destroy_outgoing_frame(struct aws_websocket *websocket, struct out } static void s_stop_writing(struct aws_websocket *websocket, int send_frame_error_code) { - assert(aws_channel_thread_is_callers_thread(websocket->channel_slot->channel)); - assert(send_frame_error_code != AWS_ERROR_SUCCESS); + AWS_ASSERT(aws_channel_thread_is_callers_thread(websocket->channel_slot->channel)); + AWS_ASSERT(send_frame_error_code != AWS_ERROR_SUCCESS); if (websocket->thread_data.is_writing_stopped) { return; @@ -726,13 +726,13 @@ static void s_stop_writing(struct aws_websocket *websocket, int send_frame_error /* BEGIN CRITICAL SECTION */ int err = aws_mutex_lock(&websocket->synced_data.lock); - assert(!err); + AWS_ASSERT(!err); (void)err; websocket->synced_data.send_frame_error_code = send_frame_error_code; err = aws_mutex_unlock(&websocket->synced_data.lock); - assert(!err); + AWS_ASSERT(!err); (void)err; /* END CRITICAL SECTION */ @@ -740,7 +740,7 @@ static void s_stop_writing(struct aws_websocket *websocket, int send_frame_error } static void s_shutdown_due_to_write_err(struct aws_websocket *websocket, int error_code) { - assert(aws_channel_thread_is_callers_thread(websocket->channel_slot->channel)); + AWS_ASSERT(aws_channel_thread_is_callers_thread(websocket->channel_slot->channel)); /* No more writing allowed (it's ok to call this redundantly). */ s_stop_writing(websocket, AWS_ERROR_HTTP_CONNECTION_CLOSED); @@ -768,7 +768,7 @@ static void s_shutdown_due_to_write_err(struct aws_websocket *websocket, int err } static void s_shutdown_due_to_read_err(struct aws_websocket *websocket, int error_code) { - assert(aws_channel_thread_is_callers_thread(websocket->channel_slot->channel)); + AWS_ASSERT(aws_channel_thread_is_callers_thread(websocket->channel_slot->channel)); AWS_LOGF_ERROR( AWS_LS_HTTP_WEBSOCKET, @@ -795,7 +795,7 @@ static int s_handler_shutdown( int error_code, bool free_scarce_resources_immediately) { - assert(aws_channel_thread_is_callers_thread(slot->channel)); + AWS_ASSERT(aws_channel_thread_is_callers_thread(slot->channel)); struct aws_websocket *websocket = handler->impl; int err; @@ -857,9 +857,9 @@ static int s_handler_shutdown( } static void s_finish_shutdown(struct aws_websocket *websocket) { - assert(aws_channel_thread_is_callers_thread(websocket->channel_slot->channel)); - assert(websocket->thread_data.is_writing_stopped); - assert(websocket->thread_data.is_shutting_down_and_waiting_for_close_frame_to_be_written); + AWS_ASSERT(aws_channel_thread_is_callers_thread(websocket->channel_slot->channel)); + AWS_ASSERT(websocket->thread_data.is_writing_stopped); + AWS_ASSERT(websocket->thread_data.is_shutting_down_and_waiting_for_close_frame_to_be_written); AWS_LOGF_TRACE(AWS_LS_HTTP_WEBSOCKET, "id=%p: Finishing websocket handler shutdown.", (void *)websocket); @@ -878,7 +878,7 @@ static void s_finish_shutdown(struct aws_websocket *websocket) { /* BEGIN CRITICAL SECTION */ int err = aws_mutex_lock(&websocket->synced_data.lock); - assert(!err); + AWS_ASSERT(!err); (void)err; while (!aws_linked_list_empty(&websocket->synced_data.outgoing_frame_list)) { @@ -888,7 +888,7 @@ static void s_finish_shutdown(struct aws_websocket *websocket) { } err = aws_mutex_unlock(&websocket->synced_data.lock); - assert(!err); + AWS_ASSERT(!err); (void)err; /* END CRITICAL SECTION */ @@ -916,8 +916,8 @@ static int s_handler_process_read_message( struct aws_channel_slot *slot, struct aws_io_message *message) { - assert(message); - assert(aws_channel_thread_is_callers_thread(slot->channel)); + AWS_ASSERT(message); + AWS_ASSERT(aws_channel_thread_is_callers_thread(slot->channel)); struct aws_websocket *websocket = handler->impl; struct aws_byte_cursor cursor = aws_byte_cursor_from_buf(&message->message_data); int err; @@ -987,9 +987,9 @@ static int s_handler_process_read_message( static int s_decoder_on_frame(const struct aws_websocket_frame *frame, void *user_data) { struct aws_websocket *websocket = user_data; - assert(aws_channel_thread_is_callers_thread(websocket->channel_slot->channel)); - assert(!websocket->thread_data.current_incoming_frame); - assert(!websocket->thread_data.is_reading_stopped); + AWS_ASSERT(aws_channel_thread_is_callers_thread(websocket->channel_slot->channel)); + AWS_ASSERT(!websocket->thread_data.current_incoming_frame); + AWS_ASSERT(!websocket->thread_data.is_reading_stopped); websocket->thread_data.current_incoming_frame = &websocket->thread_data.incoming_frame_storage; @@ -1016,9 +1016,9 @@ static int s_decoder_on_frame(const struct aws_websocket_frame *frame, void *use static int s_decoder_on_payload(struct aws_byte_cursor data, void *user_data) { struct aws_websocket *websocket = user_data; - assert(aws_channel_thread_is_callers_thread(websocket->channel_slot->channel)); - assert(websocket->thread_data.current_incoming_frame); - assert(!websocket->thread_data.is_reading_stopped); + AWS_ASSERT(aws_channel_thread_is_callers_thread(websocket->channel_slot->channel)); + AWS_ASSERT(websocket->thread_data.current_incoming_frame); + AWS_ASSERT(!websocket->thread_data.is_reading_stopped); /* Invoke user cb */ if (websocket->on_incoming_frame_payload) { @@ -1029,7 +1029,7 @@ static int s_decoder_on_payload(struct aws_byte_cursor data, void *user_data) { /* If user reduced window_udpate_size, reduce how much the websocket will update its window */ size_t reduce = data.len - window_update_size; - assert(reduce <= websocket->thread_data.incoming_message_window_update); + AWS_ASSERT(reduce <= websocket->thread_data.incoming_message_window_update); websocket->thread_data.incoming_message_window_update -= reduce; AWS_LOGF_DEBUG( @@ -1050,8 +1050,8 @@ static int s_decoder_on_payload(struct aws_byte_cursor data, void *user_data) { } static void s_complete_incoming_frame(struct aws_websocket *websocket, int error_code) { - assert(aws_channel_thread_is_callers_thread(websocket->channel_slot->channel)); - assert(websocket->thread_data.current_incoming_frame); + AWS_ASSERT(aws_channel_thread_is_callers_thread(websocket->channel_slot->channel)); + AWS_ASSERT(websocket->thread_data.current_incoming_frame); if (error_code == AWS_OP_SUCCESS) { /* If this was a CLOSE frame, don't read any more data. */ diff --git a/source/websocket_decoder.c b/source/websocket_decoder.c index 697101215..acdd862ed 100644 --- a/source/websocket_decoder.c +++ b/source/websocket_decoder.c @@ -130,7 +130,7 @@ static int s_state_extended_length(struct aws_websocket_decoder *decoder, struct min_acceptable_value = AWS_WEBSOCKET_2BYTE_EXTENDED_LENGTH_MIN_VALUE; max_acceptable_value = AWS_WEBSOCKET_2BYTE_EXTENDED_LENGTH_MAX_VALUE; } else { - assert(decoder->current_frame.payload_length == AWS_WEBSOCKET_7BIT_VALUE_FOR_8BYTE_EXTENDED_LENGTH); + AWS_ASSERT(decoder->current_frame.payload_length == AWS_WEBSOCKET_7BIT_VALUE_FOR_8BYTE_EXTENDED_LENGTH); total_bytes_extended_length = 8; min_acceptable_value = AWS_WEBSOCKET_8BYTE_EXTENDED_LENGTH_MIN_VALUE; @@ -138,12 +138,12 @@ static int s_state_extended_length(struct aws_websocket_decoder *decoder, struct } /* Copy bytes of extended-length to state_cache, we'll process them later.*/ - assert(total_bytes_extended_length > decoder->state_bytes_processed); + AWS_ASSERT(total_bytes_extended_length > decoder->state_bytes_processed); size_t remaining_bytes = (size_t)(total_bytes_extended_length - decoder->state_bytes_processed); size_t bytes_to_consume = remaining_bytes <= data->len ? remaining_bytes : data->len; - assert(bytes_to_consume + decoder->state_bytes_processed <= sizeof(decoder->state_cache)); + AWS_ASSERT(bytes_to_consume + decoder->state_bytes_processed <= sizeof(decoder->state_cache)); memcpy(decoder->state_cache + decoder->state_bytes_processed, data->ptr, bytes_to_consume); @@ -203,7 +203,7 @@ static int s_state_masking_key(struct aws_websocket_decoder *decoder, struct aws return AWS_OP_SUCCESS; } - assert(4 > decoder->state_bytes_processed); + AWS_ASSERT(4 > decoder->state_bytes_processed); size_t bytes_remaining = 4 - (size_t)decoder->state_bytes_processed; size_t bytes_to_consume = bytes_remaining < data->len ? bytes_remaining : data->len; @@ -247,7 +247,7 @@ static int s_state_payload(struct aws_websocket_decoder *decoder, struct aws_byt return AWS_OP_SUCCESS; } - assert(decoder->current_frame.payload_length > decoder->state_bytes_processed); + AWS_ASSERT(decoder->current_frame.payload_length > decoder->state_bytes_processed); uint64_t bytes_remaining = decoder->current_frame.payload_length - decoder->state_bytes_processed; size_t bytes_to_consume = bytes_remaining < data->len ? (size_t)bytes_remaining : data->len; @@ -277,7 +277,7 @@ static int s_state_payload(struct aws_websocket_decoder *decoder, struct aws_byt } decoder->state_bytes_processed += payload.len; - assert(decoder->state_bytes_processed <= decoder->current_frame.payload_length); + AWS_ASSERT(decoder->state_bytes_processed <= decoder->current_frame.payload_length); /* If all data consumed, proceed to next state. */ if (decoder->state_bytes_processed == decoder->current_frame.payload_length) { @@ -314,7 +314,7 @@ int aws_websocket_decoder_process( } if (decoder->state == prev_state) { - assert(data->len == 0); /* If no more work to do, all possible data should have been consumed */ + AWS_ASSERT(data->len == 0); /* If no more work to do, all possible data should have been consumed */ break; } } diff --git a/source/websocket_encoder.c b/source/websocket_encoder.c index 946c50790..ad3a150e3 100644 --- a/source/websocket_encoder.c +++ b/source/websocket_encoder.c @@ -36,7 +36,7 @@ static int s_state_init(struct aws_websocket_encoder *encoder, struct aws_byte_b /* STATE_OPCODE_BYTE: Outputs 1st byte of frame, which is packed with goodies. */ static int s_state_opcode_byte(struct aws_websocket_encoder *encoder, struct aws_byte_buf *out_buf) { - assert((encoder->frame.opcode & 0xF0) == 0); /* Should be impossible, the opcode was checked in start_frame() */ + AWS_ASSERT((encoder->frame.opcode & 0xF0) == 0); /* Should be impossible, the opcode was checked in start_frame() */ /* Right 4 bits are opcode, left 4 bits are fin|rsv1|rsv2|rsv3 */ uint8_t byte = encoder->frame.opcode; @@ -69,7 +69,7 @@ static int s_state_length_byte(struct aws_websocket_encoder *encoder, struct aws byte |= AWS_WEBSOCKET_7BIT_VALUE_FOR_2BYTE_EXTENDED_LENGTH; extended_length_required = true; } else { - assert(encoder->frame.payload_length <= AWS_WEBSOCKET_8BYTE_EXTENDED_LENGTH_MAX_VALUE); + AWS_ASSERT(encoder->frame.payload_length <= AWS_WEBSOCKET_8BYTE_EXTENDED_LENGTH_MAX_VALUE); byte |= AWS_WEBSOCKET_7BIT_VALUE_FOR_8BYTE_EXTENDED_LENGTH; extended_length_required = true; } @@ -271,7 +271,7 @@ int aws_websocket_encoder_process(struct aws_websocket_encoder *encoder, struct if (prev_state == encoder->state) { /* dev-assert: Check that each state is doing as much work as it possibly can. * Except for the PAYLOAD state, where it's up to the user to fill the buffer. */ - assert((out_buf->len == out_buf->capacity) || (encoder->state == AWS_WEBSOCKET_ENCODER_STATE_PAYLOAD)); + AWS_ASSERT((out_buf->len == out_buf->capacity) || (encoder->state == AWS_WEBSOCKET_ENCODER_STATE_PAYLOAD)); break; } @@ -348,8 +348,8 @@ void aws_websocket_encoder_init( uint64_t aws_websocket_frame_encoded_size(const struct aws_websocket_frame *frame) { /* This is an internal function, so asserts are sufficient error handling */ - assert(frame); - assert(frame->payload_length <= AWS_WEBSOCKET_8BYTE_EXTENDED_LENGTH_MAX_VALUE); + AWS_ASSERT(frame); + AWS_ASSERT(frame->payload_length <= AWS_WEBSOCKET_8BYTE_EXTENDED_LENGTH_MAX_VALUE); /* All frames start with at least 2 bytes */ uint64_t total = 2; diff --git a/tests/test_decode.c b/tests/test_decode.c index 6e116868f..910cc70c4 100644 --- a/tests/test_decode.c +++ b/tests/test_decode.c @@ -79,7 +79,7 @@ static int s_on_request( void *user_data) { struct request_data *request_data = (struct request_data *)user_data; - assert(sizeof(request_data->buffer) >= uri->len + method_str->len); + AWS_ASSERT(sizeof(request_data->buffer) >= uri->len + method_str->len); if (request_data) { request_data->method_enum = method_enum;