title: Segmentation Fault "in ?? ()" in GDB
body: <p>I'm writing a function to extract all of the words from a file into a char*<em>. Initially I had it simply returning char *</em> but I changed that, trying to shy away from what was said to be a bad practice.
  Here is the condensed code:</p>
  
  <pre><code>int main(int argc, char * argv[]){
      char ** searchWords;
      FILE * fp = fopen("input.txt", "r");
      getSearchWords(&amp;searchWords, fp);
  
      return 0;
  }
  
  
  void getSearchWords(char *** searchWordList, FILE * searchFile){ 
  
      int wordIndex = 0, scalar = 1;
      char ** searchList = malloc(sizeof(char*)*DEFAULT_SEARCH_LENGTH);
  
      for(int i = 0; i &lt; DEFAULT_SEARCH_LENGTH; i++)
      *(searchList + i) = malloc(sizeof(char)* MAX_SEARCH_LENGTH);
  
      while(fgets(*(searchList + wordIndex), MAX_SEARCH_LENGTH + 1, searchFile)!= NULL){
  
          if(wordIndex == (DEFAULT_SEARCH_LENGTH*scalar - 1 )){
              scalar++;
              searchList = realloc(searchList, sizeof(char *) * DEFAULT_SEARCH_LENGTH*scalar);
  
          for(int i = wordIndex+1; i &lt; DEFAULT_SEARCH_LENGTH*scalar ; i++)
              *(searchList + i) = malloc(sizeof(char) * MAX_SEARCH_LENGTH );
          }// if
  
          wordIndex++;
  
      }// while
  
      fclose(searchFile);
      printf("%d\n", wordIndex);
      for(int i = 0; i &lt; wordIndex; i++){
          *(searchWordList + i) = (searchList + i);
          printf("%s\n", **(searchWordList + i));
      }
  }
  </code></pre>
  
  <p>The segmentation fault is coming from the last for loop, but when I run gdb,this is what I get and I'm not sure why or what to do with it: </p>
  
  <pre><code>Program received signal SIGSEGV, Segmentation fault.    
  0x00000000006034c8 in ?? ()   
  (gdb) bt    
  #0  0x00000000006034c8 in ?? ()    
  #1  0x00000000006034d0 in ?? ()    
  #2  0x00000000006034d8 in ?? ()    
  #3  0x00000000006034e0 in ?? ()    
  #4  0x00000000006034e8 in ?? ()    
  #5  0x00000000006034f0 in ?? ()   
  #6  0xf9d384796456d39a in ?? ()   
  #7  0x00000000004009e0 in __ctype_b_loc@plt ()
  #8  0x00007fffffffe850 in ?? ()
  #9  0x0000000000000000 in ?? ()
  </code></pre>
  
  <p>Thanks</p>
  
  <p>EDIT:
  Forgot to mention that the input file, "input.txt" contains 15 single word, each on one line. In the for loop at the end, it prints all of them and then hits the segmentation fault. Furthermore, it will still have the segfault even if I decrease the number of iterations of the loop by 1.</p>