Bonjour,
Après la copie d'un pointeur dans un autre, j'obtiens une erreur de segmentation mais je ne comprends pas pourquoi.
Voici le code :
j'ai fais une recherche avec Valgrind mais je ne comprends pas où est l'erreur.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111 void fullTreeInit(Element * elt, int depthTreeCurrent, int randDepth, vector<Element*>& leaves, int nbSeqByST, int *tabSeq, string * aligt, int racine, Element *father){ //si le noeud est la racine, racine=0 sinon racine=1 //cout<<"nbSeqByST : "<<nbSeqByST<<endl; //cout<<"randDepth : "<<randDepth<<endl; if(depthTreeCurrent==randDepth){ elt->STl=NULL; elt->STr=NULL; elt->posGap=-1; elt->lengthGap=-1; //elt->tabSequenceInST=NULL; elt->sizeTab = nbSeqByST; if(nbSeqByST==1){ elt->indexSequence=tabSeq[0]; //elt->tabSequenceInST=(int*)malloc(elt->sizeTab*sizeof(int)); memcpy( elt->tabSequenceInST, tabSeq, sizeof(elt->tabSequenceInST) ); //elt->tabSequenceInST=tabSeq; } else{ elt->indexSequence=-1; //elt->tabSequenceInST=NULL; } } else{ //création des 2 sous arbres //~ if(racine==1){ //~ elt->nodeFather=father; //~ } elt->STl = new Element(); elt->STr = new Element(); elt->STl->nodeFather=elt; elt->STr->nodeFather=elt; elt->sizeTab = nbSeqByST; elt->indexSequence=-1; // cout<<"test"<<endl; // for(int i=0;i<elt->sizeTab;i++){ // cout<<"tabSeq : "<<tabSeq[i]<<endl; // } if(nbSeqByST!=0){ memcpy( elt->tabSequenceInST, tabSeq, sizeof(elt->tabSequenceInST)); } //on n'ajoute pas de gap sur un noeud contenant toutes les séquences if(nbSeqByST==nbSequence){ elt->posGap=-1; elt->lengthGap=-1; } else{ int minLength=min(nbSeqByST, tabSeq); if(tossCoin(1.0)){ elt->posGap=random(0, minLength+1);//choix au hasard d'un nombre pour la position des gaps elt->lengthGap=rand() %10+1;//nombre au hasard pour le nombre de gaps ajoutés for(int j=0;j<nbSeqByST;j++){ int idSeq = tabSeq[j]; string seqGap=aligt[idSeq]; string newSeqGap=""; //~ aligt[idSeq]=addGap(seqGap, seqGap.size(), elt->posGap, elt->lengthGap, newSeqGap); } } else{ elt->posGap=-1; elt->lengthGap=-1; } } int sizeTabL=0; int sizeTabR=0; int nbLeavesCurrent = expo(2, randDepth-depthTreeCurrent);//nombre de feuilles à* la fin du sous arbre sizeTabL=random(0, nbSeqByST+1); sizeTabL=seqShareRandom(nbLeavesCurrent, nbSeqByST, sizeTabL); sizeTabR=nbSeqByST-sizeTabL; //tableau avec les séquences se trouvant dans le sous arbre int tabSTr[sizeTabR]; int tabSTl[sizeTabR]; //ajout au hasard des séquences dans les tableaux contenant les séquences dans le sous arbre int r=0; int l=0; for(int i=0; i<nbSeqByST; i++){ int a=random(0,2); if(a==0 && l<sizeTabL){ tabSTl[l]=tabSeq[i]; l++; } else{ if(r<sizeTabR){ tabSTr[r]=tabSeq[i]; r++; } else{ tabSTl[l]=tabSeq[i]; l++; } } } //initialisation noeud père fullTreeInit(elt->STl, depthTreeCurrent+1, randDepth, leaves, sizeTabL, tabSTl, aligt, 1, elt); fullTreeInit(elt->STr, depthTreeCurrent+1, randDepth, leaves, sizeTabR, tabSTr, aligt, 1, elt); } }
Est ce que quelqu'un peut m'aider?Stack overflow in thread 1: can't grow stack to 0x7fe801fe0
==5376==
==5376== Process terminating with default action of signal 11 (SIGSEGV)
==5376== Access not within mapped region at address 0x7FE801FE0
==5376== at 0x4C28AEA: operator new(unsigned long) (vg_replace_malloc.c:261)
==5376== If you believe this happened as a result of a stack
==5376== overflow in your program's main thread (unlikely but
==5376== possible), you can try to increase the size of the
==5376== main thread stack using the --main-stacksize= flag.
==5376== The main thread stack size used in this run was 8388608.
==5376== Stack overflow in thread 1: can't grow stack to 0x7fe801fd8
==5376==
==5376== Process terminating with default action of signal 11 (SIGSEGV)
==5376== Access not within mapped region at address 0x7FE801FD8
==5376== at 0x4A2359C: _vgnU_freeres (vg_preloaded.c:58)
==5376== If you believe this happened as a result of a stack
==5376== overflow in your program's main thread (unlikely but
==5376== possible), you can try to increase the size of the
==5376== main thread stack using the --main-stacksize= flag.
==5376== The main thread stack size used in this run was 8388608.
==5376==
==5376== HEAP SUMMARY:
==5376== in use at exit: 53,344,335 bytes in 213,176 blocks
==5376== total heap usage: 222,618 allocs, 9,442 frees, 54,204,936 bytes allocated
==5376==
==5376== LEAK SUMMARY:
==5376== definitely lost: 0 bytes in 0 blocks
==5376== indirectly lost: 0 bytes in 0 blocks
==5376== possibly lost: 2,407 bytes in 45 blocks
==5376== still reachable: 53,341,928 bytes in 213,131 blocks
==5376== suppressed: 0 bytes in 0 blocks
==5376== Rerun with --leak-check=full to see details of leaked memory
==5376==
==5376== For counts of detected and suppressed errors, rerun with: -v
==5376== Use --track-origins=yes to see where uninitialised values come from
==5376== ERROR SUMMARY: 12902 errors from 7 contexts (suppressed: 4 from 4)
Erreur de segmentation
Merci
Alaninho
Partager