Opened 13 years ago

Closed 13 years ago

#3100 closed Bugs (wontfix)

boost::math::binomial_coefficient causes Aborted (core dumped)

Reported by: jhair.tocancipa@… Owned by: John Maddock
Milestone: Boost 1.40.0 Component: math
Version: Boost 1.38.0 Severity: Problem
Keywords: Cc:

Description

The following program:

--- #include <boost/math/special_functions/binomial.hpp>

int main () {

boost::math::binomial_coefficient<int>(6, 2);

} ---

causes:

$ ./a.out terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::bad_lexical_cast> >'

what(): bad lexical cast: source type value could not be interpreted as target

Aborted (core dumped)

gdb says:

$ gdb ./a.out core GNU gdb 6.8-debian Copyright (C) 2008 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "i486-linux-gnu"...

warning: Can't read pathname for load map: Input/output error. Reading symbols from /home/jtocancipa/tmp/boost/lib/libboost_math_c99-gcc42-mt-1_38.so.1.38.0...done. Loaded symbols for /home/jtocancipa/tmp/boost/lib/libboost_math_c99-gcc42-mt-1_38.so.1.38.0 Reading symbols from /usr/lib/libstdc++.so.6...done. Loaded symbols for /usr/lib/libstdc++.so.6 Reading symbols from /lib/tls/i686/cmov/libm.so.6...done. Loaded symbols for /lib/tls/i686/cmov/libm.so.6 Reading symbols from /lib/libgcc_s.so.1...done. Loaded symbols for /lib/libgcc_s.so.1 Reading symbols from /lib/tls/i686/cmov/libc.so.6...done. Loaded symbols for /lib/tls/i686/cmov/libc.so.6 Reading symbols from /lib/tls/i686/cmov/librt.so.1...done. Loaded symbols for /lib/tls/i686/cmov/librt.so.1 Reading symbols from /lib/tls/i686/cmov/libpthread.so.0...done. Loaded symbols for /lib/tls/i686/cmov/libpthread.so.0 Reading symbols from /lib/ld-linux.so.2...done. Loaded symbols for /lib/ld-linux.so.2 Core was generated by `./a.out'. Program terminated with signal 6, Aborted. [New process 22772] #0 0xb7f53410 in kernel_vsyscall () (gdb) bt 100 #0 0xb7f53410 in kernel_vsyscall () #1 0xb7cd5085 in raise () from /lib/tls/i686/cmov/libc.so.6 #2 0xb7cd6a01 in abort () from /lib/tls/i686/cmov/libc.so.6 #3 0xb7ee5480 in gnu_cxx::verbose_terminate_handler () from /usr/lib/libstdc++.so.6 #4 0xb7ee2d05 in ?? () from /usr/lib/libstdc++.so.6 #5 0xb7ee2d42 in std::terminate () from /usr/lib/libstdc++.so.6 #6 0xb7ee2e6a in cxa_throw () from /usr/lib/libstdc++.so.6 #7 0x0805da35 in boost::throw_exception<boost::bad_lexical_cast> () #8 0x0805db17 in boost::detail::lexical_cast<int, char const*, false, char> () #9 0x0805dd3e in boost::lexical_cast<int, char [11]> () #10 0x0805edfe in boost::math::unchecked_factorial<int> () #11 0x08061d77 in boost::math::binomial_coefficient<int, boost::math::policies::policy<boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy> > () #12 0x08061ef5 in boost::math::binomial_coefficient<int> () #13 0x08050e35 in main ()

Attachments (1)

foo.cpp (119 bytes ) - added by anonymous 13 years ago.

Download all attachments as: .zip

Change History (2)

by anonymous, 13 years ago

Attachment: foo.cpp added

comment:1 by John Maddock, 13 years ago

Resolution: wontfix
Status: newclosed

This function, and the similar factorial functions are not intended to be used with integer types: doing so is generally speaking unsafe, because any non-trivial example will return a result too large to be represented in an integer type.

I'll add a static-assertion to that effect so that in future this code doesn't compile.

Regards, John Maddock.

Note: See TracTickets for help on using tickets.