Thread: getting errrrrors

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    10

    getting errrrrors

    when i run my program following errors showing.........

    *** glibc detected *** ./a.out: double free or corruption (top): 0x087c8008 ***
    ======= Backtrace: =========
    /lib/tls/i686/cmov/libc.so.6[0xb7e003f4]
    /lib/tls/i686/cmov/libc.so.6(cfree+0x96)[0xb7e02456]
    /lib/tls/i686/cmov/libc.so.6(fclose+0x144)[0xb7df0004]
    ./a.out[0x8048929]
    /lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe5)[0xb7da7685]
    ./a.out[0x8048451]
    ======= Memory map: ========
    08048000-08049000 r-xp 00000000 07:00 260627 /home/group20/Desktop/data/a.out
    08049000-0804a000 r--p 00000000 07:00 260627 /home/group20/Desktop/data/a.out
    0804a000-0804d000 rw-p 00001000 07:00 260627 /home/group20/Desktop/data/a.out
    0804d000-0841e000 rw-p 0804d000 00:00 0
    087c8000-087e9000 rw-p 087c8000 00:00 0 [heap]
    b7c00000-b7c21000 rw-p b7c00000 00:00 0
    b7c21000-b7d00000 ---p b7c21000 00:00 0
    b7d81000-b7d8e000 r-xp 00000000 07:00 350254 /lib/libgcc_s.so.1
    b7d8e000-b7d8f000 r--p 0000c000 07:00 350254 /lib/libgcc_s.so.1
    b7d8f000-b7d90000 rw-p 0000d000 07:00 350254 /lib/libgcc_s.so.1
    b7d90000-b7d91000 rw-p b7d90000 00:00 0
    b7d91000-b7ee9000 r-xp 00000000 07:00 367491 /lib/tls/i686/cmov/libc-2.8.90.so
    b7ee9000-b7eeb000 r--p 00158000 07:00 367491 /lib/tls/i686/cmov/libc-2.8.90.so
    b7eeb000-b7eec000 rw-p 0015a000 07:00 367491 /lib/tls/i686/cmov/libc-2.8.90.so
    b7eec000-b7eef000 rw-p b7eec000 00:00 0
    b7efc000-b7efe000 rw-p b7efc000 00:00 0
    b7efe000-b7f18000 r-xp 00000000 07:00 350211 /lib/ld-2.8.90.so
    b7f18000-b7f19000 r-xp b7f18000 00:00 0 [vdso]
    b7f19000-b7f1a000 r--p 0001a000 07:00 350211 /lib/ld-2.8.90.so
    b7f1a000-b7f1b000 rw-p 0001b000 07:00 350211 /lib/ld-2.8.90.so
    bf805000-bf81a000 rw-p bffeb000 00:00 0 [stack]
    Aborted


    i have illustrated my code below............
    Code:
    
    
    
    
    
    #include <stdio.h>
    
    #include <limits.h>
    
    #include <assert.h>
    
    
    
    
    
    typedef enum {false, true} bool; /* The order is rather important to
    
                                        get the boolean values right. */
    
    typedef char *string;
    
    
    
    
    
    
    /*
    
      We define a type of values for weights, which can be changed (to
    
      e.g. floats) if required.But the algorithm works for nonnegative values only.
    
    */
    
    
    
    #define oo UINT_MAX /* infinity is represented as the maximum unsigned int. */
    
    
    
    typedef unsigned int value;
    
    
    
    /* 
    
       In order to avoid complications with IO, we include the graph in
    
       the program directly. Of course, one wouldn't do that in practice.
    
    */
    
    
    
    
    
    /*  The (non)vertex `nonexistent' is used in order to indicate that a vertex hasn't got a predecessor
    
       in the path under consideration.  */
    
    
    
    typedef enum{ ArtsTheatre,NewArtsBlock,OpenAirTheatre,GeographyDept,FacultyOfAgriculture,PGIA,MeewathuraFarm ,FacultyOfDentalScience,FacultyOfEngineering,FacultyOfMedicine,TeachingHospital,FacultyOfScience,GeologyDepartment,VetFaculty,SwineProductionUnit,UniversityFarm,ExternalExaminationBranch,FacultyClub,HallMaintenaceDept,LandscapeBranch,MaintenanceServiceDept,SecurityOffice,SenateBuilding ,StudentCentre,TelephoneExchange,Library,USO,HealthCentre,SportsArena,Gymnasium,StaffRecreationClub,SwimmingPool,AkbarHall,ArunachalamHall,HildaObeysekaraHall,JamesPeirisHall,JayathilakaHall,MarcusFernandoHall,MarrsHall,RamanathanHall,SangamittaHall,WijewardanaHall,HindagalaHall,BhikkuHostel,KehelpannalaBhikkuHostel,Sangaramaya,GuestHouse,Stupa,ChristChurch,VCResidence ,ITCentre,Mosque,HinduKowil,Lodge,nonexistent}vertex; 
    
    
    
    
    
    const vertex first_vertex = ArtsTheatre;
    
    const vertex last_vertex = Lodge;
    
    
    
    #define no_vertices 54 /*  This has to be the same as the number
    
                             (last_vertex + 1), but being using it,it
    
                             doesn't compile... */
    
    
    
    /*This part is for getting clear output */
    
    
    
    string name[] = {"ArtsTheatre","NewArtsBlock","OpenAirTheatre","GeographyDept","FacultyOfAgriculture","PGIA","MeewathuraFarm ","FacultyOfDentalScience","FacultyOfEngineering","FacultyOfMedicine","TeachingHospital","FacultyOfScience","GeologyDepartment","VetFaculty","SwineProductionUnit","UniversityFarm","ExternalExaminationBranch","FacultyClub","HallMaintenaceDept","LandscapeBranch","MaintenanceServiceDept","SecurityOffice","SenateBuilding" ,"StudentCentre","TelephoneExchange","Library","USO","HealthCentre","SportsArena","Gymnasium","StaffRecreationClub","SwimmingPool","AkbarHall","ArunachalamHall","HildaObeysekaraHall","JamesPeirisHall","JayathilakaHall","MarcusFernandoHall","MarrsHall","RamanathanHall","SangamittaHall","WijewardanaHall","HindagalaHall","BhikkuHostel","KehelpannalaBhikkuHostel","Sangaramaya","GuestHouse","Stupa","ChristChurch","VCResidence","ITCentre","Mosque","HinduKowil","Lodge"};
    
    
    
    
    
    
    
    value weight[no_vertices][no_vertices] =
    
      {
    
       {0,46,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,188,oo,oo,189,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo},
    {46,0,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,188,oo,oo,oo,349,oo,oo,oo,oo,328,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,275,oo,oo,oo,oo,oo,oo}, {oo,oo,0,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,332,oo,oo,oo,oo,oo,o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o,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,98,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,oo,0}
    };
    
    
    
    
    
    
    /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *     
    
     * The implementation of Dijkstra's algorithm starts here. *
    
     * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
    
    
    
    
    
    
    
    value D[no_vertices]; 
    
    bool tight[no_vertices];
    
    vertex predecessor[no_vertices];
    
    
    
    
    
    vertex minimal_nontight() {
    
    
    
      vertex j, u;
    
    
    
      for (j = first_vertex; j <= last_vertex; j++) 
    
         if (!tight[j]) 
    
            break;
    
    
    
      assert(j <= last_vertex); 
    
    
    
      u = j; 
    
    
    
     
    
    
    
     
    
      for (j++; j <= last_vertex; j++)
    
         if (!tight[j]  &&  D[j] < D[u])
    
              u = j;
    
    
    
      /* Having checked all vertices, we now know that u has the required
    
         minimality property. */ 
    
    
    
      return u;
    
    }
    
    
    
    
    
    
    
    bool successor(vertex u, vertex z) {
    
      return (weight[u][z] != oo  &&  u != z);
    
    }
    
    
    
    
    
    
    
    
    
    void dijkstra(vertex s) {
    
    
    
      vertex z, u;
    
      int i;
    
    
    
      D[s] = 0;
    
    
    
      for (z = first_vertex; z <= last_vertex; z++) {
    
    
    
        if (z != s)
    
          D[z] = oo;
    
    
    
        tight[z] = false;
    
        predecessor[z] = nonexistent;
    
      }
    
    
    
      for (i = 0; i < no_vertices; i++) {
    
    
    
        u = minimal_nontight();
    
        tight[u] = true;
    
    
    
        /* In a disconnected graph, D[u] can be oo. But then we just move
    
           on to the next iteration of the loop.  */
    
    
    
        if (D[u] == oo)
    
          continue; /* to next iteration ofthe for loop */
    
    
    
        for (z = first_vertex; z <= last_vertex; z++)
    
          if (successor(u,z) && !tight[z] && D[u] + weight[u][z] < D[z]) {
    
            D[z] = D[u] + weight[u][z]; /* Shortcut found. */
    
            predecessor[z] = u;
    
          }
    
      }
    
    }
    
    
    
    
    
    
    
    #define stack_limit 1000000 /* Arbitrary choice. Has to be big enough to
    
                                 accomodate the largest path. */
    
    
    
    vertex stack[stack_limit];
    
    unsigned int sp = 0; /* Stack pointer. */
    
    
    
    void push(vertex u) {
    
      assert(sp < stack_limit); /* We abort if the limit is exceeded. This
    
                                   will happen if a path with more
    
                                   vertices than stack_limit is found. */
    
      stack[sp] = u;
    
      sp++;
    
    }
    
    
    
    bool stack_empty() {
    
      return (sp == 0);
    
    }
    
    
    
    vertex pop() {
    
      assert(!stack_empty()); /* We abort if the stack is empty. This will
    
                                 happen if this program has a bug. */
    
      sp--;
    
      return stack[sp];
    
    }
    
    
    
    /* End of stack digression and back to printing paths. */
    
    
    
    void print_shortest_path(vertex origin, vertex destination) {
    
    
    
      vertex v;
    
    
    
      assert(origin != nonexistent  &&  destination != nonexistent);
    
    
    
      dijkstra(origin);
    
    
    
      printf("The shortest path from %s to %s is:\n\n",
    
             name[origin], name[destination]);
    
    
    
      for (v = destination; v != origin; v = predecessor[v])
    
    
        if (v == nonexistent) {
    
          printf("nonexistent (because the graph is disconnected).\n");
    
          return;
    
        }
    
        else
    
          push(v);
    
    
    
      push(origin); 
    
    
    
      while (!stack_empty()) 
    
        printf(" %s",name[pop()]);
    
    
    
      printf(".\n\n");
    
    }
    
    
    
    
    
    /* We now run an example. */
    
    
    
    int main() {
    
        
    
      FILE *infile;
    value weight[no_vertices][no_vertices];
    value row,col;
    
    
    infile = fopen ("mapdata.txt","r");
    for (row=0; row < no_vertices; row +=1)
    {
        for (col=0; col < no_vertices; col +=1)
        {
            fscanf(infile,"%d",&weight[row][col]);
        }
    fclose(infile);
    }
    
        
    
      print_shortest_path(ArtsTheatre,Lodge);
    
      
    
      return 0; /* Return gracefully to the caller of the program
    
                   (provided the assertions above haven't failed). */
    
    }

    any suggestion would be appreciate........thanks

  2. #2
    Registered User
    Join Date
    Mar 2009
    Posts
    10
    as i think stack limit is not enough to handle largest path....if it is how i increase stack limit

    thanks........

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Can I first make the general comment that your code is a mess!

    You list 54 enums on ONE line - I'd put one on each line:
    Code:
    typedef enum
    { 
        ArtsTheatre,
        NewArtsBlock,
        OpenAirTheatre,
        GeographyDept,
        FacultyOfAgriculture,
        PGIA,
        MeewathuraFarm,
        FacultyOfDentalScience,
        FacultyOfEngineering,
        FacultyOfMedicine,
        TeachingHospital,
        FacultyOfScience,
        GeologyDepartment,
        VetFaculty,
        SwineProductionUnit,
        UniversityFarm,
        ExternalExaminationBranch,
        FacultyClub,
        HallMaintenaceDept,
        LandscapeBranch,
        MaintenanceServiceDept,
        SecurityOffice,
        SenateBuilding,
        StudentCentre,
        TelephoneExchange,
        Library,
        USO,
        HealthCentre,
        SportsArena,
        Gymnasium,
        StaffRecreationClub,
        SwimmingPool,
        AkbarHall,
        ArunachalamHall,
        HildaObeysekaraHall,
        JamesPeirisHall,
        JayathilakaHall,
        MarcusFernandoHall,
        MarrsHall,
        RamanathanHall,
        SangamittaHall,
        WijewardanaHall,
        HindagalaHall,
        BhikkuHostel,
        KehelpannalaBhikkuHostel,
        Sangaramaya,
        GuestHouse,
        Stupa,
        ChristChurch,
        VCResidence,
        ITCentre,
        Mosque,
        HinduKowil,
        Lodge,
        nonexistent
    } vertex;
    Likewise for your strings.

    You initialize the weight array, then go read data from a "mapdata" file too.

    Why do you have a define to change oo into UINT_MAX - what's wrong with a descriptive name [yes, I know, oo looks a bit like infinity, but calling it infinity, huge, or something like that would make it look less like a typo for 0].

    You also have a lot of empty lines for no apparent reason.

    As to the actual problem, I'd say you probably overwrite the end of one or another array.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Registered User
    Join Date
    Mar 2009
    Posts
    10
    thanks lot bro.......

    and i m sorry the following part should not be included in the code........
    Code:
    infile = fopen ("mapdata.txt","r");
    for (row=0; row < no_vertices; row +=1)
    {
        for (col=0; col < no_vertices; col +=1)
        {
            fscanf(infile,"%d",&weight[row][col]);
        }
    fclose(infile);
    }
    i ve written it by misstakenly

    and for real error ur comment is not clear.......could u plssssssss help me to get rid of this


    thanks onceagain

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Well, I would say that you are going over the edge in one of your arrays. I haven't analyzed your application in detail - it's a fair amount of code, and it only takes ONE little mistake to mess up.

    [And I actually prefer an application that reads data from a file than one that contains the data inside itself - it makes it much easier to change the data for one thing].

    The stack-size is probably not the problem - unless your asserts are not working. You can test that by adding "assert(0)" at the beginning of your code.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Registered User
    Join Date
    Mar 2009
    Posts
    10

    thanks

    thanks lot bro..................i got rid of the mess

    one of array element is incorrectly inserted

Popular pages Recent additions subscribe to a feed