These 2 errors appear with a page / low level read / strtok file.
==10982== Use of uninitialised value of size 4 ==10982== at 0x40C3899: strtok (strtok.S:197) ==10982== by 0x8048719: main (main.c:9) ==10982== Uninitialised value was created by a stack allocation ==10982== at 0x80487D2: buildList (functions.c:13) ==10982== ==10982== Use of uninitialised value of size 4 ==10982== at 0x40C38C1: strtok (strtok.S:223) ==10982== by 0x8048719: main (main.c:9) ==10982== Uninitialised value was created by a stack allocation ==10982== at 0x80487D2: buildList (functions.c:13) ==10982== ==10982== Conditional jump or move depends on uninitialised value(s) ==10982== at 0x40C38C4: strtok (strtok.S:224) ==10982== by 0x8048719: main (main.c:9) ==10982== Uninitialised value was created by a stack allocation ==10982== at 0x80487D2: buildList (functions.c:13)
Here is the buildList function
void buildList(int fdin, int lines) { char ara[4096]; int num; double p; read(fdin, ara, 4096); char *nl = "\n"; char *ws = " "; char *temp = strtok(ara, " "); while(temp != NULL) { Stock *s = (Stock*)calloc(1, sizeof(Stock)); s->c.symbol = (char*)calloc(strlen(temp)+1, sizeof(char)); strcpy(s->c.symbol, temp); temp = strtok(NULL, "\n"); s->c.name = (char*)calloc(strlen(temp)+1, sizeof(char)); strcpy(s->c.name, temp); temp = strtok(NULL, "\n"); sscanf(temp, "%lf", &p); temp = strtok(NULL, "\n"); s->price = p; sscanf(temp, "%d", &num); s->shares = num; Node *n = (Node*)calloc(1, sizeof(Node)); n->data = s; addOrdered(n); temp = strtok(NULL, " "); } close(fdin); }
I can not understand why this error occurs. From what I read, this is because I am assigning char * things from strtok without assigning any memory to them. However, this is how I did it in the past, and I think that everything is in order.
source share