Bug #7719
closed
Convert a cpp17::any with unsigned long to a string always throws.
Added by Andreas Frolov over 4 years ago.
Updated over 3 years ago.
Description
The following code always throws:
Wt::cpp17::any value = 4ul;
auto s = Wt::asString(value);
because you try to cast value to the type long instead of unsigned long what leads to an exception.
What platform is this on? It's working fine on Linux 64 bit, but maybe the issue is specific to 32 bit, I'll have to check that.
I tested on Windows 32 bit, but I wonder that it works somewhere.
This is your code:
@ } else if (v.type() typeid(unsigned long)) {
if (sizeof(long) 4) {
if (format.empty())
return WLocale::currentLocale().toString
((unsigned)cpp17::any_cast(v));
else {
char buf[100];
snprintf(buf, 100, format.toUTF8().c_str(),
(unsigned)cpp17::any_cast(v));
return WString::fromUTF8(buf);
}
} else {
if (format.empty())
return WLocale::currentLocale()
.toString((::uint64_t)cpp17::any_cast(v));
else {
char buf[100];
snprintf(buf, 100, format.toUTF8().c_str(),
(::uint64_t)cpp17::any_cast(v));
return WString::fromUTF8(buf);
}
}
}@
All cases in this block try to execute any_cast with wrong type.
I just tested on Windows and found the issue myself. I'm fixing it. I think on Linux 64 bit it takes a different code path since there unsigned long
is synonymous with uint64_t
.
- Status changed from New to Resolved
- Description updated (diff)
- Status changed from Resolved to Closed
Also available in: Atom
PDF