Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7831307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:40:04+00:00 2026-06-02T11:40:04+00:00

I am writing a program to select words from a txt file. Compiling flags:

  • 0

I am writing a program to select words from a txt file.
Compiling flags: -std=gnu99
The program has some segmentation faults that I am debugging with GDB and Valgrind.
Valgrind flags: –track-origins=yes –leak-check=full –show-reachable=yes
I have some question about Valgrind error messages

First of all here the code explained

  • struct character: is the struct that will contain all the word that
    start with a specific letter, for example a or b or c, ecc.
  • include function: when you have to add a word into the specific structure, insert function scans the words array to see if there is an occurrance of this word. If yes, it increase the word count. Otherwise it will add the word to the array. If there is no space, the function increases array space.
  • the main is quiet linear. You can see struct for each character of the alphabet, you can see a while loop for reading lines of text file.

#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <errno.h>


struct character
{
    char **words;
    int *count;
    int arrayCounter;
};

/*
 * if finds in the array the word to add, then increase counter
 * if it does not find the word, it puts the word non la trova ce la mette nel primo slot che è NULL, quindi vuoto.
 * se non trova slot vuoti aumenta la dimensione degli array e poi torna al punto due.
 */
void insert(struct character *character, char *word)
{
    while(1){
    printf("inserting word %s\n", word);
    for(int i = 0; i < character->arrayCounter; i++)
    {
        printf("%d\n",i);
        if((character->words[i] != NULL) && (strcmp(character->words[i], word) == 0))
        {
            printf("Insert: I found a corrispondence of word in the array, now I increase the word counter in the struct\n");
            printf("Original word: %s word to compare %s\n", character->words[i], word);

            character->count[i] = character->count[i] + 1;
            printf("Word %s counter: %d\n", character->words[i], character->count[i]);
            return;
        }

    }

    ciclo:
    for(int i = 0; i < character->arrayCounter; i++)
    {
        printf("ciclo: %d\n", i);
        if(character->words[i] == NULL)
        {
            printf("Insert: ho trovato un posto vuoto nello slot %d e ci metto la word %s\n", i, word);
            character->words[i] = malloc((strlen(word) + 1) * sizeof(char));
            strcpy(character->words[i], word);
            character->count[i] = character->count[i] + 1;
            printf("Insert: controllo, la word è %s, il suo contatore è %d\n", character->words[i], character->count[i]);

            printf("\n\n\n\n");
            return;
        }
    }

    printf("!!!Increasing arrayCounter dimension, now it is %d\n", character->arrayCounter);
    character->words = realloc(character->words, (character->arrayCounter + 1) * sizeof(char*));
    character->count = realloc(character->count, (character->arrayCounter + 1) * sizeof(int));
    character->arrayCounter++;
    printf("!!!Dimension increase, arrayCounter is %d\n", character->arrayCounter);
    /*goto ciclo;*/}
}

int main()
{
    FILE *fileToRead;
    if((fileToRead = fopen("/home/caterpillar/Universita/workspace_Progetti/SO_ricercaParole/testo2.txt", "r")) == NULL)
    {
        printf("error in opening file\n" "%s\n", strerror(errno));
        exit(EXIT_FAILURE);

    }

    struct character a;
    memset(&a, 0, sizeof(a));
    a.arrayCounter = 1;
    a.words = malloc((a.arrayCounter)*sizeof(char*));
    a.count = calloc(a.arrayCounter,sizeof(int));

    struct character c;
    memset(&c, 0, sizeof(c));
    c.arrayCounter = 1;
    c.words = malloc((c.arrayCounter)*sizeof(char*));
    c.count = calloc(c.arrayCounter,sizeof(int));

    struct character e;
    memset(&e, 0, sizeof(e));
    e.arrayCounter = 1;
    e.words = malloc((e.arrayCounter)*sizeof(char*));
    e.count = calloc(e.arrayCounter,sizeof(int));

    struct character g;
    memset(&g, 0, sizeof(g));
    g.arrayCounter = 1;
    g.words = malloc((g.arrayCounter)*sizeof(char*));
    g.count = calloc(g.arrayCounter,sizeof(int));

    struct character i;
    memset(&i, 0, sizeof(i));
    i.arrayCounter = 1;
    i.words = malloc((i.arrayCounter)*sizeof(char*));
    i.count = calloc(i.arrayCounter,sizeof(int));

    struct character m;
    memset(&m, 0, sizeof(m));
    m.arrayCounter = 1;
    m.words = malloc((m.arrayCounter)*sizeof(char*));
    m.count = calloc(m.arrayCounter,sizeof(int));

    struct character o;
    memset(&o, 0, sizeof(o));
    o.arrayCounter = 1;
    o.words = malloc((o.arrayCounter)*sizeof(char*));
    o.count = calloc(o.arrayCounter,sizeof(int));

    struct character q;
    memset(&q, 0, sizeof(q));
    q.arrayCounter = 1;
    q.words = malloc((q.arrayCounter)*sizeof(char*));
    q.count = calloc(q.arrayCounter,sizeof(int));

    struct character s;
    memset(&s, 0, sizeof(s));
    s.arrayCounter = 1;
    s.words = malloc((s.arrayCounter)*sizeof(char*));
    s.count = calloc(s.arrayCounter,sizeof(int));

    struct character u;
    memset(&u, 0, sizeof(u));
    u.arrayCounter = 1;
    u.words = malloc((u.arrayCounter)*sizeof(char*));
    u.count = calloc(u.arrayCounter,sizeof(int));

    struct character z;
    memset(&z, 0, sizeof(z));
    z.arrayCounter = 1;
    z.words = malloc((z.arrayCounter)*sizeof(char*));
    z.count = calloc(z.arrayCounter,sizeof(int));





    struct character b;
    memset(&b, 0, sizeof(b));
    b.arrayCounter = 1;
    b.words = malloc((b.arrayCounter)*sizeof(char*));
    b.count = calloc(b.arrayCounter,sizeof(int));

    struct character d;
    memset(&d, 0, sizeof(d));
    d.arrayCounter = 1;
    d.words = malloc((d.arrayCounter)*sizeof(char*));
    d.count = calloc(d.arrayCounter,sizeof(int));

    struct character f;
    memset(&f, 0, sizeof(f));
    f.arrayCounter = 1;
    f.words = malloc((f.arrayCounter)*sizeof(char*));
    f.count = calloc(f.arrayCounter,sizeof(int));

    struct character h;
    memset(&h, 0, sizeof(h));
    h.arrayCounter = 1;
    h.words = malloc((h.arrayCounter)*sizeof(char*));
    h.count = calloc(h.arrayCounter,sizeof(int));

    struct character l;
    memset(&l, 0, sizeof(l));
    l.arrayCounter = 1;
    l.words = malloc((l.arrayCounter)*sizeof(char*));
    l.count = calloc(l.arrayCounter,sizeof(int));

    struct character n;
    memset(&n, 0, sizeof(n));
    n.arrayCounter = 1;
    n.words = malloc((n.arrayCounter)*sizeof(char*));
    n.count = calloc(n.arrayCounter,sizeof(int));

    struct character p;
    memset(&p, 0, sizeof(p));
    p.arrayCounter = 1;
    p.words = malloc((p.arrayCounter)*sizeof(char*));
    p.count = calloc(p.arrayCounter,sizeof(int));

    struct character r;
    memset(&r, 0, sizeof(r));
    r.arrayCounter = 1;
    r.words = malloc((r.arrayCounter)*sizeof(char*));
    r.count = calloc(r.arrayCounter,sizeof(int));

    struct character t;
    memset(&t, 0, sizeof(t));
    t.arrayCounter = 1;
    t.words = malloc((t.arrayCounter)*sizeof(char*));
    t.count = calloc(t.arrayCounter,sizeof(int));

    struct character v;
    memset(&v, 0, sizeof(v));
    v.arrayCounter = 1;
    v.words = malloc((v.arrayCounter)*sizeof(char*));
    v.count = calloc(v.arrayCounter,sizeof(int));




    char *line;
    line = malloc(5000*sizeof(char));
    ssize_t bytesRead = 0;
    ssize_t lineLength = 5000;
    //while(fgets(line, 5000, fileToRead) != (NULL))
    while((bytesRead = getline(&line, &lineLength, fileToRead)) != -1)
    {
        line[bytesRead + 1] = '\0';
        printf("linea è %s, strlen è %d\n", line, strlen(line));
        printf("tronco l'accapo\n");
        line[strlen(line) - 1] = '\0';
        printf("Nuova linea è %s, strlen è %d\n", line, strlen(line));
        char *buffer;
        buffer = strtok(line, " ");
        /*if(buffer =! NULL)
        {
            break;
        }*/
        if((buffer != NULL) && (buffer[0] == 'a'))
        {
            insert(&a, buffer);
        }
        if((buffer != NULL) && (buffer[0] == 'c'))
        {
            insert(&c, buffer);
        }
        if((buffer != NULL) && (buffer[0] == 'e'))
        {
            insert(&e, buffer);
        }
        if((buffer != NULL) && (buffer[0] == 'g'))
        {
            insert(&g, buffer);
        }
        if((buffer != NULL) && (buffer[0] == 'i'))
        {
            insert(&i, buffer);
        }
        if((buffer != NULL) && (buffer[0] == 'm'))
        {
            insert(&m, buffer);
        }
        if((buffer != NULL) && (buffer[0] == 'o'))
        {
            insert(&o, buffer);
        }
        if((buffer != NULL) && (buffer[0] == 'q'))
        {
            insert(&q, buffer);
        }
        if(((buffer != NULL) && buffer[0] == 's'))
        {
            insert(&s, buffer);
        }
        if(((buffer != NULL) && buffer[0] == 'u'))
        {
            insert(&u, buffer);
        }
        if(((buffer != NULL) && buffer[0] == 'z'))
        {
            insert(&z, buffer);
        }

        printf("***********************\n");
        for(int i = 0; (i < a.arrayCounter) && (a.words[i] != NULL); i++)
        {
            printf("Parola %s contatore %d\n", a.words[i], a.count[i]);
        }
        printf("***********************\n");
        //memset(buffer, NULL, 50*sizeof(char));
        while(1)
        {
            printf("while 1\n");
            buffer = strtok(NULL, " ");
            if(buffer == NULL)
            {
                printf("buffer is NULL, exiting from loop and going to next line\n");
                break;
            }

            if((buffer != NULL) && (buffer[0] == 'a'))
            {
                insert(&a, buffer);
            }
            if((buffer != NULL) && (buffer[0] == 'c'))
            {
                insert(&c, buffer);
            }
            if((buffer != NULL) && (buffer[0] == 'e'))
            {
                insert(&e, buffer);
            }
            if((buffer != NULL) && (buffer[0] == 'g'))
            {
                insert(&g, buffer);
            }
            if((buffer != NULL) && (buffer[0] == 'i'))
            {
                insert(&i, buffer);
            }
            if((buffer != NULL) && (buffer[0] == 'm'))
            {
                insert(&m, buffer);
            }
            if((buffer != NULL) && (buffer[0] == 'o'))
            {
                insert(&o, buffer);
            }
            if((buffer != NULL) && (buffer[0] == 'q'))
            {
                insert(&q, buffer);
            }
            if((buffer != NULL) && (buffer[0] == 's'))
            {
                insert(&s, buffer);
            }
            if((buffer != NULL) && (buffer[0] == 'u'))
            {
                insert(&u, buffer);
            }
            if((buffer != NULL) && (buffer[0] == 'z'))
            {
                insert(&z, buffer);
            }



            if((buffer != NULL) && (buffer[0] == 'b'))
            {
                insert(&b, buffer);
            }
            if((buffer != NULL) && (buffer[0] == 'd'))
            {
                insert(&d, buffer);
            }
            if((buffer != NULL) && (buffer[0] == 'f'))
            {
                insert(&f, buffer);
            }
            if((buffer != NULL) && (buffer[0] == 'h'))
            {
                insert(&h, buffer);
            }
            if((buffer != NULL) && (buffer[0] == 'l'))
            {
                insert(&l, buffer);
            }
            if((buffer != NULL) && (buffer[0] == 'n'))
            {
                insert(&n, buffer);
            }
            if((buffer != NULL) && (buffer[0] == 'p'))
            {
                insert(&p, buffer);
            }
            if((buffer != NULL) && (buffer[0] == 'r'))
            {
                insert(&r, buffer);
            }
            if((buffer != NULL) && (buffer[0] == 't'))
            {
                insert(&t, buffer);
            }
            if((buffer != NULL) && (buffer[0] == 'v'))
            {
                insert(&v, buffer);
            }







            //memset(buffer, NULL, 50*sizeof(char));
        }
    }
    printf("***********************\n");
    for(int ii = 0; (ii < c.arrayCounter) && (c.words[ii] != NULL); ii++)
    {
        printf("Word %s count %d\n", c.words[ii], c.count[ii]);
    }
    printf("***********************\n");

    printf("***********************\n");
    for(int ii = 0; (ii < e.arrayCounter) && (e.words[ii] != NULL); ii++)
    {
        printf("Word %s count %d\n", e.words[ii], e.count[ii]);
    }
    printf("***********************\n");
    /*
    for(int i = 0; i < 21; i++)
    {
        printf("!!!!!!!STAMPO PAROLE CHE INIZIANO CON LETTERA %s\n", arrayCaratteri[i]);
        printf("***********************\n");
        for(int ii = 0; (ii < arrayCaratteri[i].arrayCounter) && (arrayCaratteri[i].words[ii] != NULL); ii++)
        {
            printf("Parola %s contatore %d\n", arrayCaratteri[i].words[ii], arrayCaratteri[i].count[ii]);
        }
        printf("***********************\n");
    }*/
    fclose(fileToRead);  // close the file prior to exiting the routine
    free(a.words);
    free(a.count);
    free(b.words);
    free(b.count);
    free(c.words);
    free(c.count);
    free(d.words);
    free(d.count);
    free(e.words);
    free(e.count);
    free(f.words);
    free(f.count);
    free(g.words);
    free(g.count);
    free(h.words);
    free(h.count);
    free(i.words);
    free(i.count);
    free(l.words);
    free(l.count);
    free(m.words);
    free(m.count);
    free(n.words);
    free(n.count);
    free(o.words);
    free(o.count);
    free(p.words);
    free(p.count);
    free(q.words);
    free(q.count);
    free(r.words);
    free(r.count);
    free(s.words);
    free(s.count);
    free(t.words);
    free(t.count);
    free(u.words);
    free(u.count);
    free(v.words);
    free(v.count);
    free(z.words);
    free(z.count);

    printf("terminate successfully\n");
    return 0;
}

Here some Valgrind error messages about conditional jumps depending on initialized values:

[caterpillar@hostname Debug]$ valgrind --track-origins=yes 
--leak-check=full ./SO_ricercaParole 
==2791== Memcheck, a memory error detector 
==2791== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al. 
==2791== Using Valgrind-3.6.1 and LibVEX; rerun with -h for copyright info 
==2791== Command: ./SO_ricercaParole 
==2791== 
==2791== Conditional jump or move depends on uninitialised value(s) 
==2791== at 0x80486E1: insert (parole.c:38) 
==2791== by 0x8049520: main (parole.c:325) 
==2791== Uninitialised value was created by a heap allocation 
==2791== at 0x4007D89: malloc (vg_replace_malloc.c:236) 
==2791== by 0x8048B17: main (parole.c:119) 
==2791== 
==2791== Conditional jump or move depends on uninitialised value(s) 
==2791== at 0x80487E0: insert (parole.c:54) 
==2791== by 0x8049520: main (parole.c:325) 
==2791== Uninitialised value was created by a heap allocation 
==2791== at 0x4007D89: malloc (vg_replace_malloc.c:236) 
==2791== by 0x8048B17: main (parole.c:119) 
==2791== 
==2791== Conditional jump or move depends on uninitialised value(s) 
==2791== at 0x80486E1: insert (parole.c:38) 
==2791== by 0x80496E2: main (parole.c:364) 
==2791== Uninitialised value was created by a heap allocation 
==2791== at 0x4007D89: malloc (vg_replace_malloc.c:236) 
==2791== by 0x8048E5C: main (parole.c:177) 
==2791== 
==2791== Conditional jump or move depends on uninitialised value(s) 
==2791== at 0x80487E0: insert (parole.c:54) 
==2791== by 0x80496E2: main (parole.c:364) 
==2791== Uninitialised value was created by a heap allocation 
==2791== at 0x4007D89: malloc (vg_replace_malloc.c:236) 
==2791== by 0x8048E5C: main (parole.c:177) 
==2791== 
==2791== Conditional jump or move depends on uninitialised value(s) 
==2791== at 0x80486E1: insert (parole.c:38) 
==2791== by 0x80494BC: main (parole.c:317) 
==2791== Uninitialised value was created by a heap allocation 
==2791== at 0x4007D89: malloc (vg_replace_malloc.c:236) 
==2791== by 0x8048A5D: main (parole.c:107) 
==2791== 
==2791== Conditional jump or move depends on uninitialised value(s) 
==2791== at 0x80487E0: insert (parole.c:54) 
==2791== by 0x80494BC: main (parole.c:317) 
==2791== Uninitialised value was created by a heap allocation 
==2791== at 0x4007D89: malloc (vg_replace_malloc.c:236) 
==2791== by 0x8048A5D: main (parole.c:107) 
==2791== 
==2791== Use of uninitialised value of size 4 
==2791== at 0x4D9851AB: _itoa_word (_itoa.c:195) 
==2791== by 0x4D98A03B: vfprintf (vfprintf.c:1570) 
==2791== by 0x4D98FF8E: printf (printf.c:35) 
==2791== by 0x80494BC: main (parole.c:317) 
==2791== Uninitialised value was created by a heap allocation 
==2791== at 0x4007E73: realloc (vg_replace_malloc.c:525) 
==2791== by 0x804892F: insert (parole.c:69) 
==2791== by 0x80494BC: main (parole.c:317) 
==2791== 
==2791== Conditional jump or move depends on uninitialised value(s) 
==2791== at 0x4D9851B3: _itoa_word (_itoa.c:195) 
==2791== by 0x4D98A03B: vfprintf (vfprintf.c:1570) 
==2791== by 0x4D98FF8E: printf (printf.c:35) 
==2791== by 0x80494BC: main (parole.c:317) 
==2791== Uninitialised value was created by a heap allocation 
==2791==
at 0x4007E73: realloc (vg_replace_malloc.c:525) 
==2791== by 0x804892F: insert (parole.c:69) 
==2791== by 0x80494BC: main (parole.c:317) 
==2791== 
==2791== Conditional jump or move depends on uninitialised value(s) 
==2791== at 0x4D98A3FD: vfprintf (vfprintf.c:1570) 
==2791== by 0x4D98FF8E: printf (printf.c:35) 
==2791== by 0x80494BC: main (parole.c:317) 
==2791== Uninitialised value was created by a heap allocation 
==2791== at 0x4007E73: realloc (vg_replace_malloc.c:525) 
==2791== by 0x804892F: insert (parole.c:69) 
==2791== by 0x80494BC: main (parole.c:317) 
==2791== 
==2791== Conditional jump or move depends on uninitialised value(s) 
==2791== at 0x4D989D7D: vfprintf (vfprintf.c:1570) 
==2791== by 0x4D98FF8E: printf (printf.c:35) 
==2791== by 0x80494BC: main (parole.c:317) 
==2791== Uninitialised value was created by a heap allocation 
==2791== at 0x4007E73: realloc (vg_replace_malloc.c:525) 
==2791== by 0x804892F: insert (parole.c:69) 
==2791== by 0x80494BC: main (parole.c:317) 
==2791== 
==2791== Conditional jump or move depends on uninitialised value(s) 
==2791== at 0x80486E1: insert (parole.c:38) 
==2791== by 0x804982B: main (parole.c:392) 
==2791== Uninitialised value was created by a heap allocation 
==2791== at 0x4007D89: malloc (vg_replace_malloc.c:236) 
==2791== by 0x804907E: main (parole.c:219) 
==2791== 
==2791== Conditional jump or move depends on uninitialised value(s) 
==2791== at 0x80487E0: insert (parole.c:54) 
==2791==
by 0x804982B: main (parole.c:392) 
==2791== Uninitialised value was created by a heap allocation 
==2791== at 0x4007D89: malloc (vg_replace_malloc.c:236) 
==2791== by 0x804907E: main (parole.c:219) 
==2791== 
==2791== Conditional jump or move depends on uninitialised value(s) 
==2791== at 0x80486E1: insert (parole.c:38) 
==2791== by 0x8049584: main (parole.c:333) 
==2791== Uninitialised value was created by a heap allocation 
==2791== at 0x4007D89: malloc (vg_replace_malloc.c:236) 
==2791== by 0x8048BD1: main (parole.c:131) 
==2791== 
==2791== Conditional jump or move depends on uninitialised value(s) 
==2791== at 0x80487E0: insert (parole.c:54) 
==2791== by 0x8049584: main (parole.c:333) 
==2791== Uninitialised value was created by a heap allocation 
==2791== at 0x4007D89: malloc (vg_replace_malloc.c:236) 
==2791== by 0x8048BD1: main (parole.c:131) 
==2791== 
==2791== Conditional jump or move depends on uninitialised value(s) 
==2791== at 0x80486E1: insert (parole.c:38) 
==2791== by 0x804976F: main (parole.c:376) 
==2791== Uninitialised value was created by a heap allocation 
==2791== at 0x4007D89: malloc (vg_replace_malloc.c:236) 
==2791== by 0x8048F52: main (parole.c:195) 
==2791== 
==2791== Conditional jump or move depends on uninitialised value(s) 
==2791== at 0x80487E0: insert (parole.c:54) 
==2791== by 0x804976F: main (parole.c:376) 
==2791== Uninitialised value was created by a heap allocation 
==2791== at 0x4007D89: malloc (vg_replace_malloc.c:236) 
==2791== by 0x8048F52: main (parole.c:195) 
==2791== 
==2791== Conditional jump or move depends on uninitialised value(s) 
==2791== at 0x80486E1: insert (parole.c:38) 
==2791== by 0x80497CD: main (parole.c:384) 
==2791== Uninitialised value was created by a heap allocation 
==2791== at 0x4007D89: malloc (vg_replace_malloc.c:236) 
==2791== by 0x8048FE8: main (parole.c:207) 
==2791== 
==2791== Conditional jump or move depends on uninitialised value(s) 
==2791== at 0x80487E0: insert (parole.c:54) 
==2791== by 0x80497CD: main (parole.c:384) 
==2791== Uninitialised value was created by a heap allocation 
==2791== at 0x4007D89: malloc (vg_replace_malloc.c:236) 
==2791== by 0x8048FE8: main (parole.c:207) 
==2791== 
==2791== Conditional jump or move depends on uninitialised value(s) 
==2791== at 0x80486E1: insert (parole.c:38) 
==2791== by 0x80494EE: main (parole.c:321) 
==2791== Uninitialised value was created by a heap allocation 
==2791== at 0x4007D89: malloc (vg_replace_malloc.c:236) 
==2791== by 0x8048ABA: main (parole.c:113) 
==2791== Conditional jump or move depends on uninitialised value(s) 
==2791== at 0x80487E0: insert (parole.c:54) 
==2791== by 0x80494EE: main (parole.c:321) 
==2791== Uninitialised value was created by a heap allocation 
==2791== at 0x4007D89: malloc (vg_replace_malloc.c:236) 
==2791== by 0x8048ABA: main (parole.c:113) 
==2791== 
==2791== Conditional jump or move depends on uninitialised value(s) 
==2791== at 0x80486E1: insert (parole.c:38) 
==2791==
by 0x80497FC: main (parole.c:388) 
==2791== Uninitialised value was created by a heap allocation 
==2791== at 0x4007D89: malloc (vg_replace_malloc.c:236) 
==2791== by 0x8049033: main (parole.c:213) 
==2791== Conditional jump or move depends on uninitialised value(s) 
==2791== at 0x80487E0: insert (parole.c:54) 
==2791== by 0x80497FC: main (parole.c:388) 
==2791== Uninitialised value was created by a heap allocation 
==2791== at 0x4007D89: malloc (vg_replace_malloc.c:236) 
==2791== by 0x8049033: main (parole.c:213) 
==2791== 
==2791== Conditional jump or move depends on uninitialised value(s) 
==2791== at 0x80486E1: insert (parole.c:38) 
==2791==
by 0x80492E6: main (parole.c:267) 
==2791== Uninitialised value was created by a heap allocation 
==2791== at 0x4007D89: malloc (vg_replace_malloc.c:236) 
==2791== by 0x8048B74: main (parole.c:125) 
==2791== 
==2791== Conditional jump or move depends on uninitialised value(s) 
==2791== at 0x80487E0: insert (parole.c:54) 
==2791== by 0x80492E6: main (parole.c:267) 
==2791== Uninitialised value was created by a heap allocation 
==2791== at 0x4007D89: malloc (vg_replace_malloc.c:236) 
==2791== by 0x8048B74: main (parole.c:125) 
==2791== 
==2791== Conditional jump or move depends on uninitialised value(s) 
==2791== at 0x80486E1: insert (parole.c:38) 
==2791== by 0x804964C: main (parole.c:349) 
==2791== Uninitialised value was created by a heap allocation 
==2791== at 0x4007D89: malloc (vg_replace_malloc.c:236) 
==2791== by 0x8048D45: main (parole.c:155) 
==2791== Conditional jump or move depends on uninitialised value(s) 
==2791== at 0x80487E0: insert (parole.c:54) 
==2791== by 0x804964C: main (parole.c:349) 
==2791== Uninitialised value was created by a heap allocation 
==2791== at 0x4007D89: malloc (vg_replace_malloc.c:236) 
==2791== by 0x8048D45: main (parole.c:155) 
==2791== Use of uninitialised value of size 4 
==2791== at 0x4D9851AB: _itoa_word (_itoa.c:195) 
==2791== by 0x4D98A03B: vfprintf (vfprintf.c:1570) 
==2791== by 0x4D98FF8E: printf (printf.c:35) 
==2791== by 0x80497CD: main (parole.c:384) 
==2791== Uninitialised value was created by a heap allocation 
==2791==
at 0x4007E73: realloc (vg_replace_malloc.c:525) 
==2791== by 0x804892F: insert (parole.c:69) 
==2791== by 0x80497CD: main (parole.c:384) 
==2791== 
==2791== Conditional jump or move depends on uninitialised value(s) 
==2791== at 0x4D9851B3: _itoa_word (_itoa.c:195) 
==2791== by 0x4D98A03B: vfprintf (vfprintf.c:1570) 
==2791== by 0x4D98FF8E: printf (printf.c:35) 
==2791== by 0x80497CD: main (parole.c:384) 
==2791== Uninitialised value was created by a heap allocation 
==2791==
at 0x4007E73: realloc (vg_replace_malloc.c:525) 
==2791== by 0x804892F: insert (parole.c:69) 
==2791== by 0x80497CD: main (parole.c:384) 
==2791== 
==2791== Conditional jump or move depends on uninitialised value(s) 
==2791== at 0x4D98A3FD: vfprintf (vfprintf.c:1570) 
==2791== by 0x4D98FF8E: printf (printf.c:35) 
==2791== by 0x80497CD: main (parole.c:384) 
==2791== Uninitialised value was created by a heap allocation 
==2791== at 0x4007E73: realloc (vg_replace_malloc.c:525) 
==2791== by 0x804892F: insert (parole.c:69) 
==2791== by 0x80497CD: main (parole.c:384) 
==2791== 
==2791== Conditional jump or move depends on uninitialised value(s) 
==2791== at 0x4D989D7D: vfprintf (vfprintf.c:1570) 
==2791== by 0x4D98FF8E: printf (printf.c:35) 
==2791== by 0x80497CD: main (parole.c:384) 
==2791== Uninitialised value was created by a heap allocation 
==2791== at 0x4007E73: realloc (vg_replace_malloc.c:525) 
==2791== by 0x804892F: insert (parole.c:69) 
==2791== by 0x80497CD: main (parole.c:384) 

Why this kind of messages? I initialized all structs and arrays, ecc.ecc.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T11:40:07+00:00Added an answer on June 2, 2026 at 11:40 am
    character->words = realloc(character->words, (character->arrayCounter + 1) * sizeof(char*));
    character->count = realloc(character->count, (character->arrayCounter + 1) * sizeof(int));
    character->arrayCounter++;
    
    1. You should never use the construct ptr = realloc(ptr,size); If realloc returns NULL, the memory pointed to by ptr is leaked and you can’t reach it anymore.
    2. Don’t increase the sizes by just one element, that is inefficient and expensive. Since it also leads to memory fragmentation, it probably doesn’t use less memory than an increase by a larger amount, say an increase by a constant factor (double the size, multiply by 1.5 [and add one to make sure the size is really increased]).
    3. The new storage in character->words doesn’t necessarily contain NULL, it is uninitialised, as are the original words pointers: a.words = malloc((a.arrayCounter)*sizeof(char*));.

    Probably 3. is what valgrind reports.

    And your code would be much shorter and more readable if instead of having a character structure named after the character, you had one array and indexed into that array, so e.g. struct character e; would correspond to character_array['e' - 'a'];.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a program in C# that runs some select statements using parameters
I'm writing a program in C++ and for some reason I'm getting a segmentation
I'm writing a program to allow a user to select a csv file, with
I am writing a program that does some unit conversions from a Brix scale
In my program below, I'm writing every record I select from MBRHISTDETL to a
I'm writing a program in Ruby that downloads a file from an RSS feed
I'm writing a program on Linux in C to analyze core files produced from
I'm writing a program in C++ and it takes some command line arguments. The
Backgorund I am currently writing a program that allows a user to select a
Writing a program to retrieve data from an sqlite database keeps returning no results

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.