Project

General

Profile

Actions

Bug #7719

closed

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

Added by Andreas Frolov over 3 years ago. Updated almost 3 years ago.

Status:
Closed
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.

Actions #1

Updated by Roel Standaert over 3 years 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.

Actions #2

Updated by Andreas Frolov over 3 years 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.

Actions #3

Updated by Roel Standaert over 3 years 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.

Actions #4

Updated by Roel Standaert over 3 years ago

  • Status changed from New to Resolved

I pushed a fix

Actions #5

Updated by Andreas Frolov over 3 years 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

Actions #6

Updated by Roel Standaert over 3 years ago

I see.

Actions #7

Updated by Roel Standaert almost 3 years ago

  • Description updated (diff)
  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF