Hello CF community,
I encountered interesting compile error(bug?) while I was preparing contest on Hackerrank. When I run this code:
Code#include "bits/stdc++.h"
using namespace std;
vector<int>res;
void solve(int l,int r){
if(l>r)return;
res.push_back(r+1);
solve(l+1,r);
}
int main(){
solve(0,1000000);
cout<<res.size()<<endl;
}
(you can open any problem and paste it on IDE part of problem), I get this type of error log:
Error (stderr)Reading symbols from Solution...done.
[New LWP 357307]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `./Solution'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x000000000040125b in solve (l=698913, r=1000000) at Solution.cpp:6
6 res.push_back(r+1);
To enable execution of this file add
add-auto-load-safe-path /usr/local/lib64/libstdc++.so.6.0.25-gdb.py
line to your configuration file "//.gdbinit".
To completely disable this security protection add
set auto-load safe-path /
line to your configuration file "//.gdbinit".
For more information about this security protection see the
"Auto-loading safe path" section in the GDB manual. E.g., run from the shell:
info "(gdb)Auto-loading safe path"
And interesting part is that when I change "r+1" to "r" in the code, it works without problem. I do not think it stem from lack of Hackerrank's provided "stack memory". Maybe it cause because of their integrated optimizations in low level while compiling code, but I could not figure out myself. I would be happy if you share you experience if you encountered this type of problem before.
Thanks
Полный текст и комментарии »