title: Valgrind: "Conditional jump or move depends on uninitialised value(s)"
body: <p>I'm trying to write a function that adds a new struct into a linked list. Valgrind keeps giving me this error no matter what I do. Here is the code:</p>
  
  <pre><code>/* Stores a new address record to the linked list
   * 
   * Parameters:
   * first: pointer to the start of the linked list
   * name: name of the new record to be added (same name can be stored multiple times)
   * ad: IPv4 address to be stored with the name
   * 
   * Returns:
   * Pointer to the new node in linked list (that becomes the first node in list) */
  struct addrRecord *storeIPv4(struct addrRecord *first, const char *name, const addr_4 *ad)
  {
      if (first==NULL) {
          first=malloc(sizeof(struct addrRecord));
          if (!first)
               return NULL;
          strcpy(first-&gt;name,name);
          first-&gt;type=IPv4;
          strcpy(first-&gt;u.in4.a,ad);
          first-&gt;next=NULL;
          return first;
      }
      struct addrRecord *new=malloc(sizeof(struct addrRecord));
      if (!new)
          return NULL;
      strcpy(new-&gt;name,name);
      new-&gt;type=IPv4;
      strcpy(new-&gt;u.in4.a,ad);
      new-&gt;next=first;
      return new;
  }
  </code></pre>
  
  <p>Here is the main code:</p>
  
  <pre><code>struct addrRecord *recs = NULL;
  addr_4 ad4 = {{128, 214, 4, 64}};
  recs = storeIPv4(recs, "www.example.com", &amp;ad4);
  if (!recs)
      return EXIT_FAILURE;
  </code></pre>
  
  <p>and finally the header:</p>
  
  <pre><code>#ifndef AALTO_ADDRESS_H
  #define AALTO_ADDRESS_H
  
  /* container for 32-bit IPv4 address */
  typedef struct {
      char a[4];
  } addr_4;
  
  /* container for 128-bit IPv6 address */
  typedef struct {
      char a[16];
  } addr_6;
  
  /* container for Unix domain address */
  typedef struct {
      char a[108];
  } addr_un;
  
  typedef enum {
      NONE, // address not in use
      IPv4,
      IPv6,
      UNIX
  } adType;
  
  /* One node in linked list of name / address entries */
  struct addrRecord {
      char name[20];
      adType type;
      union {
          addr_4 in4;
          addr_6 in6;
          addr_un un;
      } u;
          struct addrRecord *next;
  };
  
  /* Store IPv4 address to addrRecord */
  struct addrRecord *storeIPv4(struct addrRecord *first, const char *name, const addr_4 *ad);
  
  /* Store IPv6 address to addrRecord */
  struct addrRecord *storeIPv6(struct addrRecord *first, const char *name, const addr_6 *ad);
  
  /* Store Unix domain address to addrRecord */
  struct addrRecord *storeUnix(struct addrRecord *first, const char *name, const addr_un *ad);
  
  /* Find address from linked list starting from 'first' */
  struct addrRecord *findAddress(struct addrRecord *first, const char *name);
  
  /* Prints the address in address record to standard output */
  void printAddress(struct addrRecord *ad);
  
  #endif  /* AALTO_ADDRESS_H */
  </code></pre>
  
  <p>The error I get:</p>
  
  <pre><code>==358== Conditional jump or move depends on uninitialised value(s)
  ==358==    at 0x4C25897: strcpy (mc_replace_strmem.c:311)
  ==358==    by 0x403203: storeIPv4 (address.c:79)
  ==358==    by 0x401706: initRec (test_source.c:30)
  ==358==    by 0x401AB0: test_store (test_source.c:97)
  ==358==    by 0x406350: srunner_run_all (in /tmc/test/test)
  ==358==    by 0x402C5A: tmc_run_tests (tmc-check.c:121)
  ==358==    by 0x402915: main (test_source.c:324)
  </code></pre>
  
  <p>Sorry for the lengthy codes and thanks in advance.</p>