简体   繁体   English

为什么我得到以下代码 AddressSanitizer: SEGV on unknown address error

[英]why am i getting for the following code AddressSanitizer: SEGV on unknown address error

'''
#include<stack>
using namespace std;
class Solution {
public:
    bool isValid(string s) {
        stack<char> mystack;
        char c;

        for(int i=0;i<= s.length();i++){


            if(s[i]=='(' || s[i]=='{' || s[i]== '[')
                mystack.push(s[i]);
            if(i!=0){
            switch (s[i]){
               case ')':
                   if(mystack.top()== '(')
                       mystack.pop();
                   else return false;
               case '}':
                   if(mystack.top()== '{')
                       mystack.pop();
                   else return false;
               case ']':
                   if (mystack.top()== '[')
                       mystack.pop();
                   else return false;

           }
            }
            if(i==s.length() && !mystack.empty())
                return false;


        } 
        return true;
    }
};'''

I dont know why but Iam getting this error AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x000000383dd4 bp 0x7ffc40c5d970 sp 0x7ffc40c5d860 T0) with hint ** address pointing to zero page** can someone please explain why iam getting this and how to resolve this.我不知道为什么但我收到此错误AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x000000383dd4 bp 0x7ffc40c5d970 sp 0x7ffc40c5d970 sp 0x7ffc40c5d860 T0)提示**地址指向零页**有人可以解释为什么我得到这个以及如何解决这个问题。 THANKS in advance!提前致谢!

This code contained so many bugs.这段代码包含很多错误。 But the cause of the error actually was that inside the if condition of switch case但错误的原因实际上是在switch case的if条件内

if( mystack.top() )

here I am accessing the top element of my stack without checking if it even exist or not hence the unknown address.在这里,我正在访问堆栈的顶部元素,而不检查它是否存在,因此是未知地址。 It should have been应该是

if( !mystack.empty() && mystack.top())

This was compiler check if the address you are looking for exist or not if it does than only it will try to access the value.这是编译器检查您正在寻找的地址是否存在,如果它存在,它只会尝试访问该值。

I asked this as a noob programmer and after months of programming I debugged this myself.我作为一个菜鸟程序员问过这个问题,经过几个月的编程,我自己调试了这个。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我在 leetcode 上收到 AddressSanitizer: heap-buffer-overflow on address 0x602000000058 错误? - Why am I getting AddressSanitizer: heap-buffer-overflow on address 0x602000000058 error on leetcode? 为什么在以下代码中没有出现错误? - Why I am not getting error in following code? AddressSanitizer: SEGV on unknown address 0x000000000000 是什么意思? - What does AddressSanitizer: SEGV on unknown address 0x000000000000 mean? 为什么在执行以下代码时出现错误? - Why i am getting error while executing with the following code? 我收到这个错误:AddressSanitizer: negative-size-param: (size=-8) - I am getting this ERROR: AddressSanitizer: negative-size-param: (size=-8) 我在以下代码中收到总线错误 - I am getting a bus error in the following code 为什么我在以下代码段中收到UMR(未初始化的内存读取)错误 - Why I am getting UMR(unInitialized Memory Read)Error in following code snippet 为什么我会收到“未知类型名称对手”错误? (代码下的详细信息) - Why am I getting a “unknown type name Opponent” error? (Details under code) 为什么我在以下代码中的每个输出后都得到 32767? - Why am I getting 32767 after each output in the following code? “==7645==ERROR: AddressSanitizer: SEGV on unknown address 0x1003fd37e049 (pc 0x55c8da2c3605 bp 0x7fffe9c30110 sp 0x7fffe9c300f0 T0)”是什么意思 - What does "==7645==ERROR: AddressSanitizer: SEGV on unknown address 0x1003fd37e049 (pc 0x55c8da2c3605 bp 0x7fffe9c30110 sp 0x7fffe9c300f0 T0)" mean
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM