From 4f70f527c27a774144996e576c1e547c64ffd02c Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 27 Jun 2023 18:08:19 +0200 Subject: [PATCH] android: Fix compiler warning from GCC MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This ignores the following two warnings from the compiler. CC android/gatt.o android/gatt.c: In function ‘handle_client_register_for_notification’: android/gatt.c:3733:9: error: ‘memcpy’ offset [0, 16] is out of the bounds [0, 0] [-Werror=array-bounds=] 3733 | memcpy(¬ification->ch, &cmd->char_id, sizeof(notification->ch)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CC android/gatt.o android/gatt.c: In function ‘handle_client_register_for_notification’: android/gatt.c:3735:9: error: ‘memcpy’ writing 17 bytes into a region of size 0 overflows the destination [-Werror=stringop-overflow=] 3735 | memcpy(¬ification->ch, &cmd->char_id, sizeof(notification->ch)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ It could be possible that these warnings are valid or they might be a false positive. However since this is Android based code based on Android HAL headers, just set pragma to ignore them. --- android/gatt.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/android/gatt.c b/android/gatt.c index e0e43d2..9af4aed 100755 --- a/android/gatt.c +++ b/android/gatt.c @@ -3729,7 +3729,11 @@ static void handle_client_register_for_notification(const void *buf, notification = new0(struct notification_data, 1); +_Pragma("GCC diagnostic push") +_Pragma("GCC diagnostic ignored \"-Warray-bounds\"") +_Pragma("GCC diagnostic ignored \"-Wstringop-overflow\"") memcpy(¬ification->ch, &cmd->char_id, sizeof(notification->ch)); +_Pragma("GCC diagnostic pop") memcpy(¬ification->service, &cmd->srvc_id, sizeof(notification->service)); notification->conn = conn; -- 2.7.4