Menu

#51 Error on 64 bits archi when filename has no extension

Program crashes
open
nobody
5
2018-09-07
2009-10-16
Anonymous
No

Hello,

when running cccc on x86_64 archi with a filename that has no extension, it crashes. The core give the following info:

(gdb) bt
(...)
#7 0x00007f4e0b809b93 in std::string::substr(unsigned long, unsigned long) const () from /usr/lib/libstdc++.so.6
#8 0x000000000043ec41 in CCCC_Options::getFileLanguage (filename=...) at cccc_opt.cc:229
#9 0x00000000004374b0 in Main::ParseFiles (this=0xb40ca0) at ccccmain.cc:354
#10 0x000000000043856f in main (argc=2, argv=0x7fff215ed878) at ccccmain.cc:725

(gdb) frame 8
#8 0x000000000043ec41 in CCCC_Options::getFileLanguage (filename=...) at cccc_opt.cc:229
229 extension=filename.substr(extpos);

(gdb) list
226 unsigned int extpos=filename.rfind(".");
227 if(extpos!=string::npos)
228 {
229 extension=filename.substr(extpos);

(gdb) p extpos
$1 = 4294967295

(gdb) p filename
$2 = (const std::string &) @0x7fff215ed6d0: {static npos = 18446744073709551615,
_M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>}, _M_p = 0xb42468 "basic/CVS"}}

Obviously the problem come from the usage of unsigned int for extpos when the good type is size_t.

So simple patch would be in cccc_opt.cc:226:
<unsigned int extpos=filename.rfind(".");
>size_t extpos=filename.rfind(".");

Regards,
Colin

Discussion

  • Thomas Anthony Francis Thorne

    Is it possible that this bug related to the one I have been seeing on Ubuntu recently? Full details of that are on lunchpad under bug #1504454.

    Apport gave the stack trace for the problem as:

    StacktraceTop:
     __gnu_cxx::__verbose_terminate_handler () at ../../../../src/libstdc++-v3/libsupc++/vterminate.cc:95
     __cxxabiv1::__terminate (handler=<optimized out>) at ../../../../src/libstdc++-v3/libsupc++/eh_terminate.cc:38
     std::terminate () at ../../../../src/libstdc++-v3/libsupc++/eh_terminate.cc:48
     __cxxabiv1::__cxa_throw (obj=0x1000df0, tinfo=0x7fafff84e1f0 <typeinfo for std::out_of_range>, dest=0x7fafff5d88b0 <std::out_of_range::~out_of_range()>) at ../../../../src/libstdc++-v3/libsupc++/eh_throw.cc:87
     std::__throw_out_of_range (__s=__s@entry=0x4566fb "basic_string::substr") at ../../../../../src/libstdc++-v3/src/c++11/functexcept.cc:80
    

    Ubuntu gives the version I am using as cccc 1:3.1.4-6

     
  • Colin Watson

    Colin Watson - 2018-09-07

    Yes, that's the same bug. I'm applying this patch for my next Debian upload.

     

Log in to post a comment.