]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Revert "Slightly less hacky way of quieting GCC"
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sat, 30 Oct 2021 19:07:52 +0000 (15:07 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sat, 30 Oct 2021 19:07:52 +0000 (15:07 -0400)
This reverts commit ff8869bda0b3f69d2655ccc9e577a2d4c267bc5e.

src/lib/util/base_16_32_64_tests.c
src/lib/util/log.c
src/lib/util/pair_print.c
src/lib/util/sbuff.h

index cd68b5a770fbdd49ba232f7c547262a3a38c4505..182471a5e2a7a580074123593109712e374c6b63 100644 (file)
@@ -60,7 +60,7 @@ static const test_vector base64_vectors[] = {
 
 static void test_base16_encode(void)
 {
-       char            buffer[17];
+       char            buffer[17] = { '\0' };
        fr_sbuff_t      out;
        size_t          i;
 
@@ -104,7 +104,7 @@ static void test_base16_decode(void)
 
 static void test_base32_encode(void)
 {
-       char            buffer[17];
+       char            buffer[17] = { '\0' };
        fr_sbuff_t      out;
        size_t          i;
 
@@ -151,7 +151,7 @@ static void test_base32_decode(void)
 
 static void test_base32_hex_encode(void)
 {
-       char            buffer[17];
+       char            buffer[17] = { '\0' };
        fr_sbuff_t      out;
        size_t          i;
 
@@ -198,7 +198,7 @@ static void test_base32_hex_decode(void)
 
 static void test_base64_encode(void)
 {
-       char            buffer[17];
+       char            buffer[17] = { '\0' };
        fr_sbuff_t      out;
        size_t          i;
 
index f91f352e6f2ca6ad229ca01aa8ec9bbf9807ce93..12f62dbf3ab85acce148cfdcecc73ade60c374c6 100644 (file)
@@ -189,6 +189,8 @@ void fr_log_fd_event(UNUSED fr_event_list_t *el, int fd, UNUSED int flags, void
                return;
        }
 
+       buffer[0] = '\0';       /* Fix GCC11 bug where it flags the buffer as uninitialised for no reason */
+
        fr_sbuff_init_out(&sbuff, buffer, sizeof(buffer));
        fr_sbuff_marker(&m_start, &sbuff);
        fr_sbuff_marker(&m_end, &sbuff);
index 1b7bb5cb3f4f6c643936de2f6f029a6a489bdeaf..fb86ef2414496e7c645a84ab1c7cb4ee08c7c5bd 100644 (file)
@@ -201,6 +201,8 @@ void _fr_pair_list_log(fr_log_t const *log, int lvl, fr_pair_t *parent, fr_pair_
        fr_sbuff_t sbuff;
        char buffer[1024];
 
+       buffer[0] = '\0';       /* Fix GCC11 bug where it flags the buffer as uninitialised for no reason */
+
        fr_sbuff_init_out(&sbuff, buffer, sizeof(buffer));
 
        fr_pair_list_log_sbuff(log, lvl, parent, list, file, line, &sbuff);
@@ -223,6 +225,8 @@ void fr_pair_debug(fr_pair_t const *pair)
        fr_sbuff_t sbuff;
        char buffer[1024];
 
+       buffer[0] = '\0';       /* Fix GCC11 bug where it flags the buffer as uninitialised for no reason */
+
        fr_sbuff_init_out(&sbuff, buffer, sizeof(buffer));
 
        fr_pair_print(&sbuff, NULL, pair);
index 6622bf2bee8f68624423d266670636162220249d..5be27d947837d75deab95a9f06916ecdb577a856 100644 (file)
@@ -579,7 +579,7 @@ static inline void fr_sbuff_terminate(fr_sbuff_t *sbuff)
        *sbuff->p = '\0';
 }
 
-static inline void _fr_sbuff_init(fr_sbuff_t *out, UNUSED char unused, char const *start, char const *end, bool is_const)
+static inline void _fr_sbuff_init(fr_sbuff_t *out, char const *start, char const *end, bool is_const, bool nul_term)
 {
        if (unlikely(end < start)) end = start; /* Could be an assert? */
 
@@ -590,6 +590,8 @@ static inline void _fr_sbuff_init(fr_sbuff_t *out, UNUSED char unused, char cons
                .end_i = end,
                .is_const = is_const
        };
+
+       if (nul_term) *out->start = '\0';
 }
 
 /** Initialise an sbuff around a stack allocated buffer for printing
@@ -603,7 +605,6 @@ static inline void _fr_sbuff_init(fr_sbuff_t *out, UNUSED char unused, char cons
  */
 #define fr_sbuff_init_out(_out, _start, _len_or_end) \
 _fr_sbuff_init(_out, _start, \
-*(_start) = '\0' /* Prevents GCC complaining about uninitialised buffers */, \
 _Generic((_len_or_end), \
        size_t          : (char const *)(_start) + ((size_t)(_len_or_end) - 1), \
        long            : (char const *)(_start) + ((size_t)(_len_or_end) - 1), \
@@ -611,7 +612,7 @@ _Generic((_len_or_end), \
        char *          : (char const *)(_len_or_end), \
        char const *    : (char const *)(_len_or_end) \
 ), \
-IS_CONST(char *, _start))
+IS_CONST(char *, _start), true)
 
 /** Initialise an sbuff around a stack allocated buffer for parsing
  *
@@ -622,7 +623,6 @@ IS_CONST(char *, _start))
  */
 #define fr_sbuff_init_in(_out, _start, _len_or_end) \
 _fr_sbuff_init(_out, _start, \
-'\0', \
 _Generic((_len_or_end), \
        size_t          : (char const *)(_start) + (size_t)(_len_or_end), \
        long            : (char const *)(_start) + (size_t)(_len_or_end), \
@@ -630,7 +630,7 @@ _Generic((_len_or_end), \
        char *          : (char const *)(_len_or_end), \
        char const *    : (char const *)(_len_or_end) \
 ), \
-IS_CONST(char *, _start))
+IS_CONST(char *, _start), false)
 
 /** Initialise a special sbuff which automatically reads in more data as the buffer is exhausted
  *