Project

General

Profile

Bug #7719

Convert a cpp17::any with unsigned long to a string always throws.

Added by Andreas Frolov about 1 month ago. Updated 24 days ago.

Status:
Resolved
Priority:
Normal
Assignee:
-
Target version:
-
Start date:
09/17/2020
Due date:
% Done:

0%

Estimated time:

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.

#1

Updated by Roel Standaert 30 days ago

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.

#2

Updated by Andreas Frolov 30 days ago

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.

#3

Updated by Roel Standaert 30 days ago

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.

#4

Updated by Roel Standaert 30 days ago

  • Status changed from New to Resolved

I pushed a fix

#5

Updated by Andreas Frolov 24 days ago

You only fixed 2 out of 4 cases. I think an exception is still thrown on OSX (else case).

https://stackoverflow.com/questions/36814040/osx-vs-linux-how-to-deal-with-unsigned-long-and-uint64-t

#6

Updated by Roel Standaert 24 days ago

I see.

Also available in: Atom PDF