From 1a5f183efc0a900a18ccc94d7467b5e4b1e91411 Mon Sep 17 00:00:00 2001 From: Agisilaos Kounelis Date: Tue, 11 Feb 2025 16:09:35 +0200 Subject: [PATCH 1/4] Fix (u)int8 implicit ASCII conversion in stringstream --- tiledb/sm/misc/parse_argument.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tiledb/sm/misc/parse_argument.cc b/tiledb/sm/misc/parse_argument.cc index a813cad7f50..6a605858072 100644 --- a/tiledb/sm/misc/parse_argument.cc +++ b/tiledb/sm/misc/parse_argument.cc @@ -241,10 +241,12 @@ std::string to_str(const void* value, Datatype type) { std::stringstream ss; switch (type) { case Datatype::INT8: - ss << *(const int8_t*)value; + // cast to int32_t to avoid char conversion to ASCII + ss << *(const int32_t*)value; break; case Datatype::UINT8: - ss << *(const uint8_t*)value; + // cast to uint32_t to avoid char conversion to ASCII + ss << *(const uint32_t*)value; break; case Datatype::INT16: ss << *(const int16_t*)value; From 89925897ef035f2d8fa27630ddf122d6d483e634 Mon Sep 17 00:00:00 2001 From: Agisilaos Kounelis Date: Wed, 12 Feb 2025 17:25:37 +0200 Subject: [PATCH 2/4] Fix --- tiledb/sm/misc/parse_argument.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tiledb/sm/misc/parse_argument.cc b/tiledb/sm/misc/parse_argument.cc index 6a605858072..7d307d172de 100644 --- a/tiledb/sm/misc/parse_argument.cc +++ b/tiledb/sm/misc/parse_argument.cc @@ -241,12 +241,12 @@ std::string to_str(const void* value, Datatype type) { std::stringstream ss; switch (type) { case Datatype::INT8: - // cast to int32_t to avoid char conversion to ASCII - ss << *(const int32_t*)value; + // cast to int32 to avoid char conversion to ASCII + ss << static_cast(*(const int8_t*)value); break; case Datatype::UINT8: - // cast to uint32_t to avoid char conversion to ASCII - ss << *(const uint32_t*)value; + // cast to uint32 to avoid char conversion to ASCII + ss << static_cast(*(const uint8_t*)value); break; case Datatype::INT16: ss << *(const int16_t*)value; From e49c1ece4434447cec484848b995fa60e3bb7dba Mon Sep 17 00:00:00 2001 From: Agisilaos Kounelis Date: Wed, 12 Feb 2025 17:25:43 +0200 Subject: [PATCH 3/4] Add test --- test/CMakeLists.txt | 1 + test/src/unit-parse-argument.cc | 64 +++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 test/src/unit-parse-argument.cc diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ea6fcc33b34..4c0f6a9ee86 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -121,6 +121,7 @@ set(TILEDB_UNIT_TEST_SOURCES src/unit-enum-helpers.cc src/unit-filter-buffer.cc src/unit-global-order.cc + src/unit-parse-argument.cc src/unit-ordered-dim-label-reader.cc src/unit-tile-metadata.cc src/unit-tile-metadata-generator.cc diff --git a/test/src/unit-parse-argument.cc b/test/src/unit-parse-argument.cc new file mode 100644 index 00000000000..f416dcc06d0 --- /dev/null +++ b/test/src/unit-parse-argument.cc @@ -0,0 +1,64 @@ +/** + * @file unit-parse-argument.cc + * + * @section LICENSE + * + * The MIT License + * + * @copyright Copyright (c) 2025 TileDB, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @section DESCRIPTION + * + * Tests for useful (global) functions. + */ + +#include "catch.hpp" +#include "tiledb/sm/enums/datatype.h" +#include "tiledb/sm/misc/parse_argument.h" + +using namespace tiledb::sm::utils::parse; +using namespace tiledb::sm; + +TEST_CASE("Test to_str function for integers", "[to_str][integer]") { + int8_t int8_value = -10; + uint8_t uint8_value = 10; + + REQUIRE(to_str(&int8_value, Datatype::INT8) == "-10"); + REQUIRE(to_str(&uint8_value, Datatype::UINT8) == "10"); + + int16_t int16_value = -10; + uint16_t uint16_value = 10; + + REQUIRE(to_str(&int16_value, Datatype::INT16) == "-10"); + REQUIRE(to_str(&uint16_value, Datatype::UINT16) == "10"); + + int32_t int32_value = -10; + uint32_t uint32_value = 10; + + REQUIRE(to_str(&int32_value, Datatype::INT32) == "-10"); + REQUIRE(to_str(&uint32_value, Datatype::UINT32) == "10"); + + int64_t int64_value = -10; + uint64_t uint64_value = 10; + + REQUIRE(to_str(&int64_value, Datatype::INT64) == "-10"); + REQUIRE(to_str(&uint64_value, Datatype::UINT64) == "10"); +} From 1013cc47b75ac1c96b326c5e7d42e4cacd9099f6 Mon Sep 17 00:00:00 2001 From: Theodore Tsirpanis Date: Thu, 13 Feb 2025 20:13:50 +0200 Subject: [PATCH 4/4] Move test to standalone. --- test/CMakeLists.txt | 1 - tiledb/sm/misc/test/CMakeLists.txt | 1 + .../sm/misc/test/unit_parse_argument.cc | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename test/src/unit-parse-argument.cc => tiledb/sm/misc/test/unit_parse_argument.cc (98%) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4c0f6a9ee86..ea6fcc33b34 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -121,7 +121,6 @@ set(TILEDB_UNIT_TEST_SOURCES src/unit-enum-helpers.cc src/unit-filter-buffer.cc src/unit-global-order.cc - src/unit-parse-argument.cc src/unit-ordered-dim-label-reader.cc src/unit-tile-metadata.cc src/unit-tile-metadata-generator.cc diff --git a/tiledb/sm/misc/test/CMakeLists.txt b/tiledb/sm/misc/test/CMakeLists.txt index 8064459cd00..61108663f40 100644 --- a/tiledb/sm/misc/test/CMakeLists.txt +++ b/tiledb/sm/misc/test/CMakeLists.txt @@ -36,6 +36,7 @@ commence(unit_test misc) unit_hilbert.cc unit_integral_type_casts.cc unit_math.cc + unit_parse_argument.cc ) conclude(unit_test) diff --git a/test/src/unit-parse-argument.cc b/tiledb/sm/misc/test/unit_parse_argument.cc similarity index 98% rename from test/src/unit-parse-argument.cc rename to tiledb/sm/misc/test/unit_parse_argument.cc index f416dcc06d0..867af4aaa03 100644 --- a/test/src/unit-parse-argument.cc +++ b/tiledb/sm/misc/test/unit_parse_argument.cc @@ -1,5 +1,5 @@ /** - * @file unit-parse-argument.cc + * @file unit_parse_argument.cc * * @section LICENSE *