aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorEli Zaretskii <eliz@gnu.org>2015-03-21 10:48:34 +0200
committerEli Zaretskii <eliz@gnu.org>2015-03-21 10:51:40 +0200
commit4fa4c2f7bed85f7cb116466d3cf194cdb6271c60 (patch)
tree82211aa166b7080f91dbfaf51f37ce4e92914f58 /gdb
parent028272619eba21873cc7f58f6f52f4d62abb8d43 (diff)
downloadfsf-binutils-gdb-4fa4c2f7bed85f7cb116466d3cf194cdb6271c60.zip
fsf-binutils-gdb-4fa4c2f7bed85f7cb116466d3cf194cdb6271c60.tar.gz
fsf-binutils-gdb-4fa4c2f7bed85f7cb116466d3cf194cdb6271c60.tar.bz2
Fix undefined behavior in TUI's TAB expansion
gdb/ChangeLog: * tui/tui-io.c (tui_expand_tabs): Reinitialize the column counter before the second loop, to avoid undefined behavior. Reported by Anton Blanchard <anton@samba.org>. (cherry picked from commit b1a0f704950296b2363192ba91999eef3635700f)
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog6
-rw-r--r--gdb/tui/tui-io.c16
2 files changed, 14 insertions, 8 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 37a69e8..8f95a2a 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@
+2015-03-21 Eli Zaretskii <eliz@gnu.org>
+
+ * tui/tui-io.c (tui_expand_tabs): Reinitialize the column counter
+ before the second loop, to avoid undefined behavior. Reported by
+ Anton Blanchard <anton@samba.org>.
+
2015-02-26 Jan Kratochvil <jan.kratochvil@redhat.com>
PR build/18033
diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c
index 13cc5fa..61a8daf 100644
--- a/gdb/tui/tui-io.c
+++ b/gdb/tui/tui-io.c
@@ -758,20 +758,20 @@ tui_getc (FILE *fp)
char *
tui_expand_tabs (const char *string, int col)
{
- int n_adjust;
+ int n_adjust, ncol;
const char *s;
char *ret, *q;
/* 1. How many additional characters do we need? */
- for (n_adjust = 0, s = string; s; )
+ for (ncol = col, n_adjust = 0, s = string; s; )
{
s = strpbrk (s, "\t");
if (s)
{
- col += (s - string) + n_adjust;
+ ncol += (s - string) + n_adjust;
/* Adjustment for the next tab stop, minus one for the TAB
we replace with spaces. */
- n_adjust += 8 - (col % 8) - 1;
+ n_adjust += 8 - (ncol % 8) - 1;
s++;
}
}
@@ -780,7 +780,7 @@ tui_expand_tabs (const char *string, int col)
ret = q = xmalloc (strlen (string) + n_adjust + 1);
/* 2. Copy the original string while replacing TABs with spaces. */
- for (s = string; s; )
+ for (ncol = col, s = string; s; )
{
char *s1 = strpbrk (s, "\t");
if (s1)
@@ -789,12 +789,12 @@ tui_expand_tabs (const char *string, int col)
{
strncpy (q, s, s1 - s);
q += s1 - s;
- col += s1 - s;
+ ncol += s1 - s;
}
do {
*q++ = ' ';
- col++;
- } while ((col % 8) != 0);
+ ncol++;
+ } while ((ncol % 8) != 0);
s1++;
}
else