当我尝试运行代码时出现AddressSanitizer错误

时间:2020-10-08 08:19:12

标签: c++ arrays data-structures

这是一个leet代码问题,我正在尝试解决https://leetcode.com/problems/container-with-most-water/ 下面是在我的ide上运行的代码,但我无法运行此代码。那里显示AddressSanitizer错误。请帮助我解决此问题

    class Solution 
{
  public:
    int maxArea(vector<int>& height) 
    {
        int n=height.size(),product=1;
        int i=0,j=n-1;
        while(i<j)
        {
            int x=(height[i]<height[j])?height[i]:height[j];
            int y=j-i;
            int p=x*y;
            if(product<p)
                product=p;
            while(height[i]<=height[j])
                i++;
            while(height[i]>height[j])
                j--;
        }
        return product;
    }
};

================================================ ================== == 31 ==错误:AddressSanitizer:PC 0x0000003760a2 bp上地址0x606000000060的堆缓冲区溢出0x7ffc947d7160 sp 0x7ffc947d7158在0x606000000060线程T0读取大小4 #3 0x7f4235b5f0b2(/lib/x86_64-linux-gnu/libc.so.6+0x270b2)0x606000000060位于64字节区域右侧的0字节 [0x606000000020,0x606000000060)在这里由线程T0分配: #10 0x7f4235b5f0b2(/lib/x86_64-linux-gnu/libc.so.6+0x270b2)越野车地址周围的影子字节:0x0c0c7fff7fb0:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c0c7fff7fc0:0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c0c7fff7fd0:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c0c7fff7fe0:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c0c7fff7ff0:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 => 0x0c0c7fff8000:fa fa fa 00 00 00 00 00 00 00 00 [fa] fa fa fa 0x0c0c7fff8010:fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c0c7fff8020:fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c0c7fff8030:fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c0c7fff8040:fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c0c7fff8050:fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa

0 个答案:

没有答案