This is the mail archive of the gdb-prs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug python/10633] std::string pretty printer should respect 'print elements' limit


------- Additional Comments From pmuldoon at redhat dot com  2009-09-15 13:29 -------
After looking at this again this afternoon, looks like this is a bug in
c-lang.c:c_printstr after all. Attempt 3 .. ;)

I'm not sure why val_print pre-sized the string to conform with print_max before
passing it to LA_PRINT_STRING, but it just happened to do so. Anyway, not so
important. But from reading the code LA_PRINT_STRING should respect print_max in
all cases. So cases like print_string_repr which do not do any form of pre-size
check with print_max can happily rely on LA_PRINT_STRING to enforce it. In the
current code's case, the code has two loops. One outer which does gate on
print_max, and one inner which doesn't. So the inner loop races past the check,
as far as I can tell. I added a check to the inner loop, and this prints string
to the print_max size, and does the right thing with ellipses too. It passes all
tests in the testsuite.


git diff c-lang.c 
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index 83a7382..515685a 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -459,7 +459,7 @@ c_printstr (struct ui_file *stream, struct type *type, const
gdb_byte *string,
         single character in isolation.  This makes the code simpler
         and probably does the sensible thing in the majority of
         cases.  */
-      while (num_chars == 1)
+      while (num_chars == 1 && things_printed < options->print_max)
        {
          /* Count the number of repetitions.  */
          unsigned int reps = 0;


-- 


http://sourceware.org/bugzilla/show_bug.cgi?id=10633

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]