Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
234 views
in Technique[技术] by (71.8m points)

c++ - Why does this error appear during compilation?(CodeWars)

Here below is the error that ocuurs after the compilation. I've been solving 5kyu task on CodeWars.I passed all test cases, but when I want to attempt, these errors pop up:

double free or corruption (out)
UndefinedBehaviorSanitizer:DEADLYSIGNAL
==1==ERROR: UndefinedBehaviorSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7f64918f2a10 bp 0x7fff85a912b0 sp 0x7fff85a91060 T1)
==1==The signal is caused by a READ memory access.
==1==Hint: address points to the zero page.
==1==WARNING: invalid path to external symbolizer!
==1==WARNING: Failed to use and restart external symbolizer!
    #0 0x7f64918f2a0f  (/lib/x86_64-linux-gnu/libc.so.6+0x40a0f)
    #1 0x7f649193b966  (/lib/x86_64-linux-gnu/libc.so.6+0x89966)
    #2 0x7f64919429d9  (/lib/x86_64-linux-gnu/libc.so.6+0x909d9)
    #3 0x7f6491949f69  (/lib/x86_64-linux-gnu/libc.so.6+0x97f69)
    #4 0x429a0a  (/workspace/test+0x429a0a)
    #5 0x426f0e  (/workspace/test+0x426f0e)
    #6 0x426a17  (/workspace/test+0x426a17)
    #7 0x42661b  (/workspace/test+0x42661b)
    #8 0x42d8e5  (/workspace/test+0x42d8e5)
    #9 0x425ccd  (/workspace/test+0x425ccd)
    #10 0x7f64918d3bf6  (/lib/x86_64-linux-gnu/libc.so.6+0x21bf6)
    #11 0x404619  (/workspace/test+0x404619)

UndefinedBehaviorSanitizer can not provide additional info.
==1==ABORTING

MY CODE IS:

#include <iostream>
#include <cstring>


using namespace std;


string interpreter(const string &code,const string &tape){
    string str_1 = ">";
    string str_2 = "<";
    string str_3 = "*";
    string str_4 = "[";
    string str_5 = "]";
    string str_6 = "0";
    string str_7 = "1";
    string copy_code;copy_code=code;
    string result;result=tape;
    int step = 0;
    for(unsigned long i=0;i<copy_code.size();++i){
        if(str_1==string(1,copy_code[i]))step++;
        if(str_2==string(1,copy_code[i]))step--;
        if(str_3==string(1,copy_code[i])){
            //flip(result[step])step=0;}
            if(result[step] == str_6[0]){
                result[step] = str_7[0];
            }else {
                result[step] = str_6[0];
            }
        }
    }
  return result;
}
question from:https://stackoverflow.com/questions/65927067/why-does-this-error-appear-during-compilationcodewars

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...