Truncate aggregation sum to fit map bitness
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 28 Jul 2021 20:19:56 +0000 (16:19 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 12 Jul 2024 15:39:51 +0000 (11:39 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I89a77d9df897f2b1cc7bfc62dcc9e12f31e4a12b

src/common/counter/counter.c

index 99a46af6d12549416cba4fb4575db9cf97791fe6..4f2ac4c856726f40257f452833a9be9e8a7f6e98 100644 (file)
@@ -453,6 +453,35 @@ int lttng_counter_aggregate(const struct lib_counter_config *config,
        default:
                return -EINVAL;
        }
+       switch (config->counter_size) {
+       case COUNTER_SIZE_8_BIT:
+               if (sum > INT8_MAX)
+                       *overflow = true;
+               if (sum < INT8_MIN)
+                       *underflow = true;
+               sum = (int8_t) sum;     /* Truncate sum. */
+               break;
+       case COUNTER_SIZE_16_BIT:
+               if (sum > INT16_MAX)
+                       *overflow = true;
+               if (sum < INT16_MIN)
+                       *underflow = true;
+               sum = (int16_t) sum;    /* Truncate sum. */
+               break;
+       case COUNTER_SIZE_32_BIT:
+               if (sum > INT32_MAX)
+                       *overflow = true;
+               if (sum < INT32_MIN)
+                       *underflow = true;
+               sum = (int32_t) sum;    /* Truncate sum. */
+               break;
+#if CAA_BITS_PER_LONG == 64
+       case COUNTER_SIZE_64_BIT:
+               break;
+#endif
+       default:
+               return -EINVAL;
+       }
        *value = sum;
        return 0;
 }
This page took 0.026087 seconds and 4 git commands to generate.