C++: la glibc détecté corrompu double liste chaînée: 0x08f8f148

Je suis en train d'écrire un programme qui doit analyser la variable d'environnement PATH à un séparateur ":". Tout semble fonctionner correctement jusqu'à ce que la fonction chop tente de retourner le tableau. J'ai ensuite recevoir le message d'erreur suivant: "glibc détecté ./un.out: corrompu double liste chaînée: 0x08f8f148". J'utilise les hacher également d'analyser la saisie de l'utilisateur et qu'il fonctionne correctement. Toute aide est grandement appréciée.

//Parse environment variable
    char const* pPath = getenv("PATH");
    if (pPath == NULL){;}
    else{
        string ePath(pPath);
        envp = chop(ePath,':');
    }

char **chop(string s, char c){
    int i, j, k, len, words = 0;
    len = s.length();
    //determine # of words
    for(i=0;i<len+1;i++){
        if(s[i] == c || s[i] == '
//Parse environment variable
char const* pPath = getenv("PATH");
if (pPath == NULL){;}
else{
string ePath(pPath);
envp = chop(ePath,':');
}
char **chop(string s, char c){
int i, j, k, len, words = 0;
len = s.length();
//determine # of words
for(i=0;i<len+1;i++){
if(s[i] == c || s[i] == '\0'){words++;}
}
char **array;
string x;
//allocate memory for char pointers
if((array=(char**)malloc((words+1)*sizeof(char*))) == NULL){return NULL;}
array[0] = &x[0];
i = 0; k = 0;
//split string on char c
for(j = 1; j < (words+1); j++,k++,i++){
//read in characters until delimiter
while (s[k] != c && s[k] != '\0'){
x[i] = s[k];
i++; k++;
}
x[i] = '\0';
array[j] = &x[i+1];
}
array[j] = 0;
return array;   
}
'
){words++;} } char **array; string x; //allocate memory for char pointers if((array=(char**)malloc((words+1)*sizeof(char*))) == NULL){return NULL;} array[0] = &x[0]; i = 0; k = 0; //split string on char c for(j = 1; j < (words+1); j++,k++,i++){ //read in characters until delimiter while (s[k] != c && s[k] != '
//Parse environment variable
char const* pPath = getenv("PATH");
if (pPath == NULL){;}
else{
string ePath(pPath);
envp = chop(ePath,':');
}
char **chop(string s, char c){
int i, j, k, len, words = 0;
len = s.length();
//determine # of words
for(i=0;i<len+1;i++){
if(s[i] == c || s[i] == '\0'){words++;}
}
char **array;
string x;
//allocate memory for char pointers
if((array=(char**)malloc((words+1)*sizeof(char*))) == NULL){return NULL;}
array[0] = &x[0];
i = 0; k = 0;
//split string on char c
for(j = 1; j < (words+1); j++,k++,i++){
//read in characters until delimiter
while (s[k] != c && s[k] != '\0'){
x[i] = s[k];
i++; k++;
}
x[i] = '\0';
array[j] = &x[i+1];
}
array[j] = 0;
return array;   
}
'
){ x[i] = s[k]; i++; k++; } x[i] = '
//Parse environment variable
char const* pPath = getenv("PATH");
if (pPath == NULL){;}
else{
string ePath(pPath);
envp = chop(ePath,':');
}
char **chop(string s, char c){
int i, j, k, len, words = 0;
len = s.length();
//determine # of words
for(i=0;i<len+1;i++){
if(s[i] == c || s[i] == '\0'){words++;}
}
char **array;
string x;
//allocate memory for char pointers
if((array=(char**)malloc((words+1)*sizeof(char*))) == NULL){return NULL;}
array[0] = &x[0];
i = 0; k = 0;
//split string on char c
for(j = 1; j < (words+1); j++,k++,i++){
//read in characters until delimiter
while (s[k] != c && s[k] != '\0'){
x[i] = s[k];
i++; k++;
}
x[i] = '\0';
array[j] = &x[i+1];
}
array[j] = 0;
return array;   
}
'
; array[j] = &x[i+1]; } array[j] = 0; return array; }
InformationsquelleAutor user2829557 | 2013-09-30