Project

General

Profile

Actions

Bug #7719

closed
AF

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

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

Added by Andreas Frolov about 6 years ago. Updated about 5 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.

RS Updated by Roel Standaert almost 6 years ago Actions #1

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.

AF Updated by Andreas Frolov almost 6 years ago Actions #2

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.

RS Updated by Roel Standaert almost 6 years ago Actions #3

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.

RS Updated by Roel Standaert almost 6 years ago Actions #4

  • Status changed from New to Resolved

I pushed a fix

AF Updated by Andreas Frolov almost 6 years ago Actions #5

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

RS Updated by Roel Standaert almost 6 years ago Actions #6

I see.

RS Updated by Roel Standaert about 5 years ago Actions #7

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

Also available in: PDF Atom