| Message ID | 20251030181127.1059501-2-kieran.bingham@ideasonboard.com |
|---|---|
| State | Superseded |
| Headers | show |
| Series |
|
| Related | show |
2025. 10. 30. 19:11 keltezéssel, Kieran Bingham írta: > Converting strings to hex stores data in a uint64_t. This can > incorrectly sign extend if the type being converted is signed. > > Provide tests to be sure that the signed conversion is correct. > > This is known to fail, so report as expected failure. > > Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> > --- Looks good. Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com> > test/meson.build | 2 +- > test/utils.cpp | 17 +++++++++++++++++ > 2 files changed, 18 insertions(+), 1 deletion(-) > > diff --git a/test/meson.build b/test/meson.build > index 52f04364e4fc..96c4477f04b2 100644 > --- a/test/meson.build > +++ b/test/meson.build > @@ -73,7 +73,7 @@ internal_tests = [ > {'name': 'timer-fail', 'sources': ['timer-fail.cpp'], 'should_fail': true}, > {'name': 'timer-thread', 'sources': ['timer-thread.cpp']}, > {'name': 'unique-fd', 'sources': ['unique-fd.cpp']}, > - {'name': 'utils', 'sources': ['utils.cpp']}, > + {'name': 'utils', 'sources': ['utils.cpp'], 'should_fail': true}, > {'name': 'vector', 'sources': ['vector.cpp']}, > {'name': 'yaml-parser', 'sources': ['yaml-parser.cpp']}, > ] > diff --git a/test/utils.cpp b/test/utils.cpp > index ca2e4f3b3e85..b5ce94e5e912 100644 > --- a/test/utils.cpp > +++ b/test/utils.cpp > @@ -218,6 +218,23 @@ protected: > os << utils::hex(static_cast<uint64_t>(0x42), 1) << " "; > ref += "0x42 "; > > + os << utils::hex(static_cast<int8_t>(-1)) << " "; > + ref += "0xff "; > + os << utils::hex(static_cast<uint8_t>(-1)) << " "; > + ref += "0xff "; > + os << utils::hex(static_cast<int16_t>(-1)) << " "; > + ref += "0xffff "; > + os << utils::hex(static_cast<uint16_t>(-1)) << " "; > + ref += "0xffff "; > + os << utils::hex(static_cast<int32_t>(-1)) << " "; > + ref += "0xffffffff "; > + os << utils::hex(static_cast<uint32_t>(-1)) << " "; > + ref += "0xffffffff "; > + os << utils::hex(static_cast<int64_t>(-1)) << " "; > + ref += "0xffffffffffffffff "; > + os << utils::hex(static_cast<uint64_t>(-1)) << " "; > + ref += "0xffffffffffffffff "; > + > std::string s = os.str(); > if (s != ref) { > cerr << "utils::hex() test failed, expected '" << ref
More tests \o/ On Thu, Oct 30, 2025 at 06:11:26PM +0000, Kieran Bingham wrote: > Converting strings to hex stores data in a uint64_t. This can > incorrectly sign extend if the type being converted is signed. > > Provide tests to be sure that the signed conversion is correct. > > This is known to fail, so report as expected failure. > > Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > --- > test/meson.build | 2 +- > test/utils.cpp | 17 +++++++++++++++++ > 2 files changed, 18 insertions(+), 1 deletion(-) > > diff --git a/test/meson.build b/test/meson.build > index 52f04364e4fc..96c4477f04b2 100644 > --- a/test/meson.build > +++ b/test/meson.build > @@ -73,7 +73,7 @@ internal_tests = [ > {'name': 'timer-fail', 'sources': ['timer-fail.cpp'], 'should_fail': true}, > {'name': 'timer-thread', 'sources': ['timer-thread.cpp']}, > {'name': 'unique-fd', 'sources': ['unique-fd.cpp']}, > - {'name': 'utils', 'sources': ['utils.cpp']}, > + {'name': 'utils', 'sources': ['utils.cpp'], 'should_fail': true}, > {'name': 'vector', 'sources': ['vector.cpp']}, > {'name': 'yaml-parser', 'sources': ['yaml-parser.cpp']}, > ] > diff --git a/test/utils.cpp b/test/utils.cpp > index ca2e4f3b3e85..b5ce94e5e912 100644 > --- a/test/utils.cpp > +++ b/test/utils.cpp > @@ -218,6 +218,23 @@ protected: > os << utils::hex(static_cast<uint64_t>(0x42), 1) << " "; > ref += "0x42 "; > > + os << utils::hex(static_cast<int8_t>(-1)) << " "; > + ref += "0xff "; > + os << utils::hex(static_cast<uint8_t>(-1)) << " "; > + ref += "0xff "; > + os << utils::hex(static_cast<int16_t>(-1)) << " "; > + ref += "0xffff "; > + os << utils::hex(static_cast<uint16_t>(-1)) << " "; > + ref += "0xffff "; > + os << utils::hex(static_cast<int32_t>(-1)) << " "; > + ref += "0xffffffff "; > + os << utils::hex(static_cast<uint32_t>(-1)) << " "; > + ref += "0xffffffff "; > + os << utils::hex(static_cast<int64_t>(-1)) << " "; > + ref += "0xffffffffffffffff "; > + os << utils::hex(static_cast<uint64_t>(-1)) << " "; > + ref += "0xffffffffffffffff "; > + > std::string s = os.str(); > if (s != ref) { > cerr << "utils::hex() test failed, expected '" << ref
diff --git a/test/meson.build b/test/meson.build index 52f04364e4fc..96c4477f04b2 100644 --- a/test/meson.build +++ b/test/meson.build @@ -73,7 +73,7 @@ internal_tests = [ {'name': 'timer-fail', 'sources': ['timer-fail.cpp'], 'should_fail': true}, {'name': 'timer-thread', 'sources': ['timer-thread.cpp']}, {'name': 'unique-fd', 'sources': ['unique-fd.cpp']}, - {'name': 'utils', 'sources': ['utils.cpp']}, + {'name': 'utils', 'sources': ['utils.cpp'], 'should_fail': true}, {'name': 'vector', 'sources': ['vector.cpp']}, {'name': 'yaml-parser', 'sources': ['yaml-parser.cpp']}, ] diff --git a/test/utils.cpp b/test/utils.cpp index ca2e4f3b3e85..b5ce94e5e912 100644 --- a/test/utils.cpp +++ b/test/utils.cpp @@ -218,6 +218,23 @@ protected: os << utils::hex(static_cast<uint64_t>(0x42), 1) << " "; ref += "0x42 "; + os << utils::hex(static_cast<int8_t>(-1)) << " "; + ref += "0xff "; + os << utils::hex(static_cast<uint8_t>(-1)) << " "; + ref += "0xff "; + os << utils::hex(static_cast<int16_t>(-1)) << " "; + ref += "0xffff "; + os << utils::hex(static_cast<uint16_t>(-1)) << " "; + ref += "0xffff "; + os << utils::hex(static_cast<int32_t>(-1)) << " "; + ref += "0xffffffff "; + os << utils::hex(static_cast<uint32_t>(-1)) << " "; + ref += "0xffffffff "; + os << utils::hex(static_cast<int64_t>(-1)) << " "; + ref += "0xffffffffffffffff "; + os << utils::hex(static_cast<uint64_t>(-1)) << " "; + ref += "0xffffffffffffffff "; + std::string s = os.str(); if (s != ref) { cerr << "utils::hex() test failed, expected '" << ref
Converting strings to hex stores data in a uint64_t. This can incorrectly sign extend if the type being converted is signed. Provide tests to be sure that the signed conversion is correct. This is known to fail, so report as expected failure. Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> --- test/meson.build | 2 +- test/utils.cpp | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-)