Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1474 connectés 

  FORUM HardWare.fr
  Programmation
  C++

  Etrange étrange

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Etrange étrange

n°1405463
fabllot
Posté le 12-07-2006 à 12:26:37  profilanswer
 

Voici une petite erreur que je viens d'avoir, et dont je voudrais avoir vos avis...
 
Affichage gdb :  


Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x09b608d6
0x022a0134 in Gecode::MiniModel::LinExpr::post (this=0xbfffe41c, home=0x397a0a0, icl=ICL_DEF) at gecode/minimodel/lin-expr.cc:81
81                min += ts[i].a*ts[i].x.min();
(gdb) print i
$3 = 3
(gdb) print n
$4 = 2


 
Code source du fichier lin-expr.cc

Code :
  1. 00073     IntVar
  2. 00074     LinExpr::post(Space* home, IntConLevel icl) const {
  3. 00075       GECODE_AUTOARRAY(Int::Linear::Term, ts, n+1);
  4. 00076       (void) ax->fill(ts,0,sign);
  5. 00077       double min = sign*-c;
  6. 00078       double max = sign*-c;
  7. 00079       for (int i=n; i--; )
  8. 00080         if (ts[i].a > 0) {
  9. 00081           min += ts[i].a*ts[i].x.min();
  10. 00082           max += ts[i].a*ts[i].x.max();
  11. 00083         } else {
  12. 00084           max += ts[i].a*ts[i].x.min();
  13. 00085           min += ts[i].a*ts[i].x.max();
  14. 00086         }
  15. 00087       if (min < Limits::Int::int_min)
  16. 00088         min = Limits::Int::int_min;
  17. 00089       if (max > Limits::Int::int_max)
  18. 00090         max = Limits::Int::int_max;
  19. 00091       IntVar x(home, static_cast<int>(min), static_cast<int>(max));
  20. 00092       ts[n].x = x;
  21. 00093       ts[n].a = -1;
  22. 00094       Int::Linear::post(home, ts, n+1, IRT_EQ, sign*-c, icl);
  23. 00095       return x;
  24. 00096     }


 
Petites explications :
Le code source émane d'une librairie C++ (Gecode)
Le code source mis ci-dessus est bien celui du bon fichier (etc )
 
Ce qui est étrange c'est qu'au sein de la boucle "for" (lignes 79 à 86), la variable "i" n'est jamais incrémentée, pourtant gdb indique que sa valeur (=3) est supérieure à sa valeur d'initialisation (=2)...
 
Y comprenez vous quelque chose ?

mood
Publicité
Posté le 12-07-2006 à 12:26:37  profilanswer
 

n°1405479
skelter
Posté le 12-07-2006 à 12:42:27  profilanswer
 

pour t'assurer de l'intégrité de i, dans la boucle
const int c_i = i;
et utilise c_i a la place de i

n°1405480
fabllot
Posté le 12-07-2006 à 12:45:56  profilanswer
 

Le soucis est que le code provient d'une bibliothèque, et je n'ai pas très envie de la modifier ...

n°1405489
fabllot
Posté le 12-07-2006 à 12:56:56  profilanswer
 

Bon finalement je l'ai fait ...
Revoici donc le code source (juste la boucle for)

Code :
  1. 79 for (int i=n; i--; ) {
  2. 80  const int c_i = i;
  3. 81  if (ts[c_i].a > 0) {
  4. 82  min += ts[c_i].a*ts[c_i].x.min();
  5. 83  max += ts[c_i].a*ts[c_i].x.max();
  6. 84 } else {
  7. 85  max += ts[c_i].a*ts[c_i].x.min();
  8. 86  min += ts[c_i].a*ts[c_i].x.max();
  9. 87 }
  10. 88 }


 
et l'affichage gdb ...
 


Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x09b608d6
0x022a0134 in Gecode::MiniModel::LinExpr::post (this=0xbfffe41c, home=0x3979550, icl=ICL_DEF) at gecode/minimodel/lin-expr.cc:82
82                              min += ts[c_i].a*ts[c_i].x.min();
(gdb) print c_i
No symbol "c_i" in current context.
(gdb) print i
$1 = 3
(gdb) print n
$2 = 2


 
est-ce normal qu'il ne trouve pas la variable "c_i" ?
Et "i" a encore bougé...

n°1405560
bjone
Insert booze to continue
Posté le 12-07-2006 à 14:14:07  profilanswer
 

question:
 
GECODE_AUTOARRAY(Int::Linear::Term, ts, n+1);
 
si ça crée un tableau/vecteur de taille n+1, ça va donc de 0 à n en indice.
 
hors:
 
for (int i=n; i--; )
 
va de n-1 à 0 inclus en décrémentant.
 
normal - pas normal ?


Message édité par bjone le 12-07-2006 à 14:14:30
n°1405719
fabllot
Posté le 12-07-2006 à 16:20:32  profilanswer
 

Pour la taille des tableaux : je n'ai aucune idée si c'est normal ou pas ... La bibliothèque en question est assez mystérieuse, mal documentée et incante de la magie noire ... alors pour la question de la taille des tableaux : je n'en sais rien !!!
 
En tout cas, j'ai résolu le problème. J'avais des données mal initialisées, ce qui a du provoquer du "code aléatoire"... va savoir !
 
Merci quand même...


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  C++

  Etrange étrange

 

Sujets relatifs
parse error : vraiment etrangeMauvais lancement de cookie, comportement étrange
Compilation jsp, caractères étrange, prob d'encoding ?Un bug étrange
Erreur étrange avec flottantsDépassement de capacité étrange
[PHP] Bug étrange avec strftime (résolu)Probleme étrange avec realloc ...
EtrangeInversion de matrices : bug etrange
Plus de sujets relatifs à : Etrange étrange


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR