Hi, I’ve come back to the article ᕕ (ᐛ) ᕗ
recently, I’m brushing leetcode, and there’s an error report about stack
AddressSanitizer:DEADLYSIGNAL
=================================================================
==42==ERROR: AddressSanitizer: SEGV on unknown address 0x55eb765425b8 (pc 0x55eb76542b86 bp 0x7ffd1bd27d50 sp 0x7ffd1bd27d00 T0)
==42==The signal is caused by a WRITE memory access.
#2 0x7fe2bd0fe0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
AddressSanitizer can not provide additional info.
==42==ABORTING
My code is as follows
bool isValid(char * s){
bool answer;
int i=0;
char tem;
stack S=creatstack; //Something is wrong here, it should be a function but I forgot to add the brackets
while(s[i]!='\0'){
if(s[i]=='('||s[i]=='['||s[i]=='{') push(s[i],S);
else{
tem=pop(S);
if((tem=='('&&s[i]==')')||(tem=='['&&s[i]==']')||(tem=='{'&&s[i]=='}')) ;
else return false;
}
i++;
}
return true;
}
Change to
stack S=creatstack();
After that, the problem was solved