Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions src/adapter/driver/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -1312,9 +1312,14 @@ static void fix_value(neu_datatag_t *tag, neu_type_e value_type,
static void cal_decimal(neu_type_e tag_type, neu_type_e value_type,
neu_value_u *value, double decimal, double bias)
{
long double result = value_type == NEU_TYPE_INT64
? (long double) value->i64
: (long double) value->d64;
long double result;
if (value_type == NEU_TYPE_INT64) {
result = (long double) value->i64;
} else if (value_type == NEU_TYPE_UINT64) {
result = (long double) value->u64;
} else {
result = (long double) value->d64;
}
result -= (long double) bias;
if (decimal != 0) {
result /= (long double) decimal;
Expand Down Expand Up @@ -1477,7 +1482,7 @@ static int check_write_value(neu_type_e tag_type, int64_t value, double value_d,
return valid ? NEU_ERR_SUCCESS : NEU_ERR_PLUGIN_TAG_TYPE_MISMATCH;
}
}
if (write_type != NEU_TYPE_INT64 &&
if (write_type != NEU_TYPE_INT64 && write_type != NEU_TYPE_UINT64 &&
(write_type != NEU_TYPE_DOUBLE ||
(integer && decimal == 0 && bias == 0))) {
return NEU_ERR_PLUGIN_TAG_TYPE_MISMATCH;
Expand All @@ -1486,8 +1491,14 @@ static int check_write_value(neu_type_e tag_type, int64_t value, double value_d,
(!isfinite(decimal) || !isfinite(bias))) {
return NEU_ERR_PLUGIN_TAG_VALUE_OUT_OF_RANGE;
}
long double result = write_type == NEU_TYPE_INT64 ? (long double) value
: (long double) value_d;
long double result;
if (write_type == NEU_TYPE_INT64) {
result = (long double) value;
} else if (write_type == NEU_TYPE_UINT64) {
result = (long double) (uint64_t) value;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve fractional checks for wide UINT64 transforms

On the x86_64 target configured in .github/workflows/ci.yml, long double has only 64 mantissa bits, so for newly accepted unsigned values above INT64_MAX the subsequent bias or division can round away every fractional bit before the integer check. For example, writing UINT64_MAX to a UINT64 tag with bias 0.5 turns result into UINT64_MAX - 1, passes the integrality check, and makes cal_decimal write that different value, whereas the exact transformed value is a half-integer that should be rejected; preserve the fractional remainder or use wider/exact arithmetic in both validation and conversion.

Useful? React with 👍 / 👎.

} else {
result = (long double) value_d;
}
result -= (long double) bias;
if (decimal != 0) {
result /= (long double) decimal;
Expand Down Expand Up @@ -1571,8 +1582,11 @@ static int prepare_write_tag(neu_adapter_driver_t *driver, group_t *group,
cal_decimal(tag->type, value->type, &value->value, tag->decimal,
tag->bias);
} else if ((tag->type == NEU_TYPE_FLOAT || tag->type == NEU_TYPE_DOUBLE) &&
value->type == NEU_TYPE_INT64) {
value->value.d64 = (double) value->value.i64;
(value->type == NEU_TYPE_INT64 ||
value->type == NEU_TYPE_UINT64)) {
value->value.d64 = value->type == NEU_TYPE_INT64
? (double) value->value.i64
: (double) value->value.u64;
}
if (tag->type == NEU_TYPE_FLOAT || tag->type == NEU_TYPE_DOUBLE) {
value->type = NEU_TYPE_DOUBLE;
Expand Down
2 changes: 2 additions & 0 deletions tests/ut/driver_auto_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ TEST(DriverAuto, NonfiniteAndWideBounds)
is_value_in_range(NEU_TYPE_INT64, INT64_MAX, 0, NEU_TYPE_INT64, 0.5));
EXPECT_EQ(NEU_ERR_PLUGIN_TAG_VALUE_OUT_OF_RANGE,
is_value_in_range(NEU_TYPE_UINT64, -1, 0, NEU_TYPE_INT64, 0));
EXPECT_EQ(0, is_value_in_range(NEU_TYPE_UINT64, -1, 0, NEU_TYPE_UINT64, 0));
EXPECT_EQ(0, is_value_in_range(NEU_TYPE_FLOAT, -1, 0, NEU_TYPE_UINT64, 0));
EXPECT_EQ(0,
is_value_in_range(NEU_TYPE_FLOAT, 0, 1e30, NEU_TYPE_DOUBLE, 0));
EXPECT_EQ(NEU_ERR_PLUGIN_TAG_VALUE_OUT_OF_RANGE,
Expand Down
Loading