[DTrace-devel] [PATCH 05/13] Handle steps==0 error for llquantize
eugene.loh at oracle.com
eugene.loh at oracle.com
Wed Dec 2 10:54:50 PST 2020
From: Eugene Loh <eugene.loh at oracle.com>
We can get divide-by-zero failures if we do not explicitly check.
Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
---
libdtrace/dt_cg.c | 2 +-
.../aggs/err.D_LLQUANT_STEPVAL.llqstepszero.d | 20 +++++++++++++++++++
2 files changed, 21 insertions(+), 1 deletion(-)
create mode 100644 test/unittest/aggs/err.D_LLQUANT_STEPVAL.llqstepszero.d
diff --git a/libdtrace/dt_cg.c b/libdtrace/dt_cg.c
index 29426d23..673b9794 100644
--- a/libdtrace/dt_cg.c
+++ b/libdtrace/dt_cg.c
@@ -3216,7 +3216,7 @@ dt_cg_agg_llquantize(dt_pcb_t *pcb, dt_ident_t *aid, dt_node_t *dnp,
"must be an unsigned 16-bit quantity\n");
if (steps < factor) {
- if (factor % steps != 0)
+ if (steps == 0 || factor % steps != 0)
dnerror(arg1, D_LLQUANT_STEPVAL, "llquantize() "
"argument #4 (steps) must evenly divide "
"argument #1 (factor) when steps<factor\n");
diff --git a/test/unittest/aggs/err.D_LLQUANT_STEPVAL.llqstepszero.d b/test/unittest/aggs/err.D_LLQUANT_STEPVAL.llqstepszero.d
new file mode 100644
index 00000000..f2b0f442
--- /dev/null
+++ b/test/unittest/aggs/err.D_LLQUANT_STEPVAL.llqstepszero.d
@@ -0,0 +1,20 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+
+/*
+ * ASSERTION:
+ * llquantize() steps must be nonzero.
+ *
+ * SECTION: Aggregations/Aggregations
+ *
+ */
+
+
+BEGIN
+{
+ @ = llquantize(timestamp, 10, 0, 6, 0);
+}
--
2.18.4
More information about the DTrace-devel
mailing list