IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

 C Discussion :

SIGTRAP IS BACK


Sujet :

C

  1. #1
    Membre confirmé
    Homme Profil pro
    Etudiant administrateur systèmes et réseaux
    Inscrit en
    Octobre 2007
    Messages
    731
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Etudiant administrateur systèmes et réseaux

    Informations forums :
    Inscription : Octobre 2007
    Messages : 731
    Points : 467
    Points
    467
    Par défaut SIGTRAP IS BACK
    Bonsoir,

    Encore une galère dont je n'arrive pas à me dépatouiller tout seul :S

    Voici la fonction en question

    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
     
    char *get_file_number(char *file_name)
    {
        char *file_number = allocate_1D_char_ptr(5);
        char *str_dup = my_strdup(file_name);
        while( *str_dup != '\0' )
            str_dup++;
     
        int i;
        for ( i=0 ; i<4 ; i++ )
        {
            str_dup--;
            file_number[3-i]=*str_dup;
        }
     
        file_number[4]='\0';
        free(str_dup) ; str_dup = NULL;
        return file_number;
    }
    Je lance un debug : Le programme tourne jusqu'à :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    Program received signal SIGTRAP, Trace/breakpoint trap.
    In ntdll!TpWaitForAlpcCompletion () (C:\Windows\system32\ntdll.dll)
    #12 0x00401b4f in get_file_number (file_name=0x653980 "00012182.bak") at I:\Copie de file\pattern.c:97
    I:\Copie de file\pattern.c:97:2228:beg:0x401b4f
    At I:\Copie de file\pattern.c:97
    Voici le contenu des "watches" :



    Merci d'avance.
    UNE REPONSE UTILE : &|| UN PROBLEME RESOLU :

  2. #2
    Invité
    Invité(e)
    Par défaut
    Bonsoir,

    Vu les manipulations que tu fais sur ton pointeur str_dup, lors du free(), il ne pointe plus sur l'adresse allouée retournée par la fonction strdup(), d'où je pense l'erreur que tu obtiens.
    De plus n'effectuant aucune modification sur str_dup, pourquoi ne pas travailler directement sur file_name ?

  3. #3
    Membre confirmé
    Homme Profil pro
    Etudiant administrateur systèmes et réseaux
    Inscrit en
    Octobre 2007
    Messages
    731
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Etudiant administrateur systèmes et réseaux

    Informations forums :
    Inscription : Octobre 2007
    Messages : 731
    Points : 467
    Points
    467
    Par défaut
    Ben en fait c'est là que je ne suis pas sur.
    Je fais bouger ce sur quoi pointe str_dup.
    Si je le faisais directement sur file_name, celui ci ne pointerait plus sur le même chose nan ?
    Je me doutais bien que c'était un truck comme ça mais merci de confirmer que c'est bien parce que j'essaye un free sur un variable qui ne pointe plus sur l'@ du premier block mémoire d'allocation. (str_dup est bien modifié donc ?).
    Comment je fais alors pour libérer proprement str_dup ?
    Cependant, pourquoi cela marche pour une centaine de fichiers avant de planter ?

    Cordialement.
    UNE REPONSE UTILE : &|| UN PROBLEME RESOLU :

  4. #4
    Invité
    Invité(e)
    Par défaut
    Si je le faisais directement sur file_name, celui ci ne pointerait plus sur le même chose nan ?
    Bien sûr que si. file_name est un copie du pointeur que tu rentres. Et tant que tu ne modifies pas le contenu de l'adresse qu'il pointe (ce qui n'est pas le cas ici, tu ne fais que le parcourir), il n'y a aucune raison de le recopier inutilement, et de s'embêter avec un malloc/free supplémentaire.

  5. #5
    Membre confirmé
    Homme Profil pro
    Etudiant administrateur systèmes et réseaux
    Inscrit en
    Octobre 2007
    Messages
    731
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Etudiant administrateur systèmes et réseaux

    Informations forums :
    Inscription : Octobre 2007
    Messages : 731
    Points : 467
    Points
    467
    Par défaut
    Ah oui, c'est vrai, chaque paramètre de la fonction est dupliqué sur le tas c'est bien ça ?
    Ca fait longtemps que j'ai pas codé, j'oublie vite =)
    Merci pour le rafraichissement.
    UNE REPONSE UTILE : &|| UN PROBLEME RESOLU :

  6. #6
    Inactif  


    Homme Profil pro
    Doctorant sécurité informatique — Diplômé master Droit/Économie/Gestion
    Inscrit en
    Décembre 2011
    Messages
    9 012
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 31
    Localisation : France, Loire (Rhône Alpes)

    Informations professionnelles :
    Activité : Doctorant sécurité informatique — Diplômé master Droit/Économie/Gestion
    Secteur : Enseignement

    Informations forums :
    Inscription : Décembre 2011
    Messages : 9 012
    Points : 23 145
    Points
    23 145
    Par défaut
    A chaque fois que tu tu appelles une fonction, tu va empiler sur la pile (et non le tas) un emplacement pour la valeur de retour, l'adresse de retour (= là où tu étais lorsque tu as appelé la fonction) et ensuite tous les paramètres passés à ta fonction.

  7. #7
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 369
    Points : 41 518
    Points
    41 518
    Par défaut
    Aussi, vu que tu ne modifies pas la chaîne pointée par file_name, tu peux déclarer ta fonction ainsi:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    char *get_file_number(char const *file_name)
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

  8. #8
    Membre confirmé
    Homme Profil pro
    Etudiant administrateur systèmes et réseaux
    Inscrit en
    Octobre 2007
    Messages
    731
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Etudiant administrateur systèmes et réseaux

    Informations forums :
    Inscription : Octobre 2007
    Messages : 731
    Points : 467
    Points
    467
    Par défaut
    Bonjour,

    SIGTRAP is back again. Je me permets de rouvrir ce post au lieu d'en créer un nouveau.

    D'ailleurs, l'ancien SIGTRAP semble être similaire à celui là. Visiblement, cela serait du à un free.

    Dans le main, j'appelle ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    t_dictionnary *d=dictionnary_create();
    dictionnary_destroy(d);
    L'erreur se produit lors que d est désalloué.
    Ces fonctions se trouvent dans ici :
    dictionnary.h
    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
     
    #ifndef GENERATOR_H
    #define GENERATOR_H
     
    typedef struct
    {
        t_1Dc *numeric;
        t_1Dc *alpha;
        t_1Dc *ALPHA;
        t_1Dc *Alpha;
        t_1Dc *alpha_numeric;
        t_1Dc *ALPHA_numeric;
        t_1Dc *Alpha_numeric;
        t_1Dc *hexa_numeric;
        t_1Dc *hexa_alpha;
        t_1Dc *hexa;
        t_1Dc *ascii;
        t_1Dc *asciie;
    }t_dictionnary;
     
    t_dictionnary *dictionnary_initialize(t_dictionnary *d);
    t_dictionnary *dictionnary_create();
              void dictionnary_destroy(t_dictionnary *d);
    # endif
    dictionnary.c
    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
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
     
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <errno.h>
     
    #include "create_da.h"
    #include "destroy_da.h"
    #include "logger.h"
    #include "str.h"
    #include "dictionnary.h"
     
    t_dictionnary *dictionnary_create()
    {
        t_dictionnary *d = NULL;
        if ( (d=(t_dictionnary*)malloc(sizeof(t_dictionnary))) )
            d=dictionnary_initialize(d);
     
        else fprintf(logger, "generator.h::dictionnary_create -> %s\n", strerror(errno));
     
        return d;
    }
     
    void dictionnary_destroy(t_dictionnary *d)
    {
        if (d)
        {
            if (d->numeric)
                destroy_1D_c(d->numeric), d->numeric = NULL;
     
            if (d->alpha)
                destroy_1D_c(d->alpha), d->alpha = NULL;
     
            if (d->ALPHA)
                destroy_1D_c(d->ALPHA), d->ALPHA = NULL;
     
            if (d->Alpha)
                destroy_1D_c(d->Alpha), d->Alpha = NULL;
     
            if (d->alpha_numeric)
                destroy_1D_c(d->alpha_numeric), d->alpha_numeric = NULL;
     
            if (d->ALPHA_numeric)
                destroy_1D_c(d->ALPHA_numeric), d->ALPHA_numeric = NULL;
     
            if (d->Alpha_numeric)
                destroy_1D_c(d->Alpha_numeric), d->Alpha_numeric = NULL;
     
            if (d->hexa_alpha)
                destroy_1D_c(d->hexa_alpha), d->hexa_alpha = NULL;
     
            if (d->hexa_numeric)
                destroy_1D_c(d->hexa_numeric), d->hexa_numeric = NULL;
     
            if (d->hexa)
                destroy_1D_c(d->hexa), d->hexa = NULL;
     
            if (d->ascii)
                destroy_1D_c(d->ascii), d->ascii = NULL;
     
            if (d->asciie)
                destroy_1D_c(d->asciie), d->asciie = NULL;
     
            free(d); d=NULL;
        }
        else fprintf(logger, "generator.h::dictionnary_destroy -> %s\n", strerror(errno));
    }
     
    t_dictionnary *dictionnary_initialize(t_dictionnary *d)
    {
        const char *numeric = "0123456789";
        const char *alpha = "abcdefghijklmnopqrstuvwxyz";
        const char *ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        const char *Alpha = str_concat(alpha,ALPHA);
        const char *alpha_numeric = str_concat(alpha,numeric);
        const char *ALPHA_numeric = str_concat(ALPHA,numeric);
        const char *Alpha_numeric = str_concat(Alpha,numeric);
        const char *hexa_alpha = "ABCDEF";
        const char *hexa_numeric = str_copy(numeric);
        const char *hexa = str_concat(hexa_alpha, hexa_numeric);
        const char ascii[128] = {'\0','\1','\2','\3','\4','\5','\6','\7','\10','\11','\12','\13','\14','\15','\16','\17','\20','\21','\22','\23','\24','\25','\26','\27','\30','\31','\32','\33','\34','\35','\36','\37','\40','\41','\42','\43','\44','\45','\46','\47','\50','\51','\52','\53','\54','\55','\56','\57','\60','\61','\62','\63','\64','\65','\66','\67','\70','\71','\72','\73','\74','\75','\76','\77','\100','\101','\102','\103','\104','\105','\106','\107','\110','\111','\112','\113','\114','\115','\116','\117','\120','\121','\122','\123','\124','\125','\126','\127','\130','\131','\132','\133','\134','\135','\136','\137','\140','\141','\142','\143','\144','\145','\146','\147','\150','\151','\152','\153','\154','\155','\156','\157','\160','\161','\162','\163','\164','\165','\166','\167','\170','\171','\172','\173','\174','\175','\176','\177'};
        const char asciie[256] = {'\0','\1','\2','\3','\4','\5','\6','\7','\10','\11','\12','\13','\14','\15','\16','\17','\20','\21','\22','\23','\24','\25','\26','\27','\30','\31','\32','\33','\34','\35','\36','\37','\40','\41','\42','\43','\44','\45','\46','\47','\50','\51','\52','\53','\54','\55','\56','\57','\60','\61','\62','\63','\64','\65','\66','\67','\70','\71','\72','\73','\74','\75','\76','\77','\100','\101','\102','\103','\104','\105','\106','\107','\110','\111','\112','\113','\114','\115','\116','\117','\120','\121','\122','\123','\124','\125','\126','\127','\130','\131','\132','\133','\134','\135','\136','\137','\140','\141','\142','\143','\144','\145','\146','\147','\150','\151','\152','\153','\154','\155','\156','\157','\160','\161','\162','\163','\164','\165','\166','\167','\170','\171','\172','\173','\174','\175','\176','\177','\200','\201','\202','\203','\204','\205','\206','\207','\210','\211','\212','\213','\214','\215','\216','\217','\220','\221','\222','\223','\224','\225','\226','\227','\230','\231','\232','\233','\234','\235','\236','\237','\240','\241','\242','\243','\244','\245','\246','\247','\250','\251','\252','\253','\254','\255','\256','\257','\260','\261','\262','\263','\264','\265','\266','\267','\270','\271','\272','\273','\274','\275','\276','\277','\300','\301','\302','\303','\304','\305','\306','\307','\310','\311','\312','\313','\314','\315','\316','\317','\320','\321','\322','\323','\324','\325','\326','\327','\330','\331','\332','\333','\334','\335','\336','\337','\340','\341','\342','\343','\344','\345','\346','\347','\350','\351','\352','\353','\354','\355','\356','\357','\360','\361','\362','\363','\364','\365','\366','\367','\370','\371','\372','\373','\374','\375','\376','\377'};
        short alloc_state = 0;
        if (d)
        {
            if ( (d->numeric = create_1D_c(str_length(numeric))) )
            {
                if ( (d->alpha = create_1D_c(str_length(alpha))) )
                {
                    if ( (d->ALPHA = create_1D_c(str_length(ALPHA))) )
                    {
                        if ( (d->Alpha = create_1D_c(str_length(Alpha))) )
                        {
                            if ( (d->alpha_numeric = create_1D_c(str_length(alpha_numeric))) )
                            {
                                if ( (d->ALPHA_numeric = create_1D_c(str_length(ALPHA_numeric))) )
                                {
                                   if ( (d->Alpha_numeric = create_1D_c(str_length(Alpha_numeric))) )
                                   {
                                       if ( (d->hexa_alpha = create_1D_c(str_length(hexa_alpha))) )
                                       {
                                           if ( (d->hexa_numeric = create_1D_c(str_length(hexa_numeric))) )
                                           {
                                               if ( (d->hexa = create_1D_c(str_length(hexa))) )
                                               {
                                                   if ( (d->ascii = create_1D_c(128)) )
                                                   {
                                                       if ( (d->asciie = create_1D_c(256)) )
                                                            alloc_state = 1;
     
                                                       if (!alloc_state)
                                                            free(d->ascii), d->ascii = NULL;
                                                   }
                                                   if (!alloc_state)
                                                        free(d->hexa), d->hexa = NULL;
                                                }
                                                if (!alloc_state)
                                                    free(d->hexa_numeric), d->hexa_numeric = NULL;
                                           }
                                           if (!alloc_state)
                                                free(d->hexa_alpha), d->hexa_alpha = NULL;
                                       }
                                       if (!alloc_state)
                                            free(d->Alpha_numeric), d->Alpha_numeric = NULL;
                                   }
                                   if (!alloc_state)
                                        free(d->ALPHA_numeric), d->ALPHA_numeric = NULL;
                                }
                                if (!alloc_state)
                                    free(d->alpha_numeric), d->alpha_numeric = NULL;
                            }
                            if (!alloc_state)
                                free(d->Alpha), d->Alpha = NULL;
                        }
                        if (!alloc_state)
                            free(d->ALPHA), d->ALPHA = NULL;
                    }
                    if (!alloc_state)
                        free(d->alpha), d->alpha = NULL;
                }
                if (!alloc_state)
                    {free(d->numeric); d->numeric = NULL;}
            }
            if (!alloc_state)
                free(d), d=NULL;
        }
        else fprintf(logger, "generator.h::dictionnary_initialize -> %s\n", strerror(errno));
     
        if ( alloc_state )
        {
            strda_replace(d->numeric,numeric);
            strda_replace(d->alpha,alpha);
            strda_replace(d->ALPHA,ALPHA);
            strda_replace(d->Alpha,Alpha);
            strda_replace(d->alpha_numeric,alpha_numeric);
            strda_replace(d->ALPHA_numeric,ALPHA_numeric);
            strda_replace(d->Alpha_numeric,Alpha_numeric);
            strda_replace(d->hexa_numeric,hexa_numeric);
            strda_replace(d->hexa_alpha,hexa_alpha);
            strda_replace(d->hexa,hexa);
            strda_replace_tab(d->ascii,ascii,128);
            strda_replace_tab(d->asciie,asciie,256);
        }
        return d;
    }
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    void destroy_1D_c( t_1Dc *s)
    {
        deallocate_1D_c(s->da); free(s); s=NULL;
    }
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    void deallocate_1D_c( char *p )
    {
        if (p)
            free(p), p=NULL;
     
        else fprintf(logger,"deallocate.h::deallocate_1D_c -> %s\n",strerror(errno));
    }
    L'erreur se produit dès la première désallocation du premier membre de la structure à savoir "numeric".

    Voici le detail de l'erreur :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    Program received signal SIGTRAP, Trace/breakpoint trap.
    In ntdll!DbgUiConnectToDbg () (C:\WINDOWS\system32\ntdll.dll)
    #11 0x00405fe0 in deallocate_1D_c (p=0x3e26c0 "0123456789") at C:\LIBRARY\deallocate.c:52
    Je joints le projet en pièce jointe si besoin est de voir le code dans son intégralité.

    Merci d'avance, je sèche.
    Fichiers attachés Fichiers attachés
    UNE REPONSE UTILE : &|| UN PROBLEME RESOLU :

  9. #9
    Expert éminent
    Avatar de transgohan
    Homme Profil pro
    Développeur Temps réel Embarqué
    Inscrit en
    Janvier 2011
    Messages
    3 146
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Maine et Loire (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur Temps réel Embarqué

    Informations forums :
    Inscription : Janvier 2011
    Messages : 3 146
    Points : 9 386
    Points
    9 386
    Par défaut
    Il faudrait voir comment tu alloues s->da.
    Je n'ai pas la possibilité de télécharger ton archive au boulot.

    « Toujours se souvenir que la majorité des ennuis viennent de l'espace occupé entre la chaise et l'écran de l'ordinateur. »
    « Le watchdog aboie, les tests passent »

  10. #10
    Membre confirmé
    Homme Profil pro
    Etudiant administrateur systèmes et réseaux
    Inscrit en
    Octobre 2007
    Messages
    731
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Etudiant administrateur systèmes et réseaux

    Informations forums :
    Inscription : Octobre 2007
    Messages : 731
    Points : 467
    Points
    467
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    Comme cela !
     
    char *allocate_1D_c( unsigned long long int n )
    {
        unsigned long long int i;
        char *p = NULL;
        if ((p = (char *)malloc(n*sizeof(char))))
            for ( i=0 ; i<n ; i++ )
                p[i]='\0';
     
        else fprintf(logger, "allocate.h::allocate_1D_c -> %s\n", strerror(errno));
     
        return p;
    }
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    t_1Dc *create_1D_c( unsigned long long int x )
    {
        t_1Dc *s = NULL;
        if ( (s = (t_1Dc*)malloc(sizeof(t_1Dc))) )
        {
            if ((s->da = allocate_1D_c(x)))
                s->x = x;
     
            else fprintf(logger, "create_da.h::create_1D_c -> %s\n", strerror(errno));
        }
        else fprintf(logger, "create_da.h::create_1D_c -> %s\n", strerror(errno));
        return s;
    }
    UNE REPONSE UTILE : &|| UN PROBLEME RESOLU :

  11. #11
    Expert éminent
    Avatar de transgohan
    Homme Profil pro
    Développeur Temps réel Embarqué
    Inscrit en
    Janvier 2011
    Messages
    3 146
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Maine et Loire (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur Temps réel Embarqué

    Informations forums :
    Inscription : Janvier 2011
    Messages : 3 146
    Points : 9 386
    Points
    9 386
    Par défaut
    Dans un exemple général cela fonctionne :
    http://ideone.com/v8L86o

    Va donc falloir que tu cherches ce que tu fais entre l'instanciation et la destruction.

    « Toujours se souvenir que la majorité des ennuis viennent de l'espace occupé entre la chaise et l'écran de l'ordinateur. »
    « Le watchdog aboie, les tests passent »

  12. #12
    Membre confirmé
    Homme Profil pro
    Etudiant administrateur systèmes et réseaux
    Inscrit en
    Octobre 2007
    Messages
    731
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Etudiant administrateur systèmes et réseaux

    Informations forums :
    Inscription : Octobre 2007
    Messages : 731
    Points : 467
    Points
    467
    Par défaut
    J'initialise le dictionnaire après l'avoir alloué, c'est la seule opération avant sa destruction.

    Si je mets en commentaire les lignes de codes appelant cette fonction :
    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
    void strda_replace(t_1Dc *s, const char *S)
    {
        if ((s && S))
        {
            unsigned long long int S_length = str_length(S);
            if ( s->x >= S_length )
            {
                s->da[S_length]='\0';
                unsigned long long int i;
                for ( i=0 ; i<S_length ; i++ )
                    s->da[i]=S[i];
            }
            else fprintf(logger, "str.h::strda_replace -> you want to copy \"%s\" which its length is %I64u but destination's max length is %I64u\n", S,S_length,s->x);
        }
        else fprintf(logger, "str.h::strda_replace -> %s", strerror(errno));
    }
    Je n'ai plus de remontée de SIGTRAP. Je suppose donc que l'erreur vient d'ici. Une idée peut être ? J'avoue, je ne vois pas ce qui peut faire que cette fonction va provoquer un SIGTRAP à la desallocation.
    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
     
    t_dictionnary *dictionnary_initialize(t_dictionnary *d)
    {
        const char *numeric = "0123456789";
        const char *alpha = "abcdefghijklmnopqrstuvwxyz";
        const char *ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        const char *Alpha = str_concat(alpha,ALPHA);
        const char *alpha_numeric = str_concat(alpha,numeric);
        const char *ALPHA_numeric = str_concat(ALPHA,numeric);
        const char *Alpha_numeric = str_concat(Alpha,numeric);
        const char *hexa_alpha = "ABCDEF";
        const char *hexa_numeric = str_copy(numeric);
        const char *hexa = str_concat(hexa_alpha, hexa_numeric);
        const char ascii[128] = {'\0','\1','\2','\3','\4','\5','\6','\7','\10','\11','\12','\13','\14','\15','\16','\17','\20','\21','\22','\23','\24','\25','\26','\27','\30','\31','\32','\33','\34','\35','\36','\37','\40','\41','\42','\43','\44','\45','\46','\47','\50','\51','\52','\53','\54','\55','\56','\57','\60','\61','\62','\63','\64','\65','\66','\67','\70','\71','\72','\73','\74','\75','\76','\77','\100','\101','\102','\103','\104','\105','\106','\107','\110','\111','\112','\113','\114','\115','\116','\117','\120','\121','\122','\123','\124','\125','\126','\127','\130','\131','\132','\133','\134','\135','\136','\137','\140','\141','\142','\143','\144','\145','\146','\147','\150','\151','\152','\153','\154','\155','\156','\157','\160','\161','\162','\163','\164','\165','\166','\167','\170','\171','\172','\173','\174','\175','\176','\177'};
        const char asciie[256] = {'\0','\1','\2','\3','\4','\5','\6','\7','\10','\11','\12','\13','\14','\15','\16','\17','\20','\21','\22','\23','\24','\25','\26','\27','\30','\31','\32','\33','\34','\35','\36','\37','\40','\41','\42','\43','\44','\45','\46','\47','\50','\51','\52','\53','\54','\55','\56','\57','\60','\61','\62','\63','\64','\65','\66','\67','\70','\71','\72','\73','\74','\75','\76','\77','\100','\101','\102','\103','\104','\105','\106','\107','\110','\111','\112','\113','\114','\115','\116','\117','\120','\121','\122','\123','\124','\125','\126','\127','\130','\131','\132','\133','\134','\135','\136','\137','\140','\141','\142','\143','\144','\145','\146','\147','\150','\151','\152','\153','\154','\155','\156','\157','\160','\161','\162','\163','\164','\165','\166','\167','\170','\171','\172','\173','\174','\175','\176','\177','\200','\201','\202','\203','\204','\205','\206','\207','\210','\211','\212','\213','\214','\215','\216','\217','\220','\221','\222','\223','\224','\225','\226','\227','\230','\231','\232','\233','\234','\235','\236','\237','\240','\241','\242','\243','\244','\245','\246','\247','\250','\251','\252','\253','\254','\255','\256','\257','\260','\261','\262','\263','\264','\265','\266','\267','\270','\271','\272','\273','\274','\275','\276','\277','\300','\301','\302','\303','\304','\305','\306','\307','\310','\311','\312','\313','\314','\315','\316','\317','\320','\321','\322','\323','\324','\325','\326','\327','\330','\331','\332','\333','\334','\335','\336','\337','\340','\341','\342','\343','\344','\345','\346','\347','\350','\351','\352','\353','\354','\355','\356','\357','\360','\361','\362','\363','\364','\365','\366','\367','\370','\371','\372','\373','\374','\375','\376','\377'};
        short alloc_state = 0;
        if (d)
        {
            if ( (d->numeric = create_1D_c(str_length(numeric))) )
            {
                if ( (d->alpha = create_1D_c(str_length(alpha))) )
                {
                    if ( (d->ALPHA = create_1D_c(str_length(ALPHA))) )
                    {
                        if ( (d->Alpha = create_1D_c(str_length(Alpha))) )
                        {
                            if ( (d->alpha_numeric = create_1D_c(str_length(alpha_numeric))) )
                            {
                                if ( (d->ALPHA_numeric = create_1D_c(str_length(ALPHA_numeric))) )
                                {
                                   if ( (d->Alpha_numeric = create_1D_c(str_length(Alpha_numeric))) )
                                   {
                                       if ( (d->hexa_alpha = create_1D_c(str_length(hexa_alpha))) )
                                       {
                                           if ( (d->hexa_numeric = create_1D_c(str_length(hexa_numeric))) )
                                           {
                                               if ( (d->hexa = create_1D_c(str_length(hexa))) )
                                               {
                                                   if ( (d->ascii = create_1D_c(128)) )
                                                   {
                                                       if ( (d->asciie = create_1D_c(256)) )
                                                            alloc_state = 1;
     
                                                       if (!alloc_state)
                                                            free(d->ascii), d->ascii = NULL;
                                                   }
                                                   if (!alloc_state)
                                                        free(d->hexa), d->hexa = NULL;
                                                }
                                                if (!alloc_state)
                                                    free(d->hexa_numeric), d->hexa_numeric = NULL;
                                           }
                                           if (!alloc_state)
                                                free(d->hexa_alpha), d->hexa_alpha = NULL;
                                       }
                                       if (!alloc_state)
                                            free(d->Alpha_numeric), d->Alpha_numeric = NULL;
                                   }
                                   if (!alloc_state)
                                        free(d->ALPHA_numeric), d->ALPHA_numeric = NULL;
                                }
                                if (!alloc_state)
                                    free(d->alpha_numeric), d->alpha_numeric = NULL;
                            }
                            if (!alloc_state)
                                free(d->Alpha), d->Alpha = NULL;
                        }
                        if (!alloc_state)
                            free(d->ALPHA), d->ALPHA = NULL;
                    }
                    if (!alloc_state)
                        free(d->alpha), d->alpha = NULL;
                }
                if (!alloc_state)
                    {free(d->numeric); d->numeric = NULL;}
            }
            if (!alloc_state)
                free(d), d=NULL;
        }
        else fprintf(logger, "generator.h::dictionnary_initialize -> %s\n", strerror(errno));
     
        if ( alloc_state )
        {
            strda_replace(d->numeric,numeric);
            strda_replace(d->alpha,alpha);
            strda_replace(d->ALPHA,ALPHA);
            strda_replace(d->Alpha,Alpha);
            strda_replace(d->alpha_numeric,alpha_numeric);
            strda_replace(d->ALPHA_numeric,ALPHA_numeric);
            strda_replace(d->Alpha_numeric,Alpha_numeric);
            strda_replace(d->hexa_numeric,hexa_numeric);
            strda_replace(d->hexa_alpha,hexa_alpha);
            strda_replace(d->hexa,hexa);
            strda_replace_tab(d->ascii,ascii,128);
            strda_replace_tab(d->asciie,asciie,256);
        }
        return d;
    }
    UNE REPONSE UTILE : &|| UN PROBLEME RESOLU :

  13. #13
    Expert éminent
    Avatar de transgohan
    Homme Profil pro
    Développeur Temps réel Embarqué
    Inscrit en
    Janvier 2011
    Messages
    3 146
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Maine et Loire (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur Temps réel Embarqué

    Informations forums :
    Inscription : Janvier 2011
    Messages : 3 146
    Points : 9 386
    Points
    9 386
    Par défaut
    Faudrait regarder alors ce que fait ta fonction strda_replace().

    « Toujours se souvenir que la majorité des ennuis viennent de l'espace occupé entre la chaise et l'écran de l'ordinateur. »
    « Le watchdog aboie, les tests passent »

  14. #14
    Membre confirmé
    Homme Profil pro
    Etudiant administrateur systèmes et réseaux
    Inscrit en
    Octobre 2007
    Messages
    731
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Etudiant administrateur systèmes et réseaux

    Informations forums :
    Inscription : Octobre 2007
    Messages : 731
    Points : 467
    Points
    467
    Par défaut
    C'est ce que j'étais en train de me dire
    UNE REPONSE UTILE : &|| UN PROBLEME RESOLU :

  15. #15
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 369
    Points : 41 518
    Points
    41 518
    Par défaut
    Code C : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
        const char *Alpha = str_concat(alpha,ALPHA);
        const char *alpha_numeric = str_concat(alpha,numeric);
        const char *ALPHA_numeric = str_concat(ALPHA,numeric);
        const char *Alpha_numeric = str_concat(Alpha,numeric);
    Ça sent le soufre, ça: str_concat m'a l'air d'une fonction qui retourne une chaîne allouée dynamiquement, mais elle est placée dans un pointeur const, ce qui laisse supposer que soit elle n'est jamais libérée, soit un cast est utilisé lors de sa libération...

    Aussi, fais gaffe aux histoires de longueur: La valeur retournée par str_length comprend-elle le '\0' terminal? Si elle se comporte comme strlen, alors la réponse est non...
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

  16. #16
    Membre confirmé
    Homme Profil pro
    Etudiant administrateur systèmes et réseaux
    Inscrit en
    Octobre 2007
    Messages
    731
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Etudiant administrateur systèmes et réseaux

    Informations forums :
    Inscription : Octobre 2007
    Messages : 731
    Points : 467
    Points
    467
    Par défaut
    Je suis un couillon.
    Je viens de me rendre compte que j'ai oublié de compter le +1 de '\0'.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    d->numeric = create_1D_c(str_length(numeric)+1)
    Pour S="0123456789",
    s->x = 10 au lieu de 11

    Dans strda_replace le test :
    ...passait car il manquait aussi le +1 à S_length.

    Par conséquent, dans strda_replace
    ... aurait du provoquer un SIGSEV ?
    s->x = 10 => 0..9
    S_length=10 => s->da[10] =

    Pourquoi SIGTRAP lors du free ?
    UNE REPONSE UTILE : &|| UN PROBLEME RESOLU :

  17. #17
    Membre confirmé
    Homme Profil pro
    Etudiant administrateur systèmes et réseaux
    Inscrit en
    Octobre 2007
    Messages
    731
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Etudiant administrateur systèmes et réseaux

    Informations forums :
    Inscription : Octobre 2007
    Messages : 731
    Points : 467
    Points
    467
    Par défaut
    Citation Envoyé par Médinoc Voir le message
    Code C : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
        const char *Alpha = str_concat(alpha,ALPHA);
        const char *alpha_numeric = str_concat(alpha,numeric);
        const char *ALPHA_numeric = str_concat(ALPHA,numeric);
        const char *Alpha_numeric = str_concat(Alpha,numeric);
    Ça sent le soufre, ça: str_concat m'a l'air d'une fonction qui retourne une chaîne allouée dynamiquement, mais elle est placée dans un pointeur const, ce qui laisse supposer que soit elle n'est jamais libérée, soit un cast est utilisé lors de sa libération...

    Aussi, fais gaffe aux histoires de longueur: La valeur retournée par str_length comprend-elle le '\0' terminal? Si elle se comporte comme strlen, alors la réponse est non...
    Ah bah on est d'accord sur l'histoire du '\0'.
    Par contre le const char, je ne me souviens plus ce que j'avais écris. Parfois je fais des copiés collés pour aller plus vite et j'oublie d'enlever deux trois trucks. D'expérience je devrais savoir que ca m'en fait toujours perdre plus que ca ne m'en fait gagner.
    Dans tous les cas, ces variables là, je les déclare mais nul part je les désalloue.

    Alors en effet, il devait y avoir une tentative de désallocation d'un const char quelque part à moment donnée.
    UNE REPONSE UTILE : &|| UN PROBLEME RESOLU :

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. CullFace (Front / Back Face)
    Par Finch dans le forum OpenGL
    Réponses: 5
    Dernier message: 27/04/2005, 15h16
  2. Back Office
    Par Ric500 dans le forum Access
    Réponses: 12
    Dernier message: 02/12/2004, 15h25
  3. Script pour back up database
    Par jeff37 dans le forum MS SQL Server
    Réponses: 2
    Dernier message: 06/09/2004, 15h57
  4. [Debutant]Back up et restore
    Par christophebmx dans le forum Administration
    Réponses: 2
    Dernier message: 22/05/2004, 15h53

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo