>       keyword.key = (char *) malloc (sizeof (char) * (strlen (key) + 1));
>       i = 0;
>       do {
>               keyword.key[i] = key[i];
>               i++;
>       } while (key[i] != '\0');

The [very bad!] strategic error is that you wrote your own code
instead of using a library function such as 'strdup':

        keyword.key = strdup(key);

or at least 'strncpy':

        i= sizeof (char) * (strlen (key) + 1);
        keyword.key = malloc (i);
        strncpy(keyword.key, key, i);

[You also forgot to check for out-of-memory: 0==malloc(...) etc.]

The tactical error is that you did not copy the terminating '\0'
because the loop termination test (for a given index) occurs
before the copying of the _corresponding_ 'char'.

-- 


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Valgrind-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/valgrind-users

Reply via email to