From 56fb0b774a8e89be1cb7ab1e5f464bbedd19fb22 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Sat, 11 Jun 2022 19:12:43 +0300 Subject: fix ubsan warning in release mode --- lib/ubsan.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) (limited to 'lib') diff --git a/lib/ubsan.c b/lib/ubsan.c index f296b7a..d3e363e 100644 --- a/lib/ubsan.c +++ b/lib/ubsan.c @@ -12,6 +12,9 @@ #include #include +#if defined(DEBUG) +/* ubsan is only sensible if we're in debug mode. */ + /** * Describes a source file location. */ @@ -163,7 +166,7 @@ inline static void print_location(const char *message, * * @param data Overflow information, generated by the compiler. */ -void __ubsan_handle_add_overflow(struct overflow_data *data) +void __ubsan_handle_add_overflow(const struct overflow_data *data) { print_location("addition overflow", data->location); } @@ -173,7 +176,7 @@ void __ubsan_handle_add_overflow(struct overflow_data *data) * * @param data Overflow information, generated by the compiler. */ -void __ubsan_handle_sub_overflow(struct overflow_data *data) +void __ubsan_handle_sub_overflow(const struct overflow_data *data) { print_location("subtraction overflow", data->location); } @@ -183,7 +186,7 @@ void __ubsan_handle_sub_overflow(struct overflow_data *data) * * @param data Overflow information, generated by the compiler. */ -void __ubsan_handle_mul_overflow(struct overflow_data *data) +void __ubsan_handle_mul_overflow(const struct overflow_data *data) { print_location("multiplication overflow", data->location); } @@ -193,7 +196,7 @@ void __ubsan_handle_mul_overflow(struct overflow_data *data) * * @param data Overflow information, generated by the compiler. */ -void __ubsan_handle_divrem_overflow(struct overflow_data *data) +void __ubsan_handle_divrem_overflow(const struct overflow_data *data) { print_location("division overflow", data->location); } @@ -203,7 +206,7 @@ void __ubsan_handle_divrem_overflow(struct overflow_data *data) * * @param data Overflow information, generated by the compiler. */ -void __ubsan_handle_negate_overflow(struct overflow_data *data) +void __ubsan_handle_negate_overflow(const struct overflow_data *data) { print_location("negation overflow", data->location); } @@ -213,7 +216,7 @@ void __ubsan_handle_negate_overflow(struct overflow_data *data) * * @param data Overflow information, generated by the compiler. */ -void __ubsan_handle_pointer_overflow(struct overflow_data *data) +void __ubsan_handle_pointer_overflow(const struct overflow_data *data) { print_location("pointer overflow", data->location); } @@ -223,8 +226,7 @@ void __ubsan_handle_pointer_overflow(struct overflow_data *data) * * @param data Out of bounds information, generated by the compiler. */ -void __ubsan_handle_shift_out_of_bounds( - struct shift_out_of_bounds_data *data) +void __ubsan_handle_shift_out_of_bounds(const struct shift_out_of_bounds_data *data) { print_location("shift out of bounds", data->location); } @@ -234,7 +236,7 @@ void __ubsan_handle_shift_out_of_bounds( * * @param data Load information, generated by the compiler. */ -void __ubsan_handle_load_invalid_value(struct invalid_value_data *data) +void __ubsan_handle_load_invalid_value(const struct invalid_value_data *data) { print_location("invalid load value", data->location); } @@ -244,7 +246,7 @@ void __ubsan_handle_load_invalid_value(struct invalid_value_data *data) * * @param data Out of bounds information, generated by the compiler. */ -void __ubsan_handle_out_of_bounds(struct array_out_of_bounds_data *data) +void __ubsan_handle_out_of_bounds(const struct array_out_of_bounds_data *data) { print_location("array out of bounds", data->location); } @@ -255,7 +257,7 @@ void __ubsan_handle_out_of_bounds(struct array_out_of_bounds_data *data) * @param data Type mismatch information, generated by the compiler. * @param ptr Pointer that caused a mismatch. */ -void __ubsan_handle_type_mismatch_v1(struct type_mismatch_v1_data *data, +void __ubsan_handle_type_mismatch_v1(const struct type_mismatch_v1_data *data, uintptr_t ptr) { if (!ptr) { @@ -274,7 +276,7 @@ void __ubsan_handle_type_mismatch_v1(struct type_mismatch_v1_data *data, * * @param data VLA information, generated by the compiler. */ -void __ubsan_handle_vla_bound_not_positive(struct negative_vla_data *data) +void __ubsan_handle_vla_bound_not_positive(const struct negative_vla_data *data) { print_location("variable-length argument is negative", data->location); @@ -285,7 +287,7 @@ void __ubsan_handle_vla_bound_not_positive(struct negative_vla_data *data) * * @param data Return information, generated by compiler. */ -void __ubsan_handle_nonnull_return(struct nonnull_return_data *data) +void __ubsan_handle_nonnull_return(const struct nonnull_return_data *data) { print_location("non-null return is null", data->location); } @@ -295,7 +297,7 @@ void __ubsan_handle_nonnull_return(struct nonnull_return_data *data) * * @param data Argument information, generated by compiler. */ -void __ubsan_handle_nonnull_arg(struct nonnull_arg_data *data) +void __ubsan_handle_nonnull_arg(const struct nonnull_arg_data *data) { print_location("non-null argument is null", data->location); } @@ -305,7 +307,7 @@ void __ubsan_handle_nonnull_arg(struct nonnull_arg_data *data) * * @param data Unreachable code information, generated by compiler. */ -void __ubsan_handle_builtin_unreachable(struct unreachable_data *data) +void __ubsan_handle_builtin_unreachable(const struct unreachable_data *data) { print_location("unreachable code reached", data->location); } @@ -315,7 +317,9 @@ void __ubsan_handle_builtin_unreachable(struct unreachable_data *data) * * @param data Builtin information, generated by compiler. */ -void __ubsan_handle_invalid_builtin(struct invalid_builtin_data *data) +void __ubsan_handle_invalid_builtin(const struct invalid_builtin_data *data) { print_location("invalid builtin", data->location); } + +#endif -- cgit v1.3