Modify

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#7814 closed Bugs (fixed)

Signal 6 coredump on lexical_cast with gcc option trapv

Reported by: Bernd Raum <braum@…> Owned by: Antony Polukhin
Milestone: Boost 1.53.0 Component: lexical_cast
Version: Boost 1.51.0 Severity: Regression
Keywords: lexical_cast long trapv core dump Cc:

Description

When compiling with g++ and option -ftrapv (trap overflow errors), a simple lexical_cast of a negative value causes a signal 6 dump:

boost::lexical_cast<long>(std::string("-3333"));

However, casting to double works fine.

We're currently using gcc 4.7.1 on a OpenSuse? 12.1 platform.

Attachments (2)

7814.patch (605 bytes) - added by alexey kutumov <alexey.kutumov@…> 5 years ago.
lexical_cast.hpp.patch (5.0 KB) - added by Antony Polukhin 5 years ago.
More generic patch

Download all attachments as: .zip

Change History (12)

comment:1 Changed 5 years ago by Antony Polukhin

Status: newassigned

Changed 5 years ago by alexey kutumov <alexey.kutumov@…>

Attachment: 7814.patch added

comment:2 Changed 5 years ago by alexey kutumov <alexey.kutumov@…>

The problem is in numeric_limits::min, because negating of minimum value of signed type is not representable as signed type (but representable as unsigned), so this line is incorrect:

utype const comp_val = static_cast<utype>(-(std::numeric_limits<Type>::min)());

Patch 7814.patch solves this problem

comment:3 Changed 5 years ago by Antony Polukhin

That is not the only place where the problem occurs. There are several more places, where unary negation occurs, and they also need fixes (however they occur only when min/max value for a number is casted). Fast fixes did not help, because even some functions from std namespace trigger coredump.

I am afraid, that this issue won't be fixed in boost 1.53, but I'll try to find a good solution for the problem till 1.54

comment:4 in reply to:  3 ; Changed 5 years ago by alexey kutumov <alexey.kutumov@…>

Replying to apolukhin:

Fast fixes did not help, because even some functions from std namespace trigger coredump.

Could you give example (related to lexical_cast) when coredump occurs

comment:5 Changed 5 years ago by Antony Polukhin

I've added a patch, that fixes all the issues (even on clang, which is more strict in some cases). This patch is also fixes some warnings on VC++. I'll commit it after it passes all the tests on VC++ without a warning and fix for #7799 will be merged to release branch.

comment:6 in reply to:  4 Changed 5 years ago by Antony Polukhin

Replying to alexey kutumov <alexey.kutumov@…>:

Replying to apolukhin:

Fast fixes did not help, because even some functions from std namespace trigger coredump.

Could you give example (related to lexical_cast) when coredump occurs

It was some code like:

template <class T>
void test_impl() {
    typedef std::numeric_limits<T> limits;
    boost::lexical_cast<std::string>((limits::min)());
    boost::lexical_cast<std::string>((limits::max)());
    // boost::lexical_cast<T>("lexical representation of limits::min or limits::max");
}

int main() {
    test_impl<int>();
    test_impl<unsigned int>();
    boost::lexical_cast<int>(0.0f); // Fails only on `clang -ftrapv`
}

Changed 5 years ago by Antony Polukhin

Attachment: lexical_cast.hpp.patch added

More generic patch

comment:7 Changed 5 years ago by Antony Polukhin

Milestone: To Be Determined
Severity: ProblemRegression

Updated patch with better one, fixed a bug with conversions of signed integers to unsigned integers

comment:8 Changed 5 years ago by Antony Polukhin

(In [82227]) More strict tests, less workarounds, bugfixes (refs #7814)

comment:9 Changed 5 years ago by Antony Polukhin

Milestone: Boost 1.53.0
Resolution: fixed
Status: assignedclosed

Fixed in [82268]

comment:10 Changed 5 years ago by Antony Polukhin

(In [82694]) More tests (refs #7814)

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Antony Polukhin.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.