#C Debug

1 messages · Page 1 of 1 (latest)

oak sage
#

Hello, can someone help me to find the issue in my code
I'm working with trees, using the following structure :

struct noeud
{
  struct noeud *gauche;
  struct noeud *droite;
  int desequilibre;
  int valeur;
};
typedef struct noeud* arbre;

I'm trying to implement a rotation function which turn
v1
/
v2 D2
/
G D1

into :
v2
/
G v1
/
D1 D2
and i wrote that :

arbre rotation_droite(arbre a){
  /*Effectue la rotation droite de l'arbre a*/
  if (a != NULL && a->gauche != NULL){
    int d1prime = -1 + a->desequilibre - max(a->gauche->desequilibre, 0);
    int d2prime = -1+ a->gauche->desequilibre + min(0, d1prime);
    
    arbre D = a->droite;
    a->droite = cree_feuille(a->valeur);
    a->valeur = a->gauche->valeur;
    a->droite->gauche = a->gauche->droite;
    a->droite -> droite = D;
    a->droite->desequilibre = d1prime;
    a->desequilibre = d2prime;
  }
  return a;
}

However, i'm getting a segmentation error and i dont understand why.
If someone can help me . . .
Thank you very much !

obtuse cairnBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

iron sorrel
#

or run it with Asan

obtuse cairnBOT
#
How To Use Sanitizers

Sanitizers are tools which generate additional code in your program that can catch many common programming mistakes, such as:

General Advice

Not all sanitizers can be combined, but when they can, use e.g.: -fsanitize=address,undefined to combine them. Always compile with debug info to get line numbers, variable names, etc.

MSVC 19.27+ and VS 2019 16.9+
Sample Program
int main(void) {
    int x;
    return x;
} ```
`-fsanitize=memory -g` Output

SUMMARY: MemorySanitizer: use-of-uninitialized-value /tmp/test.cpp:3:5 in main > Exiting (3:5 is line and column of return)

oak sage
iron sorrel
#

(◠‿◠✿)

obtuse cairnBOT
#

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.