Thread: Segmentation fault in C++ program

  1. #1
    Registered User
    Join Date
    Aug 2015
    Posts
    21

    Segmentation fault in C++ program

    Hi,

    I have a program in C/C++ that runs perfectly in my Windows 7, 32 bits.

    But when I compile it in Linux, I get - only for some files reading - the "segmentation fault" error.

    Below is the report of strace. Note: the overflow error of the file de431.eph does not happen with others smaller files. I don't know what might be causing this. The file is corrupted? Or is it too large?...

    Code:
    -bash-4.1$ strace ./swetest -p2 -j5000000 -ejplde431.eph
    execve("./swetest", ["./swetest", "-p2", "-j5000000", "-ejplde431.eph"], [/* 28 vars */]) = 0
    brk(0)                                  = 0x9d90000
    mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7705000
    access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
    open("/etc/ld.so.cache", O_RDONLY)      = 3
    fstat64(3, {st_mode=S_IFREG|0644, st_size=31601, ...}) = 0
    mmap2(NULL, 31601, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb76fd000
    close(3)                                = 0
    open("/lib/libm.so.6", O_RDONLY)        = 3
    read(3, "\177ELF\1\1\1\3\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0p4\0\0004\0\0\0"..., 512) = 512
    fstat64(3, {st_mode=S_IFREG|0755, st_size=200024, ...}) = 0
    mmap2(NULL, 168064, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb76d3000
    mmap2(0xb76fb000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x27000) = 0xb76fb000
    close(3)                                = 0
    open("/lib/libc.so.6", O_RDONLY)        = 3
    read(3, "\177ELF\1\1\1\3\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\220n\1\0004\0\0\0"..., 512) = 512
    fstat64(3, {st_mode=S_IFREG|0755, st_size=1902916, ...}) = 0
    mmap2(NULL, 1665452, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb753c000
    mmap2(0xb76cd000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x190000) = 0xb76cd000
    mmap2(0xb76d0000, 10668, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xb76d0000
    close(3)                                = 0
    mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb753b000
    set_thread_area({entry_number:-1 -> 12, base_addr:0xb753b6c0, limit:1048575, seg_32bit:1, contents:0, read_exec_only:0, limit_in_pages:1, seg_not_present:0, useable:1}) = 0
    mprotect(0xb76cd000, 8192, PROT_READ)   = 0
    mprotect(0xb76fb000, 4096, PROT_READ)   = 0
    mprotect(0xb7725000, 4096, PROT_READ)   = 0
    munmap(0xb76fd000, 31601)               = 0
    access("/etc/sysconfig/32bit_ssse3_memcpy_via_32bit_ssse3_memmove", F_OK) = -1 ENOENT (No such file or directory)
    uname({sys="Linux", node="vps.casadohosting.com", ...}) = 0
    fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 0), ...}) = 0
    mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7704000
    brk(0)                                  = 0x9d90000
    brk(0x9db1000)                          = 0x9db1000
    open("sepl_18.se1", O_RDONLY)           = -1 ENOENT (No such file or directory)
    open("sepl_18.se1", O_RDONLY)           = -1 ENOENT (No such file or directory)
    open("./sepl_18.se1", O_RDONLY)         = -1 ENOENT (No such file or directory)
    open("de431.eph", O_RDONLY)             = -1 EOVERFLOW (Value too large for defined data type)
    open("de431.eph", O_RDONLY)             = -1 EOVERFLOW (Value too large for defined data type)
    open("./de431.eph", O_RDONLY)           = -1 EOVERFLOW (Value too large for defined data type)
    --- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0} ---
    +++ killed by SIGSEGV +++
    Segmentation fault
    Might the FILE pointer be NULL for some reason?...

    I would apreciate very much for some help.

    Kind regards,

    JKepler

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    But when I compile it in Linux, I get - only for some files reading - the "segmentation fault" error.
    Have you tried running the program with your debugger? The debugger should be able to tell you where it detected the error and allow you to view the contents of the variables at the time of the crash.

    Showing the source code would probably be a good idea as well.

    Jim

  3. #3
    Registered User
    Join Date
    Aug 2015
    Posts
    21
    Quote Originally Posted by jimblumberg View Post
    Have you tried running the program with your debugger? The debugger should be able to tell you where it detected the error and allow you to view the contents of the variables at the time of the crash.

    Showing the source code would probably be a good idea as well.

    Jim
    Good evening Jim,

    I don't have gdb installed in the server...only strace. But I've managed through its information to solve the issue. Notice the file error:

    Code:
    open("de431.eph", O_RDONLY)             = -1 EOVERFLOW (Value too large for defined data type)
    I finally manage to understand the error - it wasn't in the program source code. My server is in Linux, but in a 32 bits system. So I had to compile with gcc the source but with the flag -D_FILE_OFFSET_BITS=64

    The problem vanished right away...Go figure this...damn... :/

    Regards,

    JKepler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Segmentation fault in my program
    By Dr.JacKaL in forum C Programming
    Replies: 4
    Last Post: 10-29-2014, 02:31 PM
  2. Simple program has segmentation fault??
    By fsi in forum C Programming
    Replies: 4
    Last Post: 12-04-2011, 10:25 AM
  3. Segmentation fault on my program
    By blackswan in forum C Programming
    Replies: 2
    Last Post: 05-11-2005, 04:47 PM
  4. Segmentation fault in beginning or program
    By tameeyore in forum C Programming
    Replies: 1
    Last Post: 02-26-2005, 08:16 PM
  5. Segmentation fault !, program works:S
    By jspri in forum C Programming
    Replies: 8
    Last Post: 09-28-2004, 05:25 PM