title: Floating point error when accessing std::unordered_map in array of structs
body: <p>My code generates a C array of structs wherein a member of the struct is an STL std::unordered_map:</p>
  
  <pre><code>typedef struct test_s {
     int count_a;
     std::unordered_map&lt;std::string, int&gt; my_map;
  } test_map;
  
  typedef struct cm_example {
     int width;
     test_map *counts;
     unsigned int hasha, hashb;
  } cm_sketch;
  </code></pre>
  
  <p>However when I try access the map to perform find, insert etc. I always encounter a Floating Point Exception:</p>
  
  <pre><code>Compile:  g++ -std=c++11 -g test_struct.cpp -o h_str
  Run:  ./h_str_str agggcctttgagag 100
  
  Output: 
  Kmer name: agggcctttgagag
  hash_a: 172110908 , hash_b: 1954003865, bucket: 92 
  Floating point exception
  </code></pre>
  
  <p>My code is as follows:</p>
  
  <pre><code>cm_sketch *cm_init (int width, int seed)
  {
      cm_sketch *cm;
      int i=0;
  
      cm = (cm_sketch *) malloc(sizeof(cm_sketch));
      cm-&gt;width = width;
  
      cm-&gt;counts = (test_map *) malloc (sizeof(test_map) * width);
      for (i=0; i&lt;width; i++) {
           cm-&gt;counts[i].count_a = 0;
      }
  
      cm-&gt;hasha = 172110908;
      cm-&gt;hashb = 1954003865;
  
      return cm;
   }
  
   int main(int argc, char *argv[])
   {
      int bucket_id=0;
      if (argc &lt; 2)
      {
              printf ("Please provide correct number of input arguments: \n");
              printf ("./exe 1:k-mer 2:w\n");
              exit (0);
      }
  
      char *kmer_input = argv[1];
      int width = atoi(argv[2]);
  
      std::string kmer_name = kmer_input;
      std::cout &lt;&lt; "Kmer name: " &lt;&lt; kmer_name;
      printf("\n");
  
      cm_sketch *cm = cm_init(width, time(NULL));
  
      unsigned int hashval = hash_str(kmer_input);
      bucket_id = hash31(cm-&gt;hasha, cm-&gt;hashb, hashval) % cm-&gt;width;
  
      std::unordered_map&lt;std::string, int&gt;::const_iterator got;
      printf ("hash_a: %d , hash_b: %d, bucket: %d \n", cm-&gt;hasha, cm-&gt;hashb, bucket_id);
  
      got = cm-&gt;counts[bucket_id].my_map.find(kmer_name); /* FLOATING POINT ERROR */
  
      if (got == cm-&gt;counts[bucket_id].my_map.end())
          cm-&gt;counts[bucket_id].my_map[kmer_name] = 1;
      else
          cm-&gt;counts[bucket_id].my_map[kmer_name]++;
  
     // Iterate and print keys and values of unordered_map
     for( const auto&amp; n : cm-&gt;counts[bucket_id].my_map ) {
          std::cout &lt;&lt; "Key:[" &lt;&lt; n.first &lt;&lt; "] Value:[" &lt;&lt; n.second &lt;&lt; "]\n";
     }
  
     return 0;
   }
  </code></pre>
  
  <p>Floating point errors are likely the cause of "division by zero". However here the error is internal. Running in gdb gave the following:</p>
  
  <pre><code>Program received signal SIGFPE, Arithmetic exception.
  0x00000000004018f1 in std::__detail::_Mod_range_hashing::operator()    (this=0x607768, __num=10758833940372818866, __den=0)
  at /opt/gcc/4.9.3/snos/include/g++/bits/hashtable_policy.h:449
  449     { return __num % __den; }
  (gdb) bt
  #0  0x00000000004018f1 in std::__detail::_Mod_range_hashing::operator() (this=0x607768, __num=10758833940372818866, __den=0)
  at /opt/gcc/4.9.3/snos/include/g++/bits/hashtable_policy.h:449
  #1  0x00000000004021cc in std::__detail::_Hash_code_base&lt;std::string, std::pair&lt;std::string const, int&gt;, std::__detail::_Select1st, std::hash&lt;std::string&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true&gt;::_M_bucket_index (this=0x607768, 
  __c=10758833940372818866, __n=0) at /opt/gcc/4.9.3/snos/include/g++/bits/hashtable_policy.h:1266
  #2  0x0000000000401d68 in std::_Hashtable&lt;std::string, std::pair&lt;std::string const, int&gt;, std::allocator&lt;std::pair&lt;std::string const, int&gt; &gt;, std::__detail::_Select1st, std::equal_to&lt;std::string&gt;, std::hash&lt;std::string&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits&lt;true, false, true&gt; &gt;::_M_bucket_index (this=0x607768, __k=..., 
  __c=10758833940372818866) at /opt/gcc/4.9.3/snos/include/g++/bits/hashtable.h:614
  #3  0x0000000000401ac6 in std::_Hashtable&lt;std::string, std::pair&lt;std::string const, int&gt;, std::allocator&lt;std::pair&lt;std::string const, int&gt; &gt;, std::__detail::_Select1st, std::equal_to&lt;std::string&gt;, std::hash&lt;std::string&gt;, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits&lt;true, false, true&gt; &gt;::find (this=0x607768, __k=...)
  at /opt/gcc/4.9.3/snos/include/g++/bits/hashtable.h:1303
  #4  0x0000000000401969 in std::unordered_map&lt;std::string, int, std::hash&lt;std::string&gt;, std::equal_to&lt;std::string&gt;, std::allocator&lt;std::pair&lt;std::string const, int&gt; &gt; &gt;::find (this=0x607768, __x=...) at /opt/gcc/4.9.3/snos/include/g++/bits/unordered_map.h:574
  #5  0x00000000004015cb in main (argc=3, argv=0x7fffffff7618) at test_struct.cpp:100
  </code></pre>
  
  <p>I am not very familiar with C++, and I have been struggling with this piece of code for a long time. Please help isolate the error. Am I missing something? Am I not accessing the hash_map entries correctly?</p>