Need help for Access violation (solved!)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • casybay
    New Member
    • Oct 2007
    • 35

    Need help for Access violation (solved!)

    Hi all,

    I encounter a 'Access violation writing location 0x00e1d2e4' when executing my code. It worked fine when the size was smaller. The following is the code. Any help will be appreicated!!

    Code:
            int *distance = (int*)malloc(sizeof(int)*size);
            memset(distance,0,size*sizeof(int));
            int *trace = (int*)malloc(sizeof(int)*size);
            memset(trace,0,size*sizeof(int));
    
            for(i=0;i<targetSize;i++){
               *(distance+i)=0;
               *(trace+i)=STOP;
            }
            for(i=1;i<querySize;i++){
               *(distance+i*querySize)=0;
               //The program breaks here.
               *(trace+i*querySize)=STOP;
            }
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Keep in mind that if size=1, then there is 1 element. That means trace+i is outside the allocation.

    Comment

    Working...