#7814 closed Bugs (fixed)
Signal 6 coredump on lexical_cast with gcc option trapv
Reported by: | 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)
Change History (12)
comment:1 by , 10 years ago
Status: | new → assigned |
---|
by , 10 years ago
Attachment: | 7814.patch added |
---|
comment:2 by , 10 years ago
follow-up: 4 comment:3 by , 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
follow-up: 6 comment:4 by , 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 , 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.
comment:6 by , 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` }
comment:7 by , 10 years ago
Milestone: | To Be Determined |
---|---|
Severity: | Problem → Regression |
Updated patch with better one, fixed a bug with conversions of signed integers to unsigned integers
comment:9 by , 10 years ago
Milestone: | → Boost 1.53.0 |
---|---|
Resolution: | → fixed |
Status: | assigned → closed |
Fixed in [82268]
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:
Patch 7814.patch solves this problem