public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Don't create empty literal pieces
@ 2019-10-01 21:25 Tom Tromey
0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2019-10-01 21:25 UTC (permalink / raw)
To: gdb-cvs
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=0dfe5bfbb7e7a3e55c57d1b59c265dc1a3cd9fc7
commit 0dfe5bfbb7e7a3e55c57d1b59c265dc1a3cd9fc7
Author: Tom Tromey <tom@tromey.com>
Date: Sun Sep 22 16:06:03 2019 -0600
Don't create empty literal pieces
I noticed that format_pieces can create an empty literal piece.
However, there's never a need for one, so this patch removes the
possibility.
gdb/ChangeLog
2019-10-01 Tom Tromey <tom@tromey.com>
* unittests/format_pieces-selftests.c: Update. Add final format.
* gdbsupport/format.c (format_pieces::format_pieces): Don't add
empty literal pieces.
Diff:
---
gdb/ChangeLog | 6 ++++++
gdb/gdbsupport/format.c | 16 ++++++++++------
gdb/unittests/format_pieces-selftests.c | 6 ++++--
3 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index dd196d7..5c3dec3 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,11 @@
2019-10-01 Tom Tromey <tom@tromey.com>
+ * unittests/format_pieces-selftests.c: Update. Add final format.
+ * gdbsupport/format.c (format_pieces::format_pieces): Don't add
+ empty literal pieces.
+
+2019-10-01 Tom Tromey <tom@tromey.com>
+
* ui-out.h (enum class ui_out_style_kind): Remove.
(class ui_out) <field_string, field_stsream, do_field_string>:
Change type of "style".
diff --git a/gdb/gdbsupport/format.c b/gdb/gdbsupport/format.c
index fb3421e..a5a3670 100644
--- a/gdb/gdbsupport/format.c
+++ b/gdb/gdbsupport/format.c
@@ -129,7 +129,8 @@ format_pieces::format_pieces (const char **arg)
current_substring += f - 1 - prev_start;
*current_substring++ = '\0';
- m_pieces.emplace_back (sub_start, literal_piece);
+ if (*sub_start != '\0')
+ m_pieces.emplace_back (sub_start, literal_piece);
percent_loc = f - 1;
@@ -340,11 +341,14 @@ format_pieces::format_pieces (const char **arg)
/* Record the remainder of the string. */
- sub_start = current_substring;
+ if (f > prev_start)
+ {
+ sub_start = current_substring;
- strncpy (current_substring, prev_start, f - prev_start);
- current_substring += f - prev_start;
- *current_substring++ = '\0';
+ strncpy (current_substring, prev_start, f - prev_start);
+ current_substring += f - prev_start;
+ *current_substring++ = '\0';
- m_pieces.emplace_back (sub_start, literal_piece);
+ m_pieces.emplace_back (sub_start, literal_piece);
+ }
}
diff --git a/gdb/unittests/format_pieces-selftests.c b/gdb/unittests/format_pieces-selftests.c
index 7d31b3c..862b2da 100644
--- a/gdb/unittests/format_pieces-selftests.c
+++ b/gdb/unittests/format_pieces-selftests.c
@@ -48,13 +48,15 @@ test_escape_sequences ()
static void
test_format_specifier ()
{
- check ("Hello %d%llx%%d", /* ARI: %ll */
+ /* The format string here ends with a % sequence, to ensure we don't
+ see a trailing empty literal piece. */
+ check ("Hello %d%llx%%d%d", /* ARI: %ll */
{
format_piece ("Hello ", literal_piece),
format_piece ("%d", int_arg),
- format_piece ("", literal_piece),
format_piece ("%llx", long_long_arg), /* ARI: %ll */
format_piece ("%%d", literal_piece),
+ format_piece ("%d", int_arg),
});
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2019-10-01 21:25 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-01 21:25 [binutils-gdb] Don't create empty literal pieces Tom Tromey
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).