Skip to content

Commit 0c820d6

Browse files
committed
Fix some valgrind errors in the TUI
The styling series introduced some new errors in the TUI -- the series changed how source lines are allocated, without updating tui_set_source_content_nil. There are several failures but a typical one looks like: ==6274== Use of uninitialised value of size 8 ==6274== at 0x4E4A095: wclrtoeol (in /usr/lib64/libncursesw.so.6.1) ==6274== by 0x4E47617: waddch (in /usr/lib64/libncursesw.so.6.1) ==6274== by 0x8325CB: tui_puts_internal(_win_st*, char const*, int*) (tui-io.c:393) ==6274== by 0x82E89D: tui_file::puts(char const*) (tui-file.c:39) ==6274== by 0x84BF5F: vfprintf_unfiltered(ui_file*, char const*, __va_list_tag*) (utils.c:2026) This patch rewrites tui_set_source_content_nil, fixing the bug. This was also reported as PR tui/24197. Verified by running valgrind before and after on x86-64 Fedora 29. gdb/ChangeLog 2019-02-17 Tom Tromey <tom@tromey.com> PR tui/24197: * tui/tui-source.c (tui_set_source_content_nil): Rewrite.
1 parent a008792 commit 0c820d6

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

gdb/ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2019-02-17 Tom Tromey <tom@tromey.com>
2+
3+
PR tui/24197:
4+
* tui/tui-source.c (tui_set_source_content_nil): Rewrite.
5+
16
2019-02-17 Tom Tromey <tom@tromey.com>
27

38
* ada-lang.c (user_select_syms): Use filtered printing.

gdb/tui/tui-source.c

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -253,33 +253,22 @@ tui_set_source_content_nil (struct tui_win_info *win_info,
253253

254254
if (curr_line == (n_lines / 2 + 1))
255255
{
256-
int i;
257256
int xpos;
258257
int warning_length = strlen (warning_string);
259258
char *src_line;
260259

261-
src_line = element->which_element.source.line;
262-
263260
if (warning_length >= ((line_width - 1) / 2))
264261
xpos = 1;
265262
else
266263
xpos = (line_width - 1) / 2 - warning_length;
267264

268-
for (i = 0; i < xpos; i++)
269-
src_line[i] = ' ';
270-
271-
sprintf (src_line + i, "%s", warning_string);
272-
273-
for (i = xpos + warning_length; i < line_width; i++)
274-
src_line[i] = ' ';
275-
276-
src_line[i] = '\n';
277-
278-
} /* end if */
265+
src_line = xstrprintf ("%s%s", n_spaces (xpos), warning_string);
266+
xfree (element->which_element.source.line);
267+
element->which_element.source.line = src_line;
268+
}
279269

280270
curr_line++;
281-
282-
} /* end while */
271+
}
283272
}
284273

285274

0 commit comments

Comments
 (0)