Message ID | 20230815200234.32fd17dd@gandalf.local.home (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | [RFC] libtraceeval: Add size checks to insert and query functions | expand |
On Tue, 15 Aug 2023 20:02:34 -0400 Steven Rostedt <rostedt@goodmis.org> wrote: > --- a/samples/task-eval.c > +++ b/samples/task-eval.c > @@ -814,7 +814,7 @@ static void display_processes(struct traceeval *teval, > struct process_data *pdata = NULL; > const char *comm = keys[0].cstring; > > - ret = traceeval_query(teval_data, keys, &results); > + ret = traceeval_query(teval_data, keys, 2, &results); > if (ret < 1) > continue; /* ?? */ > That should be: traceeval_query_size(...) I removed it to get the warning to copy into the change log, and ended up not putting it back :-p -- Steve
On Tue, 15 Aug 2023 20:02:34 -0400 Steven Rostedt <rostedt@goodmis.org> wrote: > @@ -171,15 +171,23 @@ struct traceeval *traceeval_init(struct traceeval_type *keys, > > void traceeval_release(struct traceeval *teval); > > -int traceeval_insert(struct traceeval *teval, > - const struct traceeval_data *keys, > - const struct traceeval_data *vals); > +int traceeval_insert_size(struct traceeval *teval, > + const struct traceeval_data *keys, size_t nr_keys, > + const struct traceeval_data *vals, size_t nr_vals); > + > +#define traceeval_insert(teval, keys, vals) \ > + traceeval_insert_size(teval, keys, sizeof(keys) / sizeof(keys[0]), \ > + vals, sizeof(vals) / sizeof(vals[0])) > I just realized that vals may be NULL, so the above needs to be: #define traceeval_insert(teval, keys, vals) \ traceeval_insert_size(teval, keys, sizeof(keys) / sizeof(keys[0]), \ vals, vals ? sizeof(vals) / sizeof(vals[0]) : 0) -- Steve
On Tue, 15 Aug 2023 21:10:52 -0400 Steven Rostedt <rostedt@goodmis.org> wrote: > > +#define traceeval_insert(teval, keys, vals) \ > > + traceeval_insert_size(teval, keys, sizeof(keys) / sizeof(keys[0]), \ > > + vals, sizeof(vals) / sizeof(vals[0])) > > > > I just realized that vals may be NULL, so the above needs to be: > > #define traceeval_insert(teval, keys, vals) \ > traceeval_insert_size(teval, keys, sizeof(keys) / sizeof(keys[0]), \ > vals, vals ? sizeof(vals) / sizeof(vals[0]) : 0) Nevermind. NULL won't compile (and neither will the above). -- Steve
diff --git a/include/traceeval-hist.h b/include/traceeval-hist.h index d0bee7c02aa0..c8c27a51c62b 100644 --- a/include/traceeval-hist.h +++ b/include/traceeval-hist.h @@ -171,15 +171,23 @@ struct traceeval *traceeval_init(struct traceeval_type *keys, void traceeval_release(struct traceeval *teval); -int traceeval_insert(struct traceeval *teval, - const struct traceeval_data *keys, - const struct traceeval_data *vals); +int traceeval_insert_size(struct traceeval *teval, + const struct traceeval_data *keys, size_t nr_keys, + const struct traceeval_data *vals, size_t nr_vals); + +#define traceeval_insert(teval, keys, vals) \ + traceeval_insert_size(teval, keys, sizeof(keys) / sizeof(keys[0]), \ + vals, sizeof(vals) / sizeof(vals[0])) int traceeval_remove(struct traceeval *teval, const struct traceeval_data *keys); -int traceeval_query(struct traceeval *teval, const struct traceeval_data *keys, - const struct traceeval_data **results); +int traceeval_query_size(struct traceeval *teval, const struct traceeval_data *keys, + size_t nr_keys, const struct traceeval_data **results); + +#define traceeval_query(teval, keys, results) \ + traceeval_query_size(teval, keys, \ + sizeof(keys) / sizeof(keys[0]), results); void traceeval_results_release(struct traceeval *teval, const struct traceeval_data *results); diff --git a/samples/task-eval.c b/samples/task-eval.c index c2950b2d64b0..4eaab7ad6e15 100644 --- a/samples/task-eval.c +++ b/samples/task-eval.c @@ -814,7 +814,7 @@ static void display_processes(struct traceeval *teval, struct process_data *pdata = NULL; const char *comm = keys[0].cstring; - ret = traceeval_query(teval_data, keys, &results); + ret = traceeval_query(teval_data, keys, 2, &results); if (ret < 1) continue; /* ?? */ diff --git a/src/histograms.c b/src/histograms.c index a7d0643cfbbd..f71a2d557e34 100644 --- a/src/histograms.c +++ b/src/histograms.c @@ -669,8 +669,8 @@ fail: * * Returns 1 if found, 0 if not found, and -1 on error. */ -int traceeval_query(struct traceeval *teval, const struct traceeval_data *keys, - const struct traceeval_data **results) +int traceeval_query_size(struct traceeval *teval, const struct traceeval_data *keys, + size_t nr_keys, const struct traceeval_data **results) { struct entry *entry; int check; @@ -909,9 +909,9 @@ unsigned long long traceeval_stat_count(struct traceeval_stat *stat) * * Returns 0 on success, and -1 on error. */ -int traceeval_insert(struct traceeval *teval, - const struct traceeval_data *keys, - const struct traceeval_data *vals) +int traceeval_insert_size(struct traceeval *teval, + const struct traceeval_data *keys, size_t nr_keys, + const struct traceeval_data *vals, size_t nr_vals) { struct entry *entry; int check;