@@ -171,12 +171,19 @@ struct traceeval;
/* Histogram interfaces */
-#define traceeval_init(keys, vals) \
- traceeval_init_data_size(keys, vals, sizeof(struct traceeval_type), \
+#define traceeval_init(keys, vals) \
+ traceeval_init_size(keys, vals, \
+ TRACEEVAL_ARRAY_SIZE(keys), \
+ (void *)vals == NULL ? 0 : TRACEEVAL_ARRAY_SIZE(vals))
+
+#define traceeval_init_size(keys, vals, nr_keys, nr_vals) \
+ traceeval_init_data_size(keys, vals, nr_keys, nr_vals, \
+ sizeof(struct traceeval_type), \
sizeof(struct traceeval_data))
struct traceeval *traceeval_init_data_size(struct traceeval_type *keys,
struct traceeval_type *vals,
+ size_t nr_keys, size_t nr_vals,
size_t sizeof_type, size_t sizeof_data);
void traceeval_release(struct traceeval *teval);
@@ -151,7 +151,8 @@ static void type_release(struct traceeval_type *defs, size_t len)
* Returns the size of the array pointed to by @copy, or -1 on error.
*/
static size_t type_alloc(const struct traceeval_type *defs,
- struct traceeval_type **copy)
+ struct traceeval_type **copy,
+ size_t cnt)
{
struct traceeval_type *new_defs = NULL;
size_t size;
@@ -162,7 +163,8 @@ static size_t type_alloc(const struct traceeval_type *defs,
if (!defs)
return 0;
- for (size = 0; defs && defs[size].type != TRACEEVAL_TYPE_NONE; size++)
+ for (size = 0; defs && size < cnt &&
+ defs[size].type != TRACEEVAL_TYPE_NONE; size++)
;
if (!size)
@@ -269,6 +271,7 @@ static int check_vals(struct traceeval_type *vals)
*/
struct traceeval *traceeval_init_data_size(struct traceeval_type *keys,
struct traceeval_type *vals,
+ size_t nr_keys, size_t nr_vals,
size_t sizeof_type, size_t sizeof_data)
{
struct traceeval *teval;
@@ -301,14 +304,14 @@ struct traceeval *traceeval_init_data_size(struct traceeval_type *keys,
}
/* alloc key types */
- teval->nr_key_types = type_alloc(keys, &teval->key_types);
+ teval->nr_key_types = type_alloc(keys, &teval->key_types, nr_keys);
if ((ssize_t)teval->nr_key_types <= 0) {
err_msg = "Failed to allocate user defined keys";
goto fail_release;
}
/* alloc val types */
- teval->nr_val_types = type_alloc(vals, &teval->val_types);
+ teval->nr_val_types = type_alloc(vals, &teval->val_types, nr_vals);
if ((ssize_t)teval->nr_val_types < 0) {
err_msg = "Failed to allocate user defined values";
goto fail_release;