aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom de Vries <tdevries@suse.de>2020-07-30 09:23:01 +0200
committerTom de Vries <tdevries@suse.de>2020-07-30 09:23:01 +0200
commit5a99adb86018c10da294e7556544e401c492c2fb (patch)
treecd82df9ccda9b1fe658fce1424c7379c150b72fb
parent13069b87d1b4331b940c7744b2436291427ec988 (diff)
downloadgdb-5a99adb86018c10da294e7556544e401c492c2fb.zip
gdb-5a99adb86018c10da294e7556544e401c492c2fb.tar.gz
gdb-5a99adb86018c10da294e7556544e401c492c2fb.tar.bz2
[gdb/build] Fix Wmaybe-uninitialized in gdb/ui-style.h
When building CFLAGS/CXXFLAGS="-O2 -g -Wall" and gcc 4.8.5, we run into: ... src/gdb/cli/cli-style.c:154:42: warning: '*((void*)&<anonymous> +8)' \ may be used uninitialized in this function [-Wmaybe-uninitialized] src/gdb/cli/cli-style.c:154:42: warning: '*((void*)&<anonymous> +9)' \ may be used uninitialized in this function [-Wmaybe-uninitialized] src/gdb/cli/cli-style.c:154:42: warning: '*((void*)&<anonymous> +10)' \ may be used uninitialized in this function [-Wmaybe-uninitialized] ... The root cause is that the data members of class color, nested in struct ui_file_style in gdb/ui-style.h: ... bool m_simple; int m_value; uint8_t m_red, m_green, m_blue; ... are only partially initialized by this constructor: ... color (int c) : m_simple (true), m_value (c) { gdb_assert (c >= -1 && c <= 255); } ... but the default copy constructor will copy all the fields. The member m_simple acts as a discriminant, to indicate which other members are valid: - m_value (with m_simple == true) - m_red, m_green, m_blue (with m_simple == false) So, we don't need storage for both m_value and m_red/m_green/m_blue at the same time. Fix this by wrapping the respective members in a union: ... bool m_simple; union { int m_value; struct { uint8_t m_red, m_green, m_blue; }; }; ... which also fixes the warning. Build and reg-tested on x86_64-linux. gdb/ChangeLog: 2020-07-30 Tom de Vries <tdevries@suse.de> PR build/26320 * ui-style.h (struct ui_file_style::color): Wrap m_value and m_red/m_green/m_blue in a union.
-rw-r--r--gdb/ChangeLog6
-rw-r--r--gdb/ui-style.h10
2 files changed, 14 insertions, 2 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 4d4d62e..a61a573 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@
+2020-07-30 Tom de Vries <tdevries@suse.de>
+
+ PR build/26320
+ * ui-style.h (struct ui_file_style::color): Wrap m_value and
+ m_red/m_green/m_blue in a union.
+
2020-07-29 Tom de Vries <tdevries@suse.de>
PR tdep/26280
diff --git a/gdb/ui-style.h b/gdb/ui-style.h
index 48ab52d..9cb6dda 100644
--- a/gdb/ui-style.h
+++ b/gdb/ui-style.h
@@ -126,8 +126,14 @@ struct ui_file_style
private:
bool m_simple;
- int m_value;
- uint8_t m_red, m_green, m_blue;
+ union
+ {
+ int m_value;
+ struct
+ {
+ uint8_t m_red, m_green, m_blue;
+ };
+ };
};
/* Intensity settings that are available. */