pathtrace.c: use xgrowarray

* defs.h <struct path_set>: Change type of num_selected field to size_t.
Add size field.
* pathtrace.c (storepath): Rewrite to utilise xgrowarray.
This commit is contained in:
Eugene Syromiatnikov 2017-12-13 13:52:59 +01:00 committed by Dmitry V. Levin
parent f236207f46
commit bfbfdf5e37
2 changed files with 8 additions and 8 deletions

3
defs.h
View File

@ -364,7 +364,8 @@ extern unsigned int show_fd_path;
/* are we filtering traces based on paths? */
extern struct path_set {
const char **paths_selected;
unsigned int num_selected;
size_t num_selected;
size_t size;
} global_path_set;
#define tracing_paths (global_path_set.num_selected != 0)
extern unsigned xflag;

View File

@ -82,16 +82,15 @@ fdmatch(struct tcb *tcp, int fd, struct path_set *set)
static void
storepath(const char *path, struct path_set *set)
{
unsigned i;
if (pathmatch(path, set))
return; /* already in table */
i = set->num_selected++;
set->paths_selected = xreallocarray(set->paths_selected,
set->num_selected,
sizeof(set->paths_selected[0]));
set->paths_selected[i] = path;
if (set->num_selected >= set->size)
set->paths_selected =
xgrowarray(set->paths_selected, &set->size,
sizeof(set->paths_selected[0]));
set->paths_selected[set->num_selected++] = path;
}
/*