Thread: Segmentation Fault Help

  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    3

    Segmentation Fault Help

    Every time we try to run the following code we are getting segmentation fault errors. The help would be appreciated. This is what we are trying to run.

    Code:
    #include "local.h"
    #include <string.h>
    #include <stdio.h>
    #include <ctype.h>
    
    main()
    {
            void exit();
            int fd,fd1,j,ret;
    char c,cus[10];
    clearstr(10,cus);
           
    printf("HERE we aRE !\n");
    for (fd=0;fd<20;fd++){ putchar('-');}
    c=getchar();
    putchar(c);
    for (fd=0;fd<20;fd++){ putchar('-');}
    
    getcus(10,41,12,4,cus);
    printf("HERE we aRE !%s|\n",cus);
    
    
    
            exit(0);
    }
    getcus is running form the following code

    Code:
    #include     "nei.h"
    #include     "string.h"
    
    getcus(l,m,n,o,k,pr)
    char pr[];
    int k;
    int l,m,n,o;                    /* pos data- l,m   error- n,o   */
    {
            int i,j,c,d,e;
    
            eraseat(n,o);
            printat(n,o,"enter data"); putchar(BL);
            set_curs(l,m);
            for(j=0;j<k;j++)
                    putchar('_');
            set_curs(l,m);
    
            i=0;
            while ((c=getchar())!='\n'){
                    if (i<k ){
                    pr[i]=(isupper(c) ? tolower(c) : c);
                    i++;
                    }
            pr[i]='\0';
            }
            blankat(l,m,k+1);
            printat(l,m,pr);
    }
    Thank you for your time.

  2. #2
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,671
    Time to learn debugging! See this post here.

    Why are you using ancient K&R style function declarations? This

    Code:
    getcus(l,m,n,o,k,pr)
    char pr[];
    int k;
    int l,m,n,o;                    /* pos data- l,m   error- n,o   */
    {
    should be

    Code:
    void getcus(int l, int m, int n, int o, int k, char *pr) {
    and with that many arguments, I might suggest using a struct to hold them.

  3. #3
    Registered User
    Join Date
    Feb 2012
    Posts
    3
    yeah the code we are trying to work with was written over 15 years ago -_-. I am just trying to get this working again since we were upgrading to fedora 16. We can't afford to upgrade all of our software so we running on this old code. It worked on fedora 10 then we had an incident where someone did /b* instead of /b and everything was wiped but we reinstalled everything and we are having segmentation fault errors. Do you think maybe the issue has to do with the way we installed fedora on the system?
    Last edited by Sergio Lopez; 02-21-2012 at 09:41 AM.

  4. #4
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,671
    I doubt it has anything to do with your installation.

    Just do the debugging I pointed out. Segmentation faults are easy to diagnose when you do as I instruct in that thread.

  5. #5
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    Probably overrunning the pr[10] array.

  6. #6
    Registered User
    Join Date
    Feb 2012
    Posts
    3
    We tried running the debugger and I get this error.
    Code:
    /1neibin/cn: In function `_fini':
    (.fini+0x0): multiple definition of `_fini'
    /usr/lib/gcc/i686-redhat-linux/4.6.2/../../../crti.o:(.fini+0x0): first defined here
    /1neibin/cn: In function `__data_start':
    (.data+0x0): multiple definition of `__data_start'e
    /usr/lib/gcc/i686-redhat-linux/4.6.2/../../../crt1.o:(.data+0x0): first defined here
    /1neibin/cn:(.rodata+0x8): multiple definition of `__dso_handle'
    /usr/lib/gcc/i686-redhat-linux/4.6.2/crtbegin.o:(.rodata+0x0): first defined here
    /1neibin/cn:(.rodata+0x4): multiple definition of `_IO_stdin_used'
    /usr/lib/gcc/i686-redhat-linux/4.6.2/../../../crt1.o:(.rodata.cst4+0x0): first defined here
    /1neibin/cn: In function `_start':
    (.text+0x0): multiple definition of `_start'
    /usr/lib/gcc/i686-redhat-linux/4.6.2/../../../crt1.o:(.text+0x0): first defined here
    /1neibin/cn:(.rodata+0x0): multiple definition of `_fp_hw'
    /usr/lib/gcc/i686-redhat-linux/4.6.2/../../../crt1.o:(.rodata+0x0): first defined here
    /1neibin/cn: In function `_init':
    (.init+0x0): multiple definition of `_init'
    /usr/lib/gcc/i686-redhat-linux/4.6.2/../../../crti.o:(.init+0x0): first defined here
    /usr/lib/gcc/i686-redhat-linux/4.6.2/crtend.o:(.dtors+0x0): multiple definition of `__DTOR_END__'
    /1neibin/cn:(.dtors+0x4): first defined here
    /usr/bin/ld: error in /1neibin/cn(.eh_frame); no .eh_frame_hdr table will be created.
    collect2: ld returned 1 exit status

  7. #7
    Registered User
    Join Date
    Jun 2011
    Posts
    88
    Quote Originally Posted by Sergio Lopez View Post
    E

    getcus(10,41,12,4,cus);

    Code:
    #include     "nei.h"
    #include     "string.h"
    
    getcus(l,m,n,o,k,pr
    Thank you for your time.
    your call has 5 args , you function definition has 6 args

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Segmentation fault, how come?
    By Fader_Berg in forum C Programming
    Replies: 18
    Last Post: 08-31-2010, 01:58 AM
  2. Odd Segmentation Fault
    By JohnnyAppleseed in forum C Programming
    Replies: 7
    Last Post: 08-24-2010, 12:01 PM
  3. Segmentation fault
    By gkoenig in forum C Programming
    Replies: 3
    Last Post: 03-01-2008, 02:14 PM
  4. Segmentation fault
    By tameeyore in forum C Programming
    Replies: 4
    Last Post: 02-26-2005, 01:49 PM
  5. segmentation fault and memory fault
    By Unregistered in forum C Programming
    Replies: 12
    Last Post: 04-02-2002, 11:09 PM