Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9226645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:52:49+00:00 2026-06-18T04:52:49+00:00

I wrote a program and I’m quite amused by the fact that I’d run

  • 0

I wrote a program and I’m quite amused by the fact that I’d run it dozens of times — I’ve even wrote down results from multiple executions –, and now it does not work.

You might think I’m high as a kite to say so, or that I might have simply changed some lines, but I really do not recall doing any alterations whatsoever on the program.

The problem is a SIGFPE, that raises up in different executions of the program, according to the input. Happens though the signal is raised while inserting a value in an std::unordered_set<Point<T> *>.

Here is a snippet of the code where I do such insertion:

std::vector<Point<T> *> _point, _centroid;
std::vector<std::unordered_set<Point<T> *> > _cluster;

// Main procedure -- pseudocode
for (point in _point) {
    cluster_id = centroid_with_min_distance(point, _centroid);
    has_changed = _change_cluster(point, cluster_id);
}

// Changes from one "point->_cluster's unordered_set" to "c's unordered_set"
bool _change_cluster(Point<T> *point, const unsigned int& c) {

    if ((point->_cluster == c) &&
        (_cluster[c].find(point) != _cluster[c].end())) {
        return false;
    }

    _cluster[point->_cluster].erase(point);
    _cluster[c].insert(point); // Insertion that raises the SIGFPE exception
    point->_cluster = c;
    return true;

}

Here is a considered-important section of valgrind’s output:

==17636== Invalid read of size 8
==17636==    at 0x40A758: std::pair<std::__detail::_Hashtable_iterator<
                Point<unsigned int>*, true, false>, bool>
                std::_Hashtable<Point<unsigned int>*, Point<unsigned int>*,
                std::allocator<Point<unsigned int>*>,
                std::_Identity<Point<unsigned int>*>,
                std::equal_to<Point<unsigned int>*>,
                std::hash<Point<unsigned int>*>,
                std::__detail::_Mod_range_hashing,
                std::__detail::_Default_ranged_hash,
                std::__detail::_Prime_rehash_policy, false, true, true>::
                    _M_insert<Point<unsigned int>* const&>(
                        Point<unsigned int>* const&&&,
                        std::integral_constant<bool, true>) (hashtable.h:966)
==17636==    by 0x408EDA: std::_Hashtable<Point<unsigned int>*,
                 Point<unsigned int>*, std::allocator<Point<unsigned int>*>,
                 std::_Identity<Point<unsigned int>*>,
                 std::equal_to<Point<unsigned int>*>,
                 std::hash<Point<unsigned int>*>,
                 std::__detail::_Mod_range_hashing,
                 std::__detail::_Default_ranged_hash,
                 std::__detail::_Prime_rehash_policy, false, true, true>::
                     insert(Point<unsigned int>* const&) (hashtable.h:400)
==17636==  ... (calls from my program) ...
==17636==  Address 0x620a028 is not stack'd, malloc'd or (recently) free'd
==17636== 
==17636== 
==17636== Process terminating with default action of signal 8 (SIGFPE)
==17636==  Integer divide by zero at address 0x402D07D7C
==17636==    at 0x40252F: std::__detail::_Mod_range_hashing::operator()(
                 unsigned long, unsigned long) const (hashtable_policy.h:376)
==17636==    by 0x40A66C: std::__detail::_Hash_code_base<Point<unsigned int>*,
                 Point<unsigned int>*, std::_Identity<Point<unsigned int>*>,
                 std::equal_to<Point<unsigned int>*>,
                 std::hash<Point<unsigned int>*>,
                 std::__detail::_Mod_range_hashing,
                 std::__detail::_Default_ranged_hash, false>::_M_bucket_index(
                     Point<unsigned int>* const&, unsigned long,
                     unsigned long) const (hashtable_policy.h:758)
==17636==    by 0x40A772: std::pair<std::__detail::_Hashtable_iterator<
                 Point<unsigned int>*, true, false>, bool>
                 std::_Hashtable<Point<unsigned int>*, Point<unsigned int>*,
                 std::allocator<Point<unsigned int>*>,
                 std::_Identity<Point<unsigned int>*>,
                 std::equal_to<Point<unsigned int>*>,
                 std::hash<Point<unsigned int>*>,
                 std::__detail::_Mod_range_hashing,
                 std::__detail::_Default_ranged_hash,
                 std::__detail::_Prime_rehash_policy, false, true, true>::
                     _M_insert<Point<unsigned int>* const&>(
                     Point<unsigned int>* const&&&,
                     std::integral_constant<bool, true>) (hashtable.h:966)
==17636==    by 0x408EDA: std::_Hashtable<Point<unsigned int>*,
                 Point<unsigned int>*, std::allocator<Point<unsigned int>*>,
                 std::_Identity<Point<unsigned int>*>,
                 std::equal_to<Point<unsigned int>*>,
                 std::hash<Point<unsigned int>*>,
                 std::__detail::_Mod_range_hashing,
                 std::__detail::_Default_ranged_hash,
                 std::__detail::_Prime_rehash_policy, false, true, true>::
                     insert(Point<unsigned int>* const&) (hashtable.h:400)
==17636==    ... (calls from my program) ...

The question here is: as I have calculations in my program that may result in divisions by zero — they are not directly related to this process, though –, is it possible that the bug is being shadowed by the insertion? Or should I do some extra treatment while inserting pointers in an std::unordered_set<T>?

I’m compiling the program under x86_64 GNU/Linux, and I’m using g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T04:52:50+00:00Added an answer on June 18, 2026 at 4:52 am

    I suspect that ‘c’ is out of the range of _cluster. Can you replace all of the _cluster[c] with _cluster.at(c), and see if it finds an out of range error.

    The valgrind output indicates that it’s an invalid read followed by an integer modulus error. Since it’s doing hash_code % bucket_count, I suspect that you accessed out of the range of the vector.

    As an aside, naming things that start with _ can be risky, as if it’s in the global namespace, it is technically reserved for the implementation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a program called Hello.py that looks like this: import pygame, sys from
I wrote a program in C that waits for an event, and then run
I wrote a program that captures Ethernet packets from some NIC (i.e eth0) at
I wrote a program which includes writing and reading from database. When I run
I wrote a program for downloading an image from web using AsyncTask in service
I wrote this program: #include <stdio.h> /*Part B Write a program that: defines an
I wrote a program that forks some processes with fork(). I want to kill
I wrote a program that accepts and outputs Hebrew (i.e. right-to-left) text. In lieu
I wrote program to control iTunes by monitoring keystrokes from with pyHooks and then
I wrote a program that uses OLE and it was working fine until I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.