my solution shows runtime error(sigsegv) even though it works perfectly fine with custom input.
Which solution? Which Problem? Please link to your submission.
Edit:
If you’re referring to this solution, there’s an obvious out-of-bounds access:
int cops_cover[400];
for(int i=0;i<1000;i++){
cops_cover[i]=0;
}
1 Like
I am referring to the same question but when i corrected this part, then also i was facing this problem. I couldn’t figure out why?
I have corrected it, but it still shows the same error.
Solution: CodeChef: Practical coding for everyone
[simon@simon-laptop][10:56:52]
[~/devel/hackerrank/otherpeoples]>./compile-latest-cpp.sh
Compiling manasvvi1-COPS.cpp
+ g++ -std=c++14 manasvvi1-COPS.cpp -O3 -g3 -Wall -Wextra -Wconversion -DONLINE_JUDGE -D_GLIBCXX_DEBUG -fsanitize=undefined -ftrapv
+ set +x
Successful
[simon@simon-laptop][10:57:03]
[~/devel/hackerrank/otherpeoples]>cat failed_test_case.txt
1
10 5 7
71 39 3 26 69 4 100 20 32 16
[simon@simon-laptop][10:57:05]
[~/devel/hackerrank/otherpeoples]>cat failed_test_case.txt | ./a.out
manasvvi1-COPS.cpp:29:30: runtime error: index 400 out of bounds for type 'int [400]'
manasvvi1-COPS.cpp:29:31: runtime error: store to address 0x7ffedfacf760 with insufficient space for an object of type 'int'
0x7ffedfacf760: note: pointer points here
74 00 00 00 01 00 00 00 00 00 00 00 00 39 8b 59 ef dc 28 4b 40 db c7 c7 b7 7f 00 00 00 00 00 00
^
manasvvi1-COPS.cpp:36:30: runtime error: index 419 out of bounds for type 'int [400]'
manasvvi1-COPS.cpp:36:31: runtime error: store to address 0x7ffedfacf7ac with insufficient space for an object of type 'int'
0x7ffedfacf7ac: note: pointer points here
87 00 00 00 b7 7f 00 00 00 00 00 00 00 00 00 00 88 f8 ac df fe 7f 00 00 c0 7f bd c6 01 00 00 00
^
manasvvi1-COPS.cpp:47:28: runtime error: index 400 out of bounds for type 'int [400]'
manasvvi1-COPS.cpp:47:28: runtime error: load of address 0x7ffedfacf760 with insufficient space for an object of type 'int'
0x7ffedfacf760: note: pointer points here
74 00 00 00 75 00 00 00 76 00 00 00 77 00 00 00 78 00 00 00 79 00 00 00 7a 00 00 00 7b 00 00 00
^
0
*** stack smashing detected ***: <unknown> terminated
Aborted (core dumped)
Can u explain this please? I couldn’t understand!
With the testcase:
1
10 5 7
71 39 3 26 69 4 100 20 32 16
you’re still getting out-of-bounds accesses on the line numbers 29, 36 and 28.