title: Valgrind Uninitialized Values (making a linked list data struct)
body: <p>I've created a linked list class, but this function is producing valgrind errors based saying that there is a conditional jump based upon an uninitialized value in this function.  I'm not exactly sure what I need to do to fix it.</p>
  
  <p>Essentially there is a node class for the linked list and this is iterating over all the nodes checking if the key parameter matches a pre-existing node and if it does it returns the value.</p>
  
  <pre><code>const char *dictionary_get(dictionary_t *d, const char *key)
  {
  
  node* current;
  current = d-&gt;head;
  if(strcmp(current-&gt;key,key)==0)
          return current-&gt;value;
  while(current-&gt;next != NULL){
          current = current-&gt;next;
          if(current!=NULL &amp;&amp; strcmp(current-&gt;key,key)==0)
                  return current-&gt;value;
  }
  
          return NULL;
  }    
  </code></pre>
  
  <p>Any ideas?</p>
  
  <hr>
  
  <p>I've reexamined with valgrind tracking origins and this is the output:</p>
  
  <pre><code>==25042== Conditional jump or move depends on uninitialised value(s)
  ==25042==    at 0x4A06E6A: strcmp (mc_replace_strmem.c:412)
  ==25042==    by 0x400DD6: dictionary_get (libdictionary.c:143)
  ==25042==    by 0x400826: main (part2.c:84)
  ==25042==  Uninitialised value was created by a stack allocation
  ==25042==    at 0x400AE3: dictionary_parse (libdictionary.c:69)
  ==25042== 
  ==25042== Conditional jump or move depends on uninitialised value(s)
  ==25042==    at 0x4A06E8A: strcmp (mc_replace_strmem.c:412)
  ==25042==    by 0x400DD6: dictionary_get (libdictionary.c:143)
  ==25042==    by 0x400826: main (part2.c:84)
  ==25042==  Uninitialised value was created by a stack allocation
  ==25042==    at 0x400AE3: dictionary_parse (libdictionary.c:69)
  ==25042== 
  ==25042== Conditional jump or move depends on uninitialised value(s)
  ==25042==    at 0x400DD9: dictionary_get (libdictionary.c:143)
  ==25042==    by 0x400826: main (part2.c:84)
  ==25042==  Uninitialised value was created by a stack allocation
  ==25042==    at 0x400AE3: dictionary_parse (libdictionary.c:69)
  </code></pre>
  
  <p>It looks like this might be coming from dictionary_parse so I'll post that function too.</p>
  
  <pre><code>int dictionary_parse(dictionary_t *d, char *key_value)
      {
  char* colon;
  char* space;
  colon = key_value;
  space = key_value;
  
  space++;
  
  int key_length = -1; //Default key length to check for failure
  
  int i=0;
  int j=0;   // Loop variables
  int k=0;
  
  int length = strlen(key_value);
  
  for(i=0;i&lt;length-2;i++){
          if(*colon == ':' &amp;&amp; *space == ' '){
                  key_length = i;
                  break;
          }
          colon++;
          space++;
  }
  
  if(key_length == -1 || key_length == 0)
          return -1;
  
  int value_length = length-2-key_length;
  
  colon = key_value;
  
  
  char key_word[key_length];
  key_word[0] = '\0';
  char value_word[value_length];
  value_word[0] = '\0';
  
  for(j=0;j&lt;key_length;j++){
  key_word[j] = *colon;
  colon++;
  }
  
  space++;    
  
  for(k=0; k&lt;value_length;k++){
  value_word[k] = *space;
  space++;
      }
  char* finalkey[key_length];
  strcpy((char*)finalkey,key_word);
  char* finalvalue[value_length];
  strcpy((char*)finalvalue,value_word);
  
  dictionary_add(d,(char*)finalkey,(char*)finalvalue);
  
  return 0;
  }
  </code></pre>