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

Linux Discussion :

erreur de mémoire


Sujet :

Linux

  1. #1
    Membre régulier
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mars 2003
    Messages
    132
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val d'Oise (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2003
    Messages : 132
    Points : 89
    Points
    89
    Par défaut erreur de mémoire
    Bonjour, j'ai un plantage au niveau je pense d'un dépassement de mémoire ou un pointeur mal initialisé.
    Voici le code, je trouve pas le bug:

    Code c : 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
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
     
    /* Hash.C */
     
    #include <stdlib.h>
     
    #include "hash.h"
    #include "types.h"
    #include "mboard.h"
     
    /* Macros */
     
    #define BCH(N)          (BchTable[(uint8)(N)])
    #define CODE(A,B,C,D,N) ((((((BCH((A)*(N))<<8)|BCH((B)*(N)))<<8)|BCH((C)*(N)))<<8)|BCH((D)*(N)))
     
    /* Types */
     
    typedef struct {
       uint32 Lock;
       info   Info;
    } entry;
     
    /* Variables */
     
    int HashDate, HashScheme;
     
    int ReadHashTotal, ReadHashTrue;
    int WriteHashTotal, WriteHashTrue;
     
    uint64 HashKeyTable[SQUARE_NB][PIECE_NB];
     
    int HashAge[4];
     
    static int    HashBitNb, DateBitNb, DateSize, ClusterSize;
    static uint32 HashSize;
    static entry *HashTable;
     
    static uint8  BchTable[256];
    static uint8  BchSeed;
     
    /* Prototypes */
     
    static void   SetDate    (int Date);
    static int    EntryAge   (int Date);
     
    static void   InitRandom (void);
    static uint64 Rand64     (void);
     
    /* Functions */
     
    /* InitHash() */
     
    void InitHash(void) {
     
       int S, P;
     
       HashBitNb = 20;
       HashSize  = 1 << HashBitNb;
     
       ClusterSize = 4;
     
       HashTable = malloc((HashSize+ClusterSize-1)*sizeof(entry));
       assert(HashTable!=NULL);
     
       DateBitNb = 2;
       DateSize  = 1 << DateBitNb;
     
       SetDate(0);
       ClearHashTable();
     
       InitRandom();
     
       for (S = 0; S <= 50; S++) { /* 0 maps to 0 (side to move) */
          for (P = 0; P < PIECE_NB; P++) {
             HashKeyTable[Std2Sq[S]][P] = Rand64();
          }
       }
    }
     
    /* ClearHashTable() */
     
    void ClearHashTable(void) {
     
       int I,N;
       entry *Entry;
       for (I = 0; I < HashSize+ClusterSize-1; I++) {
          Entry = &HashTable[I];
          Entry->Lock = 0x00000000;
          ClearInfo(&Entry->Info);
       }
    }
     
    /* ClearInfo() */
     
    void ClearInfo(info *Info) {
     
       Info->Date  = HashDate;
       Info->Depth = 0;
       Info->Min   = FALSE;
       Info->Max   = FALSE;
       Info->Value = 0;
       Info->Start = 0;
       Info->End   = 0;
    }
     
    /* UpdateHash() */
     
    void UpdateHash(void) {
     
       SetDate((HashDate+1)%DateSize);
    }
     
    /* SetDate() */
     
    static void SetDate(int Date) {
     
       int D;
     
       assert(Date>=0&&Date<DateSize);
     
       HashDate = Date;
     
       for (D = 0; D < DateSize; D++) HashAge[D] = EntryAge(D);
    }
     
    /* EntryAge() */
     
    static int EntryAge(int Date) {
     
       int Age;
     
       assert(Date>=0&&Date<DateSize);
     
       Age = HashDate - Date;
       if (Age < 0) Age += DateSize;
     
       return Age;
    }
     
    /* ReadHash() */
     
    info *ReadHash(uint64 Key, int Depth) {
     
       uint32 Key0, Key1;
       entry *Entry, *End;
       info *Info;
     
       ReadHashTotal++;
     
       Key0 = Key >> 32;
       Key1 = (uint32) Key;
     
       Entry = &HashTable[Key0];
       End   = Entry + ClusterSize;
     
       do {
          if (Entry->Lock == Key1) {
             ReadHashTrue++;
             Info = &Entry->Info;
             Info->Date = HashDate;
             return Info;
          }
       } while (++Entry < End);
     
       return NULL;
    }
     
    /* WriteHash() */
     
    info *WriteHash(uint64 Key, int Depth) {
     
       int Diff, Age, BestAge, BestDepth;
       uint32 Key0, Key1;
       entry *Entry, *End, *Best;
       info *Info;
     
       WriteHashTotal++;
     
       Key0 = Key >> 32;
       Key1 = (uint32) Key;
     
       Entry = &HashTable[Key0];
       End   = Entry + ClusterSize;
     
       BestAge = -1;
     
       do {
     
          if (Entry->Lock == Key1) {
             Info = &Entry->Info;
             Info->Date = HashDate;
             if (Info->Depth <= Depth) {
                WriteHashTrue++;
                return Info;
             }
             return NULL;
          }
     
          Age  = HashAge[Entry->Info.Date];
          Diff = BestAge - Age;
          if (Diff < 0 || (Diff == 0 && BestDepth > Entry->Info.Depth)) {
             Best      = Entry;
             BestAge   = Age;
             BestDepth = Best->Info.Depth;
          }
     
       } while (++Entry < End);
     
       WriteHashTrue++;
     
       Best->Lock = Key1;
       Info = &Best->Info;
       ClearInfo(Info);
     
       return Info;
    }
     
    /* HashKey() */
     
    uint64 HashKey(const mboard *Board) {
     
       int S, P;
       uint64 Key;
     
       Key = 0ULL;
     
       S = 0; /* Turn */
       P = (Board->Colour == WHITE) ? WHITE_MAN : BLACK_MAN;
       Key ^= HashKeyTable[S][P];
     
       for (S = S1; S <= S50; S++) {
          P = HashPiece(&Board->Square[S]);
          if (P != NO_PIECE) Key ^= HashKeyTable[S][P];
       }
     
       return Key;
    }
     
    /* HashPiece() */
     
    int HashPiece(const msquare *Square) {
     
       int P;
     
       P = NO_PIECE;
     
       switch (Square->Colour) {
       case WHITE :
          P = (! Square->IsKing) ? WHITE_MAN : WHITE_KING;
          break;
       case BLACK :
          P = (! Square->IsKing) ? BLACK_MAN : BLACK_KING;
          break;
       }
     
       return P;
    }
     
    /* InitRandom() */
     
    static void InitRandom(void) {
     
       int I, N;
     
       for (I = 0, N = 0x01; I < 256; I++) {
          BchTable[I] = N;
          if ((N += N) >= 0x100) N ^= 0x171;
       }
       BchTable[255] = 0; /* So that every value is used only once */
     
       BchSeed = 0;
    }
     
    /* Random64() */
     
    static uint64 Rand64(void) {
     
       uint32 Key, Lock;
     
       BchSeed++; /* To avoid the 0 value */
     
       Key  = CODE(7,5,3,1,BchSeed) & (HashSize - 1);
       Lock = CODE(15,13,11,9,BchSeed);
     
       return (((uint64) Key) << 32) | (uint64) Lock;
    }
     
    /* End of Hash.C */

    voilà ce que j'obtiens avec gdb:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    Program received signal SIGSEGV, Segmentation fault.
    [Switching to Thread -1218808128 (LWP 12367)]
    0x0805bdd1 in ?? ()
    (gdb) bt
    #0  0x0805bdd1 in ?? ()
    Cannot access memory at address 0xbf2ebff8
    Merci d'avance pour votre aide

  2. #2
    Membre régulier
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mars 2003
    Messages
    132
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val d'Oise (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2003
    Messages : 132
    Points : 89
    Points
    89
    Par défaut
    Voilà ce que j'ai sur valgrind:

    ==12424==
    ==12424== Invalid read of size 4
    ==12424== at 0x805FF22: (within /home/eddy/vd/bin/vd)
    ==12424== Address 0x825B498 is not stack'd, malloc'd or (recently) free'd
    ==12424==
    ==12424== Process terminating with default action of signal 11 (SIGSEGV)
    ==12424== Access not within mapped region at address 0x825B498
    ==12424== at 0x805FF22: (within /home/eddy/vd/bin/vd)
    ==12424==
    ==12424== ERROR SUMMARY: 14 errors from 12 contexts (suppressed: 83 from 1)
    ==12424== malloc/free: in use at exit: 8,620,485 bytes in 2,786 blocks.
    ==12424== malloc/free: 8,600 allocs, 5,814 frees, 9,252,661 bytes allocated.
    ==12424== For counts of detected errors, rerun with: -v
    ==12424== searching for pointers to 2,786 not-freed blocks.
    ==12424== checked 10,945,560 bytes.
    ==12424==
    ==12424==
    ==12424== 156 (36 direct, 120 indirect) bytes in 1 blocks are definitely lost in loss record 36 of 100
    ==12424== at 0x4021620: malloc (vg_replace_malloc.c:149)
    ==12424== by 0x482C687: (within /lib/tls/i686/cmov/libc-2.5.so)
    ==12424== by 0x482CED5: __nss_database_lookup (in /lib/tls/i686/cmov/libc-2.5.so)
    ==12424== by 0x4BD3EEB: ???
    ==12424== by 0x4BD5422: ???
    ==12424== by 0x47DAC92: getpwnam_r (in /lib/tls/i686/cmov/libc-2.5.so)
    ==12424== by 0x470CA65: (within /usr/lib/libglib-2.0.so.0.1200.11)
    ==12424== by 0x470DED8: g_get_home_dir (in /usr/lib/libglib-2.0.so.0.1200.11)
    ==12424== by 0x41E43A4: (within /usr/lib/libgtk-x11-2.0.so.0.1000.11)
    ==12424== by 0x41E783A: _gtk_rc_init (in /usr/lib/libgtk-x11-2.0.so.0.1000.11)
    ==12424== by 0x419A901: (within /usr/lib/libgtk-x11-2.0.so.0.1000.11)
    ==12424== by 0x46F1FA9: g_option_context_parse (in /usr/lib/libglib-2.0.so.0.1200.11)
    ==12424==
    ==12424==
    ==12424== 800 bytes in 20 blocks are possibly lost in loss record 76 of 100
    ==12424== at 0x402095F: calloc (vg_replace_malloc.c:279)
    ==12424== by 0x46EC22D: g_malloc0 (in /usr/lib/libglib-2.0.so.0.1200.11)
    ==12424== by 0x46978CF: (within /usr/lib/libgobject-2.0.so.0.1200.11)
    ==12424== by 0x4697A64: (within /usr/lib/libgobject-2.0.so.0.1200.11)
    ==12424== by 0x469C37C: g_type_register_fundamental (in /usr/lib/libgobject-2.0.so.0.1200.11)
    ==12424== by 0x46A635B: (within /usr/lib/libgobject-2.0.so.0.1200.11)
    ==12424== by 0x46980B0: g_type_init_with_debug_flags (in /usr/lib/libgobject-2.0.so.0.1200.11)
    ==12424== by 0x46981B1: g_type_init (in /usr/lib/libgobject-2.0.so.0.1200.11)
    ==12424== by 0x43CAE55: gdk_pre_parse_libgtk_only (in /usr/lib/libgdk-x11-2.0.so.0.1000.11)
    ==12424== by 0x419A9F4: (within /usr/lib/libgtk-x11-2.0.so.0.1000.11)
    ==12424== by 0x46F1E2C: g_option_context_parse (in /usr/lib/libglib-2.0.so.0.1200.11)
    ==12424== by 0x419A58B: gtk_parse_args (in /usr/lib/libgtk-x11-2.0.so.0.1000.11)
    ==12424==
    ==12424==
    ==12424== 57,304 bytes in 37 blocks are possibly lost in loss record 99 of 100
    ==12424== at 0x4020820: memalign (vg_replace_malloc.c:332)
    ==12424== by 0x402087A: posix_memalign (vg_replace_malloc.c:421)
    ==12424== by 0x46FB693: (within /usr/lib/libglib-2.0.so.0.1200.11)
    ==12424== by 0x46FC0C3: g_slice_alloc (in /usr/lib/libglib-2.0.so.0.1200.11)
    ==12424== by 0x46FC214: g_slice_alloc0 (in /usr/lib/libglib-2.0.so.0.1200.11)
    ==12424== by 0x469F336: g_type_create_instance (in /usr/lib/libgobject-2.0.so.0.1200.11)
    ==12424== by 0x4686801: (within /usr/lib/libgobject-2.0.so.0.1200.11)
    ==12424== by 0x4684A7A: g_object_newv (in /usr/lib/libgobject-2.0.so.0.1200.11)
    ==12424== by 0x46855EE: g_object_new_valist (in /usr/lib/libgobject-2.0.so.0.1200.11)
    ==12424== by 0x468579F: g_object_new (in /usr/lib/libgobject-2.0.so.0.1200.11)
    ==12424== by 0x43ED237: gdk_display_open (in /usr/lib/libgdk-x11-2.0.so.0.1000.11)
    ==12424== by 0x43CACFE: gdk_display_open_default_libgtk_only (in /usr/lib/libgdk-x11-2.0.so.0.1000.11)
    ==12424==
    ==12424== LEAK SUMMARY:
    ==12424== definitely lost: 36 bytes in 1 blocks.
    ==12424== indirectly lost: 120 bytes in 10 blocks.
    ==12424== possibly lost: 58,104 bytes in 57 blocks.
    ==12424== still reachable: 8,562,225 bytes in 2,718 blocks.
    ==12424== suppressed: 0 bytes in 0 blocks.
    ==12424== Reachable blocks (those to which a pointer was found) are not shown.
    ==12424== To see them, rerun with: --show-reachable=yes
    Erreur de segmentation (core dumped)

  3. #3
    Membre régulier
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mars 2003
    Messages
    132
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val d'Oise (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2003
    Messages : 132
    Points : 89
    Points
    89
    Par défaut
    Apparement Key prends une valeur s'apparentant à du n'importe quoi aprés
    3 passages dans la fct ReadHash(uint64 Key, int Depth).
    Exemple de valeur :

    Je reflechis...

    Key : 1270191012174645

    Key0 : 295739

    Key : 1270190142551263

    Key0 : 295739

    Key : 18442701340885007448

    Key0 : 4294026023

    Segmentation fault (core dumped)

  4. #4
    Membre régulier
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mars 2003
    Messages
    132
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val d'Oise (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2003
    Messages : 132
    Points : 89
    Points
    89
    Par défaut
    voici l'adresse du site si quelqu'un souhaite m'aider :

    http://perso.orange.fr/eddy.balavoin...GHTS/index.htm

    merci d'avance

  5. #5
    Modérateur
    Avatar de gangsoleil
    Homme Profil pro
    Manager / Cyber Sécurité
    Inscrit en
    Mai 2004
    Messages
    10 149
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Manager / Cyber Sécurité

    Informations forums :
    Inscription : Mai 2004
    Messages : 10 149
    Points : 28 116
    Points
    28 116
    Par défaut
    Bonjour,

    Il manque les fichiers .h pour pouvoir compiler ton programme, donc il est difficile de t'aider.
    Par ailleurs, la page que tu as envoyée n'est pas accessible ;-)
    "La route est longue, mais le chemin est libre" -- https://framasoft.org/
    Les règles du forum

  6. #6
    Membre régulier
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mars 2003
    Messages
    132
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val d'Oise (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2003
    Messages : 132
    Points : 89
    Points
    89
    Par défaut
    j'ai modifié le lien ci-dessus

  7. #7
    Membre régulier
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mars 2003
    Messages
    132
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val d'Oise (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2003
    Messages : 132
    Points : 89
    Points
    89
    Par défaut
    voici le code mis à jour, j'ai pas trouvé le bug:

    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
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
     
     
    /* Hash.C */
     
    #include <stdlib.h>
     
    #include "hash.h"
    #include "types.h"
    #include "mboard.h"
     
    /* Macros */
     
    #define BCH(N)          (BchTable[(guint8)(N)])
    #define CODE(A,B,C,D,N) ((((((BCH((A)*(N))<<8)|BCH((B)*(N)))<<8)|BCH((C)*(N)))<<8)|BCH((D)*(N)))
     
    /* Types */
     
    typedef struct {
       guint32 Lock;
       info   Info;
    } entry;
     
    /* Variables */
     
    gint HashDate, HashScheme;
     
    gint ReadHashTotal, ReadHashTrue;
    gint WriteHashTotal, WriteHashTrue;
     
    guint64 HashKeyTable[SQUARE_NB][PIECE_NB];
     
    gint HashAge[4];
     
    static gint    HashBitNb, DateBitNb, DateSize, ClusterSize;
    static guint32 HashSize;
    static entry *HashTable;
     
    static guint8  BchTable[256];
    static guint8  BchSeed;
     
    /* Prototypes */
     
    static void   SetDate    (gint Date);
    static gint    EntryAge   (gint Date);
     
    static void   InitRandom (void);
    static guint64 Rand64     (void);
     
    /* Functions */
     
    /* InitHash() */
     
    void InitHash(void) {
     
       gint S, P;
     
       HashBitNb = 20;
       HashSize  = 1 << HashBitNb;
     
       ClusterSize = 4;
     
       HashTable = malloc((HashSize+ClusterSize-1)*sizeof(entry));
       assert(HashTable!=NULL);
     
       DateBitNb = 2;
       DateSize  = 1 << DateBitNb;
     
       SetDate(0);
       ClearHashTable();
     
       InitRandom();
     
       for (S = 0; S <= 50; S++) { /* 0 maps to 0 (side to move) */
          for (P = 0; P < PIECE_NB; P++) {
             HashKeyTable[Std2Sq[S]][P] = Rand64();
          }
       }
    }
     
    /* ClearHashTable() */
     
    void ClearHashTable(void) {
     
       gint I;
       entry *Entry;
     
       for (I = 0; I < HashSize+ClusterSize-1; I++) {
          Entry = &HashTable[I];
          Entry->Lock = 0x00000000;
          ClearInfo(&Entry->Info);
       }
    }
     
    /* ClearInfo() */
     
    void ClearInfo(info *Info) {
     
       Info->Date  = HashDate;
       Info->Depth = 0;
       Info->Min   = FALSE;
       Info->Max   = FALSE;
       Info->Value = 0;
       Info->Start = 0;
       Info->End   = 0;
    }
     
    /* UpdateHash() */
     
    void UpdateHash(void) {
     
       SetDate((HashDate+1)%DateSize);
    }
     
    /* SetDate() */
     
    static void SetDate(gint Date) {
     
       gint D;
     
       assert(Date>=0&&Date<DateSize);
     
       HashDate = Date;
     
       for (D = 0; D < DateSize; D++) HashAge[D] = EntryAge(D);
    }
     
    /* EntryAge() */
     
    static gint EntryAge(gint Date) {
     
       gint Age;
     
       assert(Date>=0&&Date<DateSize);
     
       Age = HashDate - Date;
       if (Age < 0) Age += DateSize;
     
       return Age;
    }
     
    /* ReadHash() */
     
    info *ReadHash(guint64 Key, gint Depth) {
     
       guint32 Key0, Key1;
       entry *Entry, *End;
       info *Info;
     
       ReadHashTotal++;
     
       Key0 = Key >> 32;
       Key1 = (uint32) Key;
     
       Entry = &HashTable[Key0];
       End   = Entry + ClusterSize;
     
       do {
          if (Entry->Lock == Key1) {
             ReadHashTrue++;
             Info = &Entry->Info;
             Info->Date = HashDate;
             return Info;
          }
       } while (++Entry < End);
     
       return NULL;
    }
     
    /* WriteHash() */
     
    info *WriteHash(guint64 Key, gint Depth) {
     
       gint Diff, Age, BestAge, BestDepth;
       guint32 Key0, Key1;
       entry *Entry, *End, *Best;
       info *Info;
     
       WriteHashTotal++;
     
       Key0 = Key >> 32;
       Key1 = (guint32) Key;
     
       Entry = &HashTable[Key0];
       End   = Entry + ClusterSize;
     
       BestAge = -1;
     
       do {
     
          if (Entry->Lock == Key1) {
             Info = &Entry->Info;
             Info->Date = HashDate;
             if (Info->Depth <= Depth) {
                WriteHashTrue++;
                return Info;
             }
             return NULL;
          }
     
          Age  = HashAge[Entry->Info.Date];
          Diff = BestAge - Age;
          if (Diff < 0 || (Diff == 0 && BestDepth > Entry->Info.Depth)) {
             Best      = Entry;
             BestAge   = Age;
             BestDepth = Best->Info.Depth;
          }
     
       } while (++Entry < End);
     
       WriteHashTrue++;
     
       Best->Lock = Key1;
       Info = &Best->Info;
       ClearInfo(Info);
     
       return Info;
    }
     
    /* HashKey() */
     
    guint64 HashKey(const mboard *Board) {
     
       gint S, P;
       guint64 Key;
     
       Key = 0ULL;
     
       S = 0; /* Turn */
       P = (Board->Colour == WHITE) ? WHITE_MAN : BLACK_MAN;
       Key ^= HashKeyTable[S][P];
     
       for (S = S1; S <= S50; S++) {
          P = HashPiece(&Board->Square[S]);
          if (P != NO_PIECE) Key ^= HashKeyTable[S][P];
       }
     
       return Key;
    }
     
    /* HashPiece() */
     
    gint HashPiece(const msquare *Square) {
     
       gint P;
     
       P = NO_PIECE;
     
       switch (Square->Colour) {
       case WHITE :
          P = (! Square->IsKing) ? WHITE_MAN : WHITE_KING;
          break;
       case BLACK :
          P = (! Square->IsKing) ? BLACK_MAN : BLACK_KING;
          break;
       }
     
       return P;
    }
     
    /* InitRandom() */
     
    static void InitRandom(void) {
     
       gint I, N;
     
       for (I = 0, N = 0x01; I < 256; I++) {
          BchTable[I] = N;
          if ((N += N) >= 0x100) N ^= 0x171;
       }
       BchTable[255] = 0; /* So that every value is used only once */
     
       BchSeed = 0;
    }
     
    /* Random64() */
     
    static guint64 Rand64(void) {
     
       guint32 Key, Lock;
     
       BchSeed++; /* To avoid the 0 value */
     
       Key  = CODE(7,5,3,1,BchSeed) & (HashSize - 1);
       Lock = CODE(15,13,11,9,BchSeed);
     
       return (((guint64) Key) << 32) | (guint64) Lock;
    }
     
    /* End of Hash.C */
    et le fichier 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
    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
     
     
    /* Hash.H */
     
    #ifndef HASH_H
    #define HASH_H
     
    #include "types.h"
    #include "mboard.h"
     
    /* Constants */
     
    enum { NEW, DEEP }; /* Hash entry replacement scheme */
     
    /* Types */
     
    typedef struct {
       guint Date  : 2; /* Affects HashAge[] size */
       guint Depth : 5;
       guint Min   : 1;
       guint Max   : 1;
       gint Value : 11;
       guint Start : 6;
       guint End   : 6;
    } info;
     
    /* Variables */
     
    extern gint    HashDate, HashScheme;
     
    extern gint    ReadHashTotal, ReadHashTrue;
    extern gint    WriteHashTotal, WriteHashTrue;
     
    extern guint64 HashKeyTable[SQUARE_NB][PIECE_NB];
     
    extern int    HashAge[4];
     
    /* Prototypes */
     
    extern void    InitHash       (void);
     
    extern void    ClearHashTable (void);
    extern void    ClearInfo      (info *Info);
    extern void    UpdateHash     (void);
     
    extern info   *ReadHash       (guint64 Key, gint Depth);
    extern info   *WriteHash      (guint64 Key, gint Depth);
     
    extern guint64  HashKey        (const mboard *Board);
    extern gint     HashPiece      (const msquare *Square);
     
    #endif /* ! defined HASH_H */
     
    /* End of Hash.H */

  8. #8
    Expert éminent sénior

    Avatar de fearyourself
    Homme Profil pro
    Ingénieur Informaticien Senior
    Inscrit en
    Décembre 2005
    Messages
    5 121
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : Ingénieur Informaticien Senior
    Secteur : Industrie

    Informations forums :
    Inscription : Décembre 2005
    Messages : 5 121
    Points : 11 877
    Points
    11 877
    Par défaut
    Est-ce qu'on pourrait avoir la fonction main qui pilote ton application et qui provoque l'erreur ?

    Jc

  9. #9
    Membre régulier
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mars 2003
    Messages
    132
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val d'Oise (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2003
    Messages : 132
    Points : 89
    Points
    89
    Par défaut
    Bonjour,

    J'ai trouvé le bug dans mon code.

    Merci de m'avoir orienté

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

Discussions similaires

  1. [PR-2007] Demarrage Project 2007 : "erreur de mémoire"
    Par Invité dans le forum Project
    Réponses: 15
    Dernier message: 28/05/2009, 08h16
  2. Réponses: 2
    Dernier message: 12/03/2008, 13h37
  3. [Upload] Erreur de mémoire lors d'un upload
    Par alpking dans le forum Langage
    Réponses: 3
    Dernier message: 10/11/2006, 10h35
  4. Erreur Allocation mémoire
    Par Thordax dans le forum C++
    Réponses: 10
    Dernier message: 05/04/2006, 21h29
  5. Programme détectant les erreurs de mémoire
    Par gids01 dans le forum MFC
    Réponses: 2
    Dernier message: 07/12/2005, 10h57

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