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 8226281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:42:34+00:00 2026-06-07T15:42:34+00:00

I have a class ArbDouble, made by me, which is basically a wrapper for

  • 0

I have a class ArbDouble, made by me, which is basically a wrapper for a mpfr_t

The relevant part of the class for this problem is

class ArbDouble
{
private:
    mpfr_t value;

public:
    explicit ArbDouble(long double value_, unsigned long precision) {
        mpfr_init2(value, precision);
        mpfr_set_d(value, value_, MPFR_RNDN);
    }
    explicit ArbDouble(long int value_, unsigned long precision) {
        mpfr_init2(value, precision);
        mpfr_set_ui(value, value_, MPFR_RNDN);
    }

    ArbDouble(){
        mpfr_init(value);
    }

    ArbDouble(unsigned long precision) {
        mpfr_init2(value,precision);
    }
    ArbDouble(const ArbDouble& other) {
        mpfr_init2(value, other.getPrecision());
        mpfr_set(value, other.value, MPFR_RNDN);
    }

    ArbDouble(const mpfr_t& other) {
        mpfr_init2(value, mpfr_get_prec(other));
        mpfr_set(value, other, MPFR_RNDN);
    }

    explicit ArbDouble(char* other, unsigned long precision) {
        mpfr_init2(value, precision);
        mpfr_set_str(value, other, 10, MPFR_RNDN);
    }

    ~ArbDouble() {
        mpfr_clear(value);
    }

    inline unsigned long getPrecision() const
    {
        return mpfr_get_prec(value);
    }
    inline ArbDouble& operator=(const ArbDouble &other)
    {
        mpfr_set_prec(value, other.getPrecision());
        mpfr_set(value, other.value, MPFR_RNDN);
        return *this;
    }
}

Now, I’m using std::vector to store a matrix of these values e.g.

std::vector<ArbDouble> temp;
temp.push_back(ArbDouble((long int)0,64)); // calling "ArbDouble(long int value_, unsigned long precision)"

std::vector<std::vector<ArbDouble> > currentOrbit;
currentOrbit.push_back(temp);

and this causes a segfault on a linux machine, but not on a mac machine.

The error given by gdb is:

Program received signal SIGSEGV, Segmentation fault.
0x00000000004069fe in std::vector<std::vector<ArbDouble, std::allocator<ArbDouble> >, std::allocator<std::vector<ArbDouble, std::allocator<ArbDouble> > > >::push_back (this=0xb5daafcc938b13f6, __x=std::vector of length 1, capacity 1 = {...})
    at /usr/include/c++/4.5/bits/stl_vector.h:743
743     if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)

Does anyone knows where the problem can be? I’m not a very good class designer, so, my guess is that somewhere it has a flaw. Any suggestions to it are very welcome!!!

  • 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-07T15:42:35+00:00Added an answer on June 7, 2026 at 3:42 pm

    This is a typical case of heap/stack corruption. You probably have an array somewhere that you are writing to, but out of its boundaries. Doing so, you are changing variables of random nearby objects (in this case the vector) and hence the strange errors on internals of some other library (in this case std).

    Since all your class does is call this mpfr_ set of functions, most probably the error is there (unless there is some other code that you are not showing). You could try debugging and finding out the problem in any way you like, but perhaps the easiest solution would be to use valgrind:

    valgrind --leak-check=full ./your_program --args --to --your program
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have class with back reference: public class Employee : Entity { private string
I have class with collection as below public class MyClass:IXmlSerializable { int vesrion; private
I have class like this below shown. which contains the shopping items where the
I have class that looks like this: class A { public: class variables_map vm
I have class which implements Countable, ArrayAccess, Iterator and Serializable. I have a public
I have class like public class ProgressBars { public ProgressBars() { } private Int32
I have class Person: public class Person : INotifyPropertyChanged { private String name =
I have class A and B which inherit from Base. Base has a private
I have: class first{ private: int *array; public: first(int x){ array = new int[x][10];
I have class where the relevant part looks like class C { void Method<T>(SomeClass<T>

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.