This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[v3] Fix debug mode output
- From: Paolo Carlini <pcarlini at suse dot de>
- To: "'gcc-patches at gcc dot gnu dot org'" <gcc-patches at gcc dot gnu dot org>
- Cc: libstdc++ <libstdc++ at gcc dot gnu dot org>,Jonathan Wakely <cow at compsoc dot man dot ac dot uk>,Kaspar Fischer <kasparfischer at gmx dot net>
- Date: Sat, 07 Aug 2004 16:40:48 +0200
- Subject: [v3] Fix debug mode output
Hi,
I'm committing a variant of the second solution developed with Jonathan
on the libstdc++ list. Took the occasion to fix an off-by-one error
present in the original code and reformat a bit.
Tested x86-linux.
Paolo.
//////////////
2004-08-07 Jonathan Wakely <redi@gcc.gnu.org>
Paolo Carlini <pcarlini@suse.de>
* src/debug.cc (_Error_formatter::_M_print_string): In order
to print individual words from __string, _M_format_word can't
be called since may be just sprintf, thus ignoring completely
__n: instead, use memmove and append '\0' by hand.
diff -urN libstdc++-v3-orig/src/debug.cc libstdc++-v3/src/debug.cc
--- libstdc++-v3-orig/src/debug.cc 2004-05-13 18:29:38.000000000 +0200
+++ libstdc++-v3/src/debug.cc 2004-08-07 16:12:58.000000000 +0200
@@ -569,12 +569,17 @@
{
// [__start, __end) denotes the next word
__end = __start;
- while (isalnum(*__end)) ++__end;
- if (__start == __end) ++__end;
- if (isspace(*__end)) ++__end;
+ while (isalnum(*__end))
+ ++__end;
+ if (__start == __end)
+ ++__end;
+ if (isspace(*__end))
+ ++__end;
- assert(__end - __start + 1< __bufsize);
- _M_format_word(__buf, __end - __start + 1, "%s", __start);
+ const ptrdiff_t __len = __end - __start;
+ assert(__len < __bufsize);
+ memmove(__buf, __start, __len);
+ __buf[__len] = '\0';
_M_print_word(__buf);
__start = __end;