lundi 13 juin 2016

Memory Error: Segmentation fault (core dumped) error


I am trying to run some code which calls a function as seen below:

void Memreuse::InitializeElements(unsigned long size, pairing_t * pairing)
{
  m_pairing = pairing;

  for (unsigned long i = 0; i < size; i++)
    {
      element_t * a = (element_t * ) malloc(sizeof(element_t) * 1);
      element_init_G1(*a, *m_pairing);
      m_qG1Element.push(a);

      element_t * b = (element_t * ) malloc(sizeof(element_t) * 1);
      element_init_G2(*b, *m_pairing);
      m_qG2Element.push(b);

      element_t * c = (element_t * ) malloc(sizeof(element_t) * 1);
      element_init_GT(*c, *m_pairing);
      m_qGTElement.push(c);

      element_t * r = (element_t * ) malloc(sizeof(element_t) * 1);
      element_init_Zr(*r, *m_pairing);
      m_qZrElement.push(r);
    }
}

The part in the main code that calls this function looks like this:

g_pairing = (pairing_t *) malloc(sizeof(pairing_t));
Memreuse::InitializeElements(1000, g_pairing);

I keep getting the error "Segmentation fault (core dumped) error". I've searched it online and read that it has to do with memory allocation and there is not a specific reason why this error could could arise. I thought I'd post the function which causes the problem. Maybe someone could notice a mistake in the code that is causing this error.


Aucun commentaire:

Enregistrer un commentaire