public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [pushed] analyzer: use correct format code for string literal indices [PR110483,PR111802]
@ 2024-02-27 22:23 David Malcolm
  0 siblings, 0 replies; only message in thread
From: David Malcolm @ 2024-02-27 22:23 UTC (permalink / raw)
  To: gcc-patches; +Cc: David Malcolm

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(-)

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 ()));
       }
 
-- 
2.26.3


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-02-27 22:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-27 22:23 [pushed] analyzer: use correct format code for string literal indices [PR110483,PR111802] David Malcolm

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).