-1

Well, this is the problem: i was trying to compile my altoin in ARM and i get stack smashing error: . Aborted. then, i try to compile exactly the same code but with SSE2 flags in my other linux computer, and it success. if i disable stack protection on the makefile im able to compile. But isnt good idea disable that. I try use older GCC, but nothing, is the same. my question is, why im able to compile in SSE2 instructions but no in ARM? This is the code that create a warning on the build logs:

double GaussianQuad_N(double func(const double), const double a2, const double b2, int NptGQ)
{
    double s = 0.0;
    double x[NptGQ], w[NptGQ];

    gauleg(a2, b2, x, w, NptGQ);
    for (int j = 1 ; j <= NptGQ ; j++)
        s += w[j] * func(x[j]);

    return s;
}

i get:

warning: stack protector not protecting local variables: variable length buffer [-Wstack-protecto ] double GaussianQuad_N(double func(const double)

  • 1
    `double x[NptGQ], w[NptGQ];` variable length arrays are not standard in C++. – 273K Feb 12 '21 at 17:47
  • but why the error is in the definition of the function? any idea how to translate them to standard? –  Feb 12 '21 at 17:49
  • "i was trying to compile my altoin in ARM" - What *is* an "altoin?" – AJM Nov 04 '22 at 17:15

2 Answers2

0

double x[NptGQ], w[NptGQ]; variable length arrays are not standard in C++. Use std:: vector in C++

std::vector<double> x(NptGQ), w(NptGQ);
gauleg(a2, b2, x.data(), w.data(), NptGQ);
273K
  • 29,503
  • 10
  • 41
  • 64
  • i go to try this in a second, but why it compiles with no problems in SSE2 instruction set? –  Feb 12 '21 at 17:50
  • Because Intel and ARM are different CPU architectures. – 273K Feb 12 '21 at 17:54
  • ok, im compiling, is a 20000+ lines project, so, in few minutes i aprove your answere or i tell u what happend, thanks for the help –  Feb 12 '21 at 18:04
  • now i get this error: munmap_chunk(): invalid pointer –  Feb 12 '21 at 18:25
  • 20000+ lines is a small project, should not take a while for building. – 273K Feb 12 '21 at 18:25
  • othe small point, a project thet uses this same function compiles ok in my ARM what can be the problem? i ran out of ideas –  Feb 12 '21 at 18:28
0

Your arrays have NptGQ as the size, which means the valid indexes are 0 up to NptGQ-1. However, your loop goes from 1 up to NptGQ, so the last iteration will be beyond the end of the array.

Running off the end of an array like this causes undefined behavior -- it may work (if nothing important is in the space after the array) or it may crash or otherwise misbehave.

Chris Dodd
  • 119,907
  • 13
  • 134
  • 226
  • ok, i go to try this, but why it works on SSE2 instruction set and not in ARM? –  Feb 12 '21 at 21:15
  • Perhaps with SSE2, there's extra padding involved and the out of range access only hits that padding and not anything important. – Chris Dodd Feb 12 '21 at 21:17
  • ooooooh man, if this works, you saved my life, i go to try expand by one the pad –  Feb 12 '21 at 21:29
  • nah, sadly it not work, i do: for (int j = 1 ; j <= NptGQ - 1 ; j++) but i get : munmap_chunk(): invalid pointer –  Feb 12 '21 at 23:33