File disambiguate-unterminated-strings.patch of Package readsb

From 77296c980154b555e6f08272e0c315cb6aa542f7 Mon Sep 17 00:00:00 2001
From: "Eugenio Paolantonio (g7)" <me@medesimo.eu>
Date: Sun, 20 Jul 2025 23:33:03 +0200
Subject: [PATCH 1/3] net_io: use global ais_charset definition

Signed-off-by: Eugenio Paolantonio (g7) <me@medesimo.eu>
---
 net_io.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net_io.c b/net_io.c
index ed4f0627..20c12df3 100644
--- a/net_io.c
+++ b/net_io.c
@@ -51,6 +51,7 @@
 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
+#include "ais_charset.h"
 #include "readsb.h"
 
 #include <assert.h>
@@ -208,7 +209,6 @@ static struct net_service *serviceInit(struct net_service_group *group, const ch
     return service;
 }
 
-static char *ais_charset = "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_ !\"#$%&'()*+,-./0123456789:;<=>?";
 static uint8_t char_to_ais(int ch)
 {
     char *match;

From f743b90e7525b9e40ddf144782418df9a5f6bfbc Mon Sep 17 00:00:00 2001
From: "Eugenio Paolantonio (g7)" <me@medesimo.eu>
Date: Sun, 20 Jul 2025 23:34:19 +0200
Subject: [PATCH 2/3] ais_charset, uat2esnt: ensure ais_charset is a
 NUL-terminated string

Signed-off-by: Eugenio Paolantonio (g7) <me@medesimo.eu>
---
 ais_charset.c       | 2 +-
 ais_charset.h       | 2 +-
 uat2esnt/uat2esnt.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/ais_charset.c b/ais_charset.c
index 18bbe4f3..2da9f6e3 100644
--- a/ais_charset.c
+++ b/ais_charset.c
@@ -23,4 +23,4 @@
 
 #include "ais_charset.h"
 
-char ais_charset[64] = "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_ !\"#$%&'()*+,-./0123456789:;<=>?";
+char ais_charset[65] = "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_ !\"#$%&'()*+,-./0123456789:;<=>?";
diff --git a/ais_charset.h b/ais_charset.h
index 71125fb5..4a8b3a24 100644
--- a/ais_charset.h
+++ b/ais_charset.h
@@ -24,6 +24,6 @@
 #ifndef AIS_CHARSET_H
 #define AIS_CHARSET_H
 
-extern char ais_charset[64];
+extern char ais_charset[65];
 
 #endif
diff --git a/uat2esnt/uat2esnt.c b/uat2esnt/uat2esnt.c
index 1af87ed4..c68d6431 100755
--- a/uat2esnt/uat2esnt.c
+++ b/uat2esnt/uat2esnt.c
@@ -486,7 +486,7 @@ static char* maybe_send_air_velocity(struct uat_adsb_mdb *mdb, char *p, char *en
 }
 
 // yeah, this could be done with a lookup table, meh.
-static char *ais_charset = "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_ !\"#$%&'()*+,-./0123456789:;<=>?";
+static char ais_charset[65] = "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_ !\"#$%&'()*+,-./0123456789:;<=>?";
 static uint8_t char_to_ais(int ch)
 {
     char *match;

From dab71ee4a930d45d4b480714f7173e65cca1acef Mon Sep 17 00:00:00 2001
From: "Eugenio Paolantonio (g7)" <me@medesimo.eu>
Date: Sun, 20 Jul 2025 23:35:09 +0200
Subject: [PATCH 3/3] interactive, uat2esnt: use __nonstring__ attribute for
 byte arrays

GCC 15 adds -Wunterminated-string-initialization, which complains if a string
is not NUL-terminated.
However, it causes false positives on byte arrays.

Disambiguate that by using the __nonstring__ attribute, which is available
since GCC 8 and clang 21.

Signed-off-by: Eugenio Paolantonio (g7) <me@medesimo.eu>
---
 interactive.c         |  2 +-
 readsb.h              | 10 ++++++++++
 uat2esnt/uat.h        |  6 ++++++
 uat2esnt/uat_decode.c |  2 +-
 4 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/interactive.c b/interactive.c
index e3346954..1a22a33a 100644
--- a/interactive.c
+++ b/interactive.c
@@ -123,7 +123,7 @@ void interactiveShowData(void) {
     static int64_t next_clear;
     int64_t now = mstime();
     char progress;
-    char spinner[4] = "|/-\\";
+    char spinner[4] __nonstring = "|/-\\";
 
     // Refresh screen every (MODES_INTERACTIVE_REFRESH_TIME) miliseconde
     if (now < next_update)
diff --git a/readsb.h b/readsb.h
index f85ed918..db3903a3 100644
--- a/readsb.h
+++ b/readsb.h
@@ -377,6 +377,16 @@ typedef enum {
 
 #endif
 
+// __nonstring__ is available since GCC 8 and clang 21.
+// It is possible to use the __nonstring__ attribute to
+// suppress the -Wunterminated-string-initialization warning
+// on unterminated strings (default since GCC 15)
+#if __has_attribute(__nonstring__)
+#define __nonstring __attribute__((__nonstring__))
+#else
+#define __nonstring
+#endif
+
 void setExit(int arg);
 int priorityTasksPending();
 void priorityTasksRun();
diff --git a/uat2esnt/uat.h b/uat2esnt/uat.h
index f9da5215..202e8e5e 100644
--- a/uat2esnt/uat.h
+++ b/uat2esnt/uat.h
@@ -41,4 +41,10 @@
 #define UPLINK_FRAME_DATA_BYTES (UPLINK_FRAME_DATA_BITS/8)
 #define UPLINK_FRAME_BYTES (UPLINK_FRAME_BITS/8)
 
+#if __has_attribute(__nonstring__)
+#define __nonstring __attribute__((__nonstring__))
+#else
+#define __nonstring
+#endif
+
 #endif
diff --git a/uat2esnt/uat_decode.c b/uat2esnt/uat_decode.c
index 284582b5..0740581c 100644
--- a/uat2esnt/uat_decode.c
+++ b/uat2esnt/uat_decode.c
@@ -267,7 +267,7 @@ static void uat_display_sv(const struct uat_adsb_mdb *mdb, FILE *to)
             mdb->tisb_site_id);
 }
 
-static char base40_alphabet[40] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ  ..";
+static char base40_alphabet[40] __nonstring = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ  ..";
 static void uat_decode_ms(uint8_t *frame, struct uat_adsb_mdb *mdb)
 {
     uint16_t v;
openSUSE Build Service is sponsored by