Opened 10 years ago

Closed 10 years ago

Last modified 10 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@…> 10 years ago.
lexical_cast.hpp.patch (5.0 KB ) - added by Antony Polukhin 10 years ago.
More generic patch

Download all attachments as: .zip

Change History (12)

comment:1 by Antony Polukhin, 10 years ago

Status: newassigned

by alexey kutumov <alexey.kutumov@…>, 10 years ago

Attachment: 7814.patch added

comment:2 by alexey kutumov <alexey.kutumov@…>, 10 years ago

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 by Antony Polukhin, 10 years ago

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

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

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 by Antony Polukhin, 10 years ago

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.

in reply to:  4 comment:6 by Antony Polukhin, 10 years ago

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`
}

by Antony Polukhin, 10 years ago

Attachment: lexical_cast.hpp.patch added

More generic patch

comment:7 by Antony Polukhin, 10 years ago

Milestone: To Be Determined
Severity: ProblemRegression

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

comment:8 by Antony Polukhin, 10 years ago

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

comment:9 by Antony Polukhin, 10 years ago

Milestone: Boost 1.53.0
Resolution: fixed
Status: assignedclosed

Fixed in [82268]

comment:10 by Antony Polukhin, 10 years ago

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

Note: See TracTickets for help on using tickets.