Blob Blame History Raw
From 8095e021588150a584371ffbbf50e5b0bb7d4ede Mon Sep 17 00:00:00 2001
From: Mattias Ellert <mattias.ellert@physics.uu.se>
Date: Fri, 4 Feb 2022 21:20:47 +0100
Subject: [PATCH] Ignore -Warray-bounds warnings from stricter check in gcc 12.

.../src/XrdFrm/XrdFrmMonitor.cc: In function 'XrdFrmMonitor::Init(char const*, char const*, char const*)':
.../src/XrdFrm/XrdFrmMonitor.cc:158:12: warning: array subscript 'struct XrdXrootdMonMap[0]' is partly outside array bounds of 'unsigned char[1036]' [-Warray-bounds]
  158 |    mP->hdr.pseq = 0;
      |    ~~~~~~~~^~~~
.../src/XrdFrm/XrdFrmMonitor.cc:155:26: note: object of size [13, 1036] allocated by 'malloc'
  155 |    idRec = (char *)malloc(idLen+1);
      |                    ~~~~~~^~~~~~~~~
.../src/XrdFrm/XrdFrmMonitor.cc:159:8: warning: array subscript 'struct XrdXrootdMonMap[0]' is partly outside array bounds of 'unsigned char[1036]' [-Warray-bounds]
  159 |    mP->dictid   = 0;
      |    ~~~~^~~~~~
.../src/XrdFrm/XrdFrmMonitor.cc:155:26: note: object of size [13, 1036] allocated by 'malloc'
  155 |    idRec = (char *)malloc(idLen+1);
      |                    ~~~~~~^~~~~~~~~

.../src/XrdXrootd/XrdXrootdMonitor.cc: In function 'XrdXrootdMonitor::Init(XrdScheduler*, XrdSysError*, char const*, char const*, char const*, int)':
.../src/XrdXrootd/XrdXrootdMonitor.cc:634:12: warning: array subscript 'struct XrdXrootdMonMap[0]' is partly outside array bounds of 'unsigned char[1036]' [-Warray-bounds]
  634 |    mP->hdr.pseq = 0;
      |    ~~~~~~~~^~~~
.../src/XrdXrootd/XrdXrootdMonitor.cc:631:26: note: object of size [13, 1036] allocated by 'malloc'
  631 |    idRec = (char *)malloc(idLen+1);
      |                    ~~~~~~^~~~~~~~~
.../src/XrdXrootd/XrdXrootdMonitor.cc:635:8: warning: array subscript 'struct XrdXrootdMonMap[0]' is partly outside array bounds of 'unsigned char[1036]' [-Warray-bounds]
  635 |    mP->dictid   = 0;
      |    ~~~~^~~~~~
.../src/XrdXrootd/XrdXrootdMonitor.cc:631:26: note: object of size [13, 1036] allocated by 'malloc'
  631 |    idRec = (char *)malloc(idLen+1);
      |                    ~~~~~~^~~~~~~~~
---
 src/XrdFrm/XrdFrmMonitor.cc       | 9 +++++++++
 src/XrdXrootd/XrdXrootdMonitor.cc | 9 +++++++++
 2 files changed, 18 insertions(+)

diff --git a/src/XrdFrm/XrdFrmMonitor.cc b/src/XrdFrm/XrdFrmMonitor.cc
index a453617a6..5abe5ff31 100644
--- a/src/XrdFrm/XrdFrmMonitor.cc
+++ b/src/XrdFrm/XrdFrmMonitor.cc
@@ -149,6 +149,12 @@ int XrdFrmMonitor::Init(const char *iHost, const char *iProg, const char *iName)
 //
    if (!isEnabled) return 1;
 
+// Ignore array bounds warning from gcc 12 triggered because the allocated
+// memory for the XrdXrootdMonMap is smaller than sizeof(XrdXrootdMonMap)
+#if defined(__GNUC__) && __GNUC__ >= 12
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Warray-bounds"
+#endif
 // Create identification record
 //
    idLen = strlen(iBuff) + sizeof(XrdXrootdMonHeader) + sizeof(kXR_int32);
@@ -158,6 +164,9 @@ int XrdFrmMonitor::Init(const char *iHost, const char *iProg, const char *iName)
    mP->hdr.pseq = 0;
    mP->dictid   = 0;
    strcpy(mP->info, iBuff);
+#if defined(__GNUC__) && __GNUC__ >= 12
+#pragma GCC diagnostic pop
+#endif
 
 // Setup the primary destination
 //
diff --git a/src/XrdXrootd/XrdXrootdMonitor.cc b/src/XrdXrootd/XrdXrootdMonitor.cc
index 2926bae75..bb0f0a242 100644
--- a/src/XrdXrootd/XrdXrootdMonitor.cc
+++ b/src/XrdXrootd/XrdXrootdMonitor.cc
@@ -625,6 +625,12 @@ void XrdXrootdMonitor::Init(XrdScheduler *sp,    XrdSysError *errp,
    kySIDSZ = strlen(kySID);
    monHost = strdup(iHost);
 
+// Ignore array bounds warning from gcc 12 triggered because the allocated
+// memory for the XrdXrootdMonMap is smaller than sizeof(XrdXrootdMonMap)
+#if defined(__GNUC__) && __GNUC__ >= 12
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Warray-bounds"
+#endif
 // Create identification record
 //
    idLen = strlen(iBuff) + sizeof(XrdXrootdMonHeader) + sizeof(kXR_int32);
@@ -634,6 +640,9 @@ void XrdXrootdMonitor::Init(XrdScheduler *sp,    XrdSysError *errp,
    mP->hdr.pseq = 0;
    mP->dictid   = 0;
    strcpy(mP->info, iBuff);
+#if defined(__GNUC__) && __GNUC__ >= 12
+#pragma GCC diagnostic pop
+#endif
 
 // Generate a CGI version of all the variations
 //
-- 
2.34.1