Fehler nur beim Debuggen



  • Hi,

    ich habe einen Code, der sich ohne Fehler ausführen läßt.
    Beim Debuggen kommt eine Fehlermeldung (HEAP Block at 00134B0 modified at 00134D8 past requested size of 20).
    Was kann ich da machen?



  • An welcher Stelle im Code kommt diese Fehlermeldung? Immer an der gleichen? Zeig mal das Codestück und eventuelle Initialisierungen oder Ähnliches an den verwendeten Variablen.



  • Die Fehlermeldung kommt immer beim letzten breakpoint.

    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    #define DIM 2
    
    #define iterate(w) (w[1]+w[0]*3)
    
    #define sqr(x) ((x)*(x))
    
    struct Particle {
    	double	m;
    	double  x[DIM];
    	double  F[DIM];
    	double  F_old[DIM];
    	double  v[DIM];
    };
    
    struct ParticleList {
    	struct Particle p;
    	struct ParticleList *next;
    };
    
    struct Zelle {
    	struct ParticleList *Cell;
    };
    
    void insertList(struct ParticleList *q1,struct ParticleList *i2);
    
    struct ParticleList* deleteList(struct ParticleList *q);
    
    void gridInit(struct Zelle *grid,struct Particle *p,struct Particle p0,int c_anz,int N,int *nc);
    
    void moveParticles(struct Zelle *grid,int *nc, double *l);
    
    void output(struct Zelle *grid, FILE *f,int *nc);
    
    int ic[2],d,c_anz=1,nc[DIM],N=2;/*N anzahl particel*/
    struct Particle p[N],p0;
    struct ParticleList *lz1,*i2;
    double r_cut=1.3, delta_t=0.1, l[DIM]=2,2;
    FILE *f;
    
    int main(){
    	p0.m=0;
    	p[0].m=1.0; p[0].x[0]=2.5; p[0].x[1]=0; p[0].v[0]=0; p[0].v[1]=0;
    	p[1].m=3e-6;p[1].x[0]=0; p[1].x[1]=1.3; p[1].v[0]=4; p[1].v[1]=4;
    	for(d=0;d<DIM;d++){
    		nc[d]=ceil(l[d]/r_cut);		/*anzahl zellen in einer richtung*/
    		c_anz*=nc[d];					/*absolut anzahl zell*/
    	}
    	struct Zelle *grid=(struct Zelle*)malloc(c_anz*N*sizeof(grid));
    	gridInit(grid,p,p0,c_anz,N,nc);
    	if ((f=fopen("ausgabatei","w"))==NULL)
    			printf("nüscht\n");
    	output(grid,f,nc);
    	moveParticles(grid,nc,l);
    	output(grid,f,nc);
    	fclose(f);
    	free(grid);
    	return (0);
    }
    
    void insertList(struct ParticleList *q1,struct ParticleList *i2){
    	i2->next=q1->next;
    	q1->next=i2;
    	}
    
    struct ParticleList* deleteList(struct ParticleList *i){
    		i2=i->next;
    		i->next=i->next->next;
    		return i2;
    
    }
    
    void gridInit (struct Zelle *grid,struct Particle *p,struct Particle p0,int c_anz,int N,int *nc){
    			int ic[DIM],kc[DIM],j,k,a;
    			for (ic[0]=0;ic[0]<=nc[0];ic[0]++){
    				for (ic[1]=0;ic[1]<=nc[1];ic[1]++){
    					lz1=NULL;
    					for(j=0;j<N+1;j++){
    							struct ParticleList *i=malloc(sizeof(struct ParticleList));
    							if(j==N)
    								i->p=p0;
    							else
    								i->p=p[j];
    							i->next=lz1;
    							lz1=i;
    					}
    					(&grid[iterate(ic)])->Cell=lz1;/*ic-te Zelle im grid*/
    
    				}
    				ic[1]=ic[1]-1;
    			}
    }
    
    void moveParticles(struct Zelle *grid,int *nc, double *l){
    	int ic[DIM],kc[DIM],d,n;
    	for(ic[0]=0;ic[0]<=nc[0];ic[0]++)
    		for(ic[1]=0;ic[1]<=nc[1];ic[1]++){
    			struct ParticleList *q=(&grid[iterate(ic)])->Cell;
    			struct ParticleList *i;
    			i=q;
    			while(NULL != i->next){
    					for(d=0;d<DIM;d++){
    						kc[d]=floor(i->next->p.x[d]);
    						if(i->next->p.x[d]>3){
    							kc[d]=0;
    							i->next->p.x[d]=0;
    						}
    						if(i->next->p.x[d]<0){
    							kc[d]=2;
    							i->next->p.x[d]=3;
    						}
    					}
    					if(kc[1]!=ic[1]||kc[0]!=ic[0]){
    						deleteList(i);
    						n=iterate(kc);
    						struct ParticleList *q1=(&grid[iterate(kc)])->Cell;
    						insertList(q1,i2);
    
    					}
    					else i=i->next;
    
    			}
    		}
    
    }
    
    void output(struct Zelle *grid, FILE *f,int *nc){
    	int ic[DIM],d;
    	struct ParticleList *i;
    		for (ic[0]=0;ic[0]<=nc[0];ic[0]++){
    				for (ic[1]=0;ic[1]<=nc[1];ic[1]++){
    					for(i=(&grid[iterate(ic)])->Cell;NULL!=i;i=i->next){
    						fprintf(f,"grid %-10d% ",iterate(ic));
    						fprintf(f,"zellnummer %-4d%-4d",ic[0],ic[1]);
    						fprintf(f,"x0 %-4f",i->p.x[0]);
    						fprintf(f," x1 %-4f\n",i->p.x[1]);
    					}
    
    				}
    		ic[1]=ic[1]-1;
    		}
    
    }
    


  • docu schrieb:

    Die Fehlermeldung kommt immer beim letzten breakpoint.

    Sehr interesant, aber leider kann ich nicht erraten wo dein letzter Breakpoint ist. Und den ganzen Code jetzt durchzuforsten, ist zu aufwändig. Also bitte etwas genauer.



  • Es spiel keine Rolle an welcher Stelle der breakpoint ist. Ich habe versucht breakpoints an unterschiedlichen Stellen und auch mehrere zu setzten. Egal an welcher Stelle der breakpoint steht, es kommt immer am letzen die Fehlermeldung.
    Was ist ein HEAP Block?


Anmelden zum Antworten