0

I recently ran a full leak check with valgrind only to discover this error and "Conditional jump or move depends on uninitialised value(s)" it has been throwing. What am i doing wrong here? It keeps pointing to this function:

int tldlist_add(TLDList *tld, char *hostname, Date *d) {

    if (date_compare(tld->begin, d) > 0 || date_compare(tld->end, d) < 0)
        return 0;

    char *dot = strrchr(hostname, '.') + 1;
    int i = 0;
    while (i < sizeof(dot))
    {
        dot[i] = tolower(dot[i]);
        i++;
    }
    char *temptld = (char *)malloc(sizeof(dot));
    strcpy(temptld, dot);

    tld->root = addnode(tld, temptld, tld->root);
    tld->count++;
    return 1;

}

specifically at this line: dot[i] = tolower(dot[i]);

Any help would be greatly appreciated, thank you!

dbush
  • 205,898
  • 23
  • 218
  • 273
user1610834
  • 115
  • 2
  • 13
  • What's up with all the pointless casting? You could remove all casts from that function and it would be all the better for it. Only cast if necessary, otherwise you can hide potential problems. – user694733 Oct 28 '15 at 10:37
  • 1
    If you have a different question, please post it as a new question. Don't completely change the existing question, which invalidates the existing answers. – dbush Oct 28 '15 at 12:51

2 Answers2

0

sizeof(dot) gives size of pointer not sizeof string pointed to by pointer dot and dot[i] will lead to out of bound memory access.

Gopi
  • 19,784
  • 4
  • 24
  • 36
0
  1. You're using sizeof where you should use strlen.
  2. You're needlessly casting an int to int, twice.
  3. You're casting the result of malloc. Don't.
  4. You forgot to allocate enough memory for the null terminator.
Community
  • 1
  • 1
Emil Laine
  • 41,598
  • 9
  • 101
  • 157