Modify

Ticket #7814 (closed Bugs: fixed)

Opened 16 months ago

Last modified 15 months ago

Signal 6 coredump on lexical_cast with gcc option trapv

Reported by: Bernd Raum <braum@…> Owned by: apolukhin
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

7814.patch Download (605 bytes) - added by alexey kutumov <alexey.kutumov@…> 16 months ago.
lexical_cast.hpp.patch Download (5.0 KB) - added by apolukhin 16 months ago.
More generic patch

Change History

comment:1 Changed 16 months ago by apolukhin

  • Status changed from new to assigned

Changed 16 months ago by alexey kutumov <alexey.kutumov@…>

comment:2 Changed 16 months 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 follow-up: ↓ 4 Changed 16 months ago by apolukhin

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 ; follow-up: ↓ 6 Changed 16 months 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 16 months ago by apolukhin

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 16 months ago by apolukhin

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 16 months ago by apolukhin

More generic patch

comment:7 Changed 16 months ago by apolukhin

  • Severity changed from Problem to Regression
  • Milestone To Be Determined deleted

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

comment:8 Changed 16 months ago by apolukhin

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

comment:9 Changed 16 months ago by apolukhin

  • Status changed from assigned to closed
  • Resolution set to fixed
  • Milestone set to Boost 1.53.0

Fixed in [82268]

comment:10 Changed 15 months ago by apolukhin

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

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


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

 
Note: See TracTickets for help on using tickets.