Message ID | 20240227222309.3519811-1-dmalcolm@redhat.com |
---|---|
State | New |
Headers | show |
Series | [pushed] analyzer: use correct format code for string literal indices [PR110483, PR111802] | expand |
diff --git a/gcc/analyzer/access-diagram.cc b/gcc/analyzer/access-diagram.cc index 9555ee823931..24d203f9325a 100644 --- a/gcc/analyzer/access-diagram.cc +++ b/gcc/analyzer/access-diagram.cc @@ -1905,7 +1905,7 @@ private: const table::rect_t idx_table_rect = btm.get_table_rect (&m_string_reg, bytes, byte_idx_table_y, 1); t.set_cell_span (idx_table_rect, - fmt_styled_string (sm, "[%li]", + fmt_styled_string (sm, "[%wu]", byte_idx_within_string.ulow ())); }
On e.g. gcc211 the use of "%li" with unsigned HOST_WIDE_INT led to this warning: ../../src/gcc/analyzer/access-diagram.cc: In member function ‘void ana::string_literal_spatial_item::add_column_for_byte(text_art::table&, const ana::bit_to_table_map&, text_art::style_manager&, ana::byte_offset_t, ana::byte_offset_t, int, int) const’: ../../src/gcc/analyzer/access-diagram.cc:1909:40: warning: format ‘%li’ expects argument of type ‘long int’, but argument 3 has type ‘long long unsigned int’ [-Wformat=] byte_idx_within_string.ulow ())); ^ and to all values being erroneously printed as "0". Fixed thusly. Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Verified that this fixes the analyzer.exp=out-of-bounds-diagram*.c tests on gcc211 (sparc-sun-solaris2.11). Pushed to trunk as r14-9199-g939439a90f234f. gcc/analyzer/ChangeLog: PR analyzer/110483 PR analyzer/111802 * access-diagram.cc (string_literal_spatial_item::add_column_for_byte): Use %wu for printing unsigned HOST_WIDE_INT. Signed-off-by: David Malcolm <dmalcolm@redhat.com> --- gcc/analyzer/access-diagram.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)