Use gdb::def_vector in find_source_lines
This replaces an explicit malloc and a cleanup with a gdb::def_vector. 2018-02-08 Tom Tromey <tom@tromey.com> * source.c (find_source_lines): Use gdb::def_vector.
This commit is contained in:
parent
84f27c6fcb
commit
a9abc43451
2 changed files with 12 additions and 12 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
2018-02-08 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
|
* source.c (find_source_lines): Use gdb::def_vector.
|
||||||
|
|
||||||
2018-02-08 Tom Tromey <tom@tromey.com>
|
2018-02-08 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
* macrocmd.c (struct temporary_macro_definition): New.
|
* macrocmd.c (struct temporary_macro_definition): New.
|
||||||
|
|
20
gdb/source.c
20
gdb/source.c
|
@ -1186,7 +1186,7 @@ void
|
||||||
find_source_lines (struct symtab *s, int desc)
|
find_source_lines (struct symtab *s, int desc)
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
char *data, *p, *end;
|
char *p, *end;
|
||||||
int nlines = 0;
|
int nlines = 0;
|
||||||
int lines_allocated = 1000;
|
int lines_allocated = 1000;
|
||||||
int *line_charpos;
|
int *line_charpos;
|
||||||
|
@ -1207,23 +1207,20 @@ find_source_lines (struct symtab *s, int desc)
|
||||||
warning (_("Source file is more recent than executable."));
|
warning (_("Source file is more recent than executable."));
|
||||||
|
|
||||||
{
|
{
|
||||||
struct cleanup *old_cleanups;
|
|
||||||
|
|
||||||
/* st_size might be a large type, but we only support source files whose
|
/* st_size might be a large type, but we only support source files whose
|
||||||
size fits in an int. */
|
size fits in an int. */
|
||||||
size = (int) st.st_size;
|
size = (int) st.st_size;
|
||||||
|
|
||||||
/* Use malloc, not alloca, because this may be pretty large, and we may
|
/* Use the heap, not the stack, because this may be pretty large,
|
||||||
run into various kinds of limits on stack size. */
|
and we may run into various kinds of limits on stack size. */
|
||||||
data = (char *) xmalloc (size);
|
gdb::def_vector<char> data (size);
|
||||||
old_cleanups = make_cleanup (xfree, data);
|
|
||||||
|
|
||||||
/* Reassign `size' to result of read for systems where \r\n -> \n. */
|
/* Reassign `size' to result of read for systems where \r\n -> \n. */
|
||||||
size = myread (desc, data, size);
|
size = myread (desc, data.data (), size);
|
||||||
if (size < 0)
|
if (size < 0)
|
||||||
perror_with_name (symtab_to_filename_for_display (s));
|
perror_with_name (symtab_to_filename_for_display (s));
|
||||||
end = data + size;
|
end = &data[size];
|
||||||
p = data;
|
p = &data[0];
|
||||||
line_charpos[0] = 0;
|
line_charpos[0] = 0;
|
||||||
nlines = 1;
|
nlines = 1;
|
||||||
while (p != end)
|
while (p != end)
|
||||||
|
@ -1239,10 +1236,9 @@ find_source_lines (struct symtab *s, int desc)
|
||||||
(int *) xrealloc ((char *) line_charpos,
|
(int *) xrealloc ((char *) line_charpos,
|
||||||
sizeof (int) * lines_allocated);
|
sizeof (int) * lines_allocated);
|
||||||
}
|
}
|
||||||
line_charpos[nlines++] = p - data;
|
line_charpos[nlines++] = p - data.data ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
do_cleanups (old_cleanups);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s->nlines = nlines;
|
s->nlines = nlines;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue