title: Use of uninitialised value of size 8. C++
body: <p>These are few snippets of where I think the problem lies (a lot of code otherwise):</p>
  
  <pre><code>//to insert the course by name and number into the hash table
  int Table::insert(Course &amp; c) {
    return insertByName(c) - insertByNumber(c); //return 0 for success
  }
  
  
  //to insert the course by the name into the hash table
  int Table::insertByName(Course &amp; c) {
    int index;
    char *name;
  
    c.getName(name); //copy the name of the course
    index = hashFunc(name); //get the index for the name
    //insert the course by the index of the name at head
    if (table[index] == NULL) { ///////////////////////////// LINE: 144
        table[index] = new node;
        table[index]-&gt;course.copy(c);
        table[index]-&gt;next = NULL;
    } else {
        node * temp = new node;
        temp-&gt;course.copy(c);
        temp-&gt;next = table[index];
        table[index] = temp;
    }
    return 1;
  }
  
  
  
  //to insert the course by the number into the hash table
    int Table::insertByNumber(Course &amp; c) {
    int index;
    char *number;
  
    c.getNumber(number); //copy the number of the course
    index = hashFunc(number); //get the index for the number
  
    //insert the course by the index of the name at head
    if (table[index] == NULL) { ///////////////////////////// LINE: 167
        table[index] = new node;
        table[index]-&gt;course.copy(c);
        table[index]-&gt;next = NULL;
    } else {
        node * temp = new node;
        temp-&gt;course.copy(c);
        temp-&gt;next = table[index];
        table[index] = temp;
    }
    return 1;
  }
  </code></pre>
  
  <p><strong>UPDATE:</strong> Here is <code>Course::getName()</code> and <code>Course::getNumber()</code>:</p>
  
  <pre><code>//to copy the name of the course to the passed array
  int Course::getName(char *&amp; arr) {
    arr = new char[strlen(name) + 1];
    strcpy(arr, name);
    return 1;
  }
  
  
  //to copy the number of the course to the passed array
  int Course::getNumber(char *&amp; arr) {
    arr = new char[strlen(number) + 1];
    strcpy(arr, number);
    return 1;
  }
  </code></pre>
  
  <p><strong>HERE IS A DETAILED ERROR MESSAGE (Valgrind):</strong></p>
  
  <blockquote>
  <pre><code>--24010-- Reading syms from /lib/x86_64-linux-gnu/ld-2.19.so
  --24010--   Considering /lib/x86_64-linux-gnu/ld-2.19.so ..
  --24010--   .. CRC mismatch (computed ef2bc4a1 wanted 12987a55)
  --24010--   Considering /usr/lib/debug/lib/x86_64-linux-gnu/ld-2.19.so ..
  --24010--   .. CRC is valid
  --24010-- Reading syms from /usr/lib/valgrind/memcheck-amd64-linux
  --24010--   Considering /usr/lib/valgrind/memcheck-amd64-linux ..
  --24010--   .. CRC mismatch (computed 4f1eed43 wanted a323a3ab)
  --24010--    object doesn't have a symbol table
  --24010--    object doesn't have a dynamic symbol table
  --24010-- Scheduler: using generic scheduler lock implementation.
  --24010-- Reading suppressions file: /usr/lib/valgrind/default.supp
  ==24010== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-24010-by-bad6-on-???
  ==24010== embedded gdbserver: writing to   /tmp/vgdb-pipe-to-vgdb-from-24010-by-bad6-on-???
  ==24010== embedded gdbserver: shared mem   /tmp/vgdb-pipe-shared-mem-vgdb-24010-by-bad6-on-???
  ==24010== 
  ==24010== TO CONTROL THIS PROCESS USING vgdb (which you probably
  ==24010== don't want to do, unless you know exactly what you're doing,
  ==24010== or are doing some strange experiment):
  ==24010==   /usr/lib/valgrind/../../bin/vgdb --pid=24010 ...command...
  ==24010== 
  ==24010== TO DEBUG THIS PROCESS USING GDB: start GDB like this
  ==24010==   /path/to/gdb ./a.out
  ==24010== and then give GDB the following command
  ==24010==   target remote | /usr/lib/valgrind/../../bin/vgdb --pid=24010
  ==24010== --pid is optional if only one valgrind process is running
  ==24010== 
  --24010-- REDIR: 0x4019ca0 (ld-linux-x86-64.so.2:strlen) redirected to 0x380764b1 (???)
  --24010-- Reading syms from /usr/lib/valgrind/vgpreload_core-amd64-linux.so
  --24010--   Considering /usr/lib/valgrind/vgpreload_core-amd64-linux.so ..
  --24010--   .. CRC mismatch (computed fc68135e wanted 45f5e986)
  --24010--    object doesn't have a symbol table
  --24010-- Reading syms from /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so
  --24010--   Considering /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so ..
  --24010--   .. CRC mismatch (computed ae683f7e wanted 08c06df2)
  --24010--    object doesn't have a symbol table
  ==24010== WARNING: new redirection conflicts with existing -- ignoring it
  --24010--     old: 0x04019ca0 (strlen              ) R-&gt; (0000.0) 0x380764b1 ???
  --24010--     new: 0x04019ca0 (strlen              ) R-&gt; (2007.0) 0x04c2e1a0 strlen
  --24010-- REDIR: 0x4019a50 (ld-linux-x86-64.so.2:index) redirected to 0x4c2dd50 (index)
  --24010-- REDIR: 0x4019c70 (ld-linux-x86-64.so.2:strcmp) redirected to 0x4c2f2f0 (strcmp)
  --24010-- REDIR: 0x401a9c0 (ld-linux-x86-64.so.2:mempcpy) redirected to 0x4c31da0 (mempcpy)
  --24010-- Reading syms from /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.19
  --24010--   Considering /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.19 ..
  --24010--   .. CRC mismatch (computed 5ce96d3c wanted bf86fabd)
  --24010--    object doesn't have a symbol table
  --24010-- Reading syms from /lib/x86_64-linux-gnu/libgcc_s.so.1
  --24010--   Considering /lib/x86_64-linux-gnu/libgcc_s.so.1 ..
  --24010--   .. CRC mismatch (computed 6116126e wanted 54e3f1f2)
  --24010--    object doesn't have a symbol table
  --24010-- Reading syms from /lib/x86_64-linux-gnu/libc-2.19.so
  --24010--   Considering /lib/x86_64-linux-gnu/libc-2.19.so ..
  --24010--   .. CRC mismatch (computed 600bae51 wanted b4d0580d)
  --24010--   Considering /usr/lib/debug/lib/x86_64-linux-gnu/libc-2.19.so ..
  --24010--   .. CRC is valid
  --24010-- Reading syms from /lib/x86_64-linux-gnu/libm-2.19.so
  --24010--   Considering /lib/x86_64-linux-gnu/libm-2.19.so ..
  --24010--   .. CRC mismatch (computed 0fbb5cf0 wanted cac31e3b)
  --24010--   Considering /usr/lib/debug/lib/x86_64-linux-gnu/libm-2.19.so ..
  --24010--   .. CRC is valid
  --24010-- REDIR: 0x53ddd60 (libc.so.6:strcasecmp) redirected to 0x4a25720 (_vgnU_ifunc_wrapper)
  --24010-- REDIR: 0x53e0050 (libc.so.6:strncasecmp) redirected to 0x4a25720 (_vgnU_ifunc_wrapper)
  --24010-- REDIR: 0x53dd530 (libc.so.6:memcpy@GLIBC_2.2.5) redirected to 0x4a25720 (_vgnU_ifunc_wrapper)
  --24010-- REDIR: 0x53db7c0 (libc.so.6:rindex) redirected to 0x4c2da30 (rindex)
  --24010-- REDIR: 0x53d9ac0 (libc.so.6:strlen) redirected to 0x4c2e0e0 (strlen)
  --24010-- REDIR: 0x53dcfa0 (libc.so.6:__GI_memcmp) redirected to 0x4c30b80 (__GI_memcmp)
  --24010-- REDIR: 0x53d8070 (libc.so.6:strcmp) redirected to 0x4a25720 (_vgnU_ifunc_wrapper)
  --24010-- REDIR: 0x53e8d20 (libc.so.6:__strcmp_sse2_unaligned) redirected to 0x4c2f1b0 (strcmp)
  --24010-- REDIR: 0x4e95ea0 (libstdc++.so.6:operator new[](unsigned long)) redirected to 0x4c2b790 (operator new[](unsigned long))
  # How many courses would you like to enter? 1
  - Please enter the name of the course: a
  --24010-- REDIR: 0x53d9500 (libc.so.6:strcpy) redirected to 0x4a25720 (_vgnU_ifunc_wrapper)
  --24010-- REDIR: 0x53edb90 (libc.so.6:__strcpy_sse2_unaligned) redirected to 0x4c2e1c0 (strcpy)
  - Please enter the number of the course: a
  - Please enter the section of the course: 
  - Please enter the time of the course: a
  - Please enter the CRN of the course: a
  - Please enter the description of the course: a
  ===============================================================
  --24010-- REDIR: 0x4e94120 (libstdc++.so.6:operator delete[](void*)) redirected to 0x4c2c7d0 (operator delete[](void*))
  ==24010== Use of uninitialised value of size 8
  ==24010==    at 0x40236F: Table::insertByName(Course&amp;) (Table.cpp:144)
  ==24010==    by 0x401DDD: Table::insert(Course&amp;) (Table.cpp:56)
  ==24010==    by 0x40144C: main (main.cpp:39)
  ==24010== 
  --24010-- REDIR: 0x4e95d90 (libstdc++.so.6:operator new(unsigned long)) redirected to 0x4c2b070 (operator new(unsigned long))
  ==24010== Use of uninitialised value of size 8
  ==24010==    at 0x4023A1: Table::insertByName(Course&amp;) (Table.cpp:145)
  ==24010==    by 0x401DDD: Table::insert(Course&amp;) (Table.cpp:56)
  ==24010==    by 0x40144C: main (main.cpp:39)
  ==24010== 
  ==24010== Use of uninitialised value of size 8
  ==24010==    at 0x4023B9: Table::insertByName(Course&amp;) (Table.cpp:146)
  ==24010==    by 0x401DDD: Table::insert(Course&amp;) (Table.cpp:56)
  ==24010==    by 0x40144C: main (main.cpp:39)
  ==24010== 
  ==24010== Use of uninitialised value of size 8
  ==24010==    at 0x4023E0: Table::insertByName(Course&amp;) (Table.cpp:147)
  ==24010==    by 0x401DDD: Table::insert(Course&amp;) (Table.cpp:56)
  ==24010==    by 0x40144C: main (main.cpp:39)
  ==24010== 
  ==24010== Use of uninitialised value of size 8
  ==24010==    at 0x4024E3: Table::insertByNumber(Course&amp;) (Table.cpp:167)
  ==24010==    by 0x401DF2: Table::insert(Course&amp;) (Table.cpp:56)
  ==24010==    by 0x40144C: main (main.cpp:39)
  ==24010== 
  ==24010== Use of uninitialised value of size 8
  ==24010==    at 0x4025A2: Table::insertByNumber(Course&amp;) (Table.cpp:174)
  ==24010==    by 0x401DF2: Table::insert(Course&amp;) (Table.cpp:56)
  ==24010==    by 0x40144C: main (main.cpp:39)
  ==24010== 
  ==24010== Use of uninitialised value of size 8
  ==24010==    at 0x4025C6: Table::insertByNumber(Course&amp;) (Table.cpp:175)
  ==24010==    by 0x401DF2: Table::insert(Course&amp;) (Table.cpp:56)
  ==24010==    by 0x40144C: main (main.cpp:39)
  ==24010== 
  --24010-- REDIR: 0x4e940f0 (libstdc++.so.6:operator delete(void*)) redirected to 0x4c2c250 (operator delete(void*))
  --24010-- REDIR: 0x53d3df0 (libc.so.6:free) redirected to 0x4c2bd80 (free)
  ==24010== 
  ==24010== HEAP SUMMARY:
  ==24010==     in use at exit: 4 bytes in 2 blocks
  ==24010==   total heap usage: 29 allocs, 27 frees, 456 bytes allocated
  ==24010== 
  ==24010== Searching for pointers to 2 not-freed blocks
  ==24010== Checked 194,168 bytes
  ==24010== 
  ==24010== LEAK SUMMARY:
  ==24010==    definitely lost: 4 bytes in 2 blocks
  ==24010==    indirectly lost: 0 bytes in 0 blocks
  ==24010==      possibly lost: 0 bytes in 0 blocks
  ==24010==    still reachable: 0 bytes in 0 blocks
  ==24010==         suppressed: 0 bytes in 0 blocks
  ==24010== Rerun with --leak-check=full to see details of leaked memory
  ==24010== 
  ==24010== Use --track-origins=yes to see where uninitialised values come from
  ==24010== ERROR SUMMARY: 7 errors from 7 contexts (suppressed: 0 from 0)
  ==24010== 
  ==24010== 1 errors in context 1 of 7:
  ==24010== Use of uninitialised value of size 8
  ==24010==    at 0x4025C6: Table::insertByNumber(Course&amp;) (Table.cpp:175)
  ==24010==    by 0x401DF2: Table::insert(Course&amp;) (Table.cpp:56)
  ==24010==    by 0x40144C: main (main.cpp:39)
  ==24010== 
  ==24010== 
  ==24010== 1 errors in context 2 of 7:
  ==24010== Use of uninitialised value of size 8
  ==24010==    at 0x4025A2: Table::insertByNumber(Course&amp;) (Table.cpp:174)
  ==24010==    by 0x401DF2: Table::insert(Course&amp;) (Table.cpp:56)
  ==24010==    by 0x40144C: main (main.cpp:39)
  ==24010== 
  ==24010== 
  ==24010== 1 errors in context 3 of 7:
  ==24010== Use of uninitialised value of size 8
  ==24010==    at 0x4024E3: Table::insertByNumber(Course&amp;) (Table.cpp:167)
  ==24010==    by 0x401DF2: Table::insert(Course&amp;) (Table.cpp:56)
  ==24010==    by 0x40144C: main (main.cpp:39)
  ==24010== 
  ==24010== 
  ==24010== 1 errors in context 4 of 7:
  ==24010== Use of uninitialised value of size 8
  ==24010==    at 0x4023E0: Table::insertByName(Course&amp;) (Table.cpp:147)
  ==24010==    by 0x401DDD: Table::insert(Course&amp;) (Table.cpp:56)
  ==24010==    by 0x40144C: main (main.cpp:39)
  ==24010== 
  ==24010== 
  ==24010== 1 errors in context 5 of 7:
  ==24010== Use of uninitialised value of size 8
  ==24010==    at 0x4023B9: Table::insertByName(Course&amp;) (Table.cpp:146)
  ==24010==    by 0x401DDD: Table::insert(Course&amp;) (Table.cpp:56)
  ==24010==    by 0x40144C: main (main.cpp:39)
  ==24010== 
  ==24010== 
  ==24010== 1 errors in context 6 of 7:
  ==24010== Use of uninitialised value of size 8
  ==24010==    at 0x4023A1: Table::insertByName(Course&amp;) (Table.cpp:145)
  ==24010==    by 0x401DDD: Table::insert(Course&amp;) (Table.cpp:56)
  ==24010==    by 0x40144C: main (main.cpp:39)
  ==24010== 
  ==24010== 
  ==24010== 1 errors in context 7 of 7:
  ==24010== Use of uninitialised value of size 8
  ==24010==    at 0x40236F: Table::insertByName(Course&amp;) (Table.cpp:144)
  ==24010==    by 0x401DDD: Table::insert(Course&amp;) (Table.cpp:56)
  ==24010==    by 0x40144C: main (main.cpp:39)
  ==24010== 
  ==24010== ERROR SUMMARY: 7 errors from 7 contexts (suppressed: 0 from 0)
  </code></pre>
  </blockquote>
  
  
  
  <p>Does anyone have an idea of what the error is about? I hope someone would "understand" the problem with this little amount of information, because I thought it would be easier since I have more than 1000 lines of code separated into different header files and .cpp files. </p>
  
  <p>Thanks</p>