简体   繁体   English

“==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

I am solving a problem where i have to perform a DFS.我正在解决一个我必须执行 DFS 的问题。 Everything works perfectly fine until i test my code with large entries.一切正常,直到我用大条目测试我的代码。 When i test it with large entries i get this error.当我用大条目测试它时,我得到了这个错误。

AddressSanitizer:DEADLYSIGNAL
=================================================================
==7645==ERROR: AddressSanitizer: SEGV on unknown address 0x1003fd37e049 (pc 0x55c8da2c3605 bp 0x7fffe9c30110 sp 0x7fffe9c300f0 T0)
==7645==The signal is caused by a READ memory access.
    #0 0x55c8da2c3604 in std::__cxx1998::vector<int, std::allocator<int> >::size() const /usr/include/c++/9/bits/stl_vector.h:916
    #1 0x55c8da2c2a0e in std::__debug::vector<int, std::allocator<int> >::push_back(int const&) /usr/include/c++/9/debug/vector:476
    #2 0x55c8da2babce in add_edge(std::__debug::vector<int, std::allocator<int> >*, int, int) /home/my_name/Documents/Competitive Programming/C++/c.cpp:10
    #3 0x55c8da2bd9ef in main /home/my_name/Documents/Competitive Programming/C++/c.cpp:110
    #4 0x7ff3b36b70b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
    #5 0x55c8da2ba90d in _start (/home/my_name/Documents/Competitive Programming/C++/c+0x3390d)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /usr/include/c++/9/bits/stl_vector.h:916 in std::__cxx1998::vector<int, std::allocator<int> >::size() const
==7645==ABORTING

I don't know what this error mean.我不知道这个错误是什么意思。 Here is my code:这是我的代码:


#include <bits/stdc++.h>
#include <map>
using namespace std;


void add_edge(vector<int> adj[], int src, int dest)
{
    adj[src].push_back(dest);
    adj[dest].push_back(src);
}

bool BFS(vector<int> adj[], int src, int dest, int v,
        int pred[], int dist[])
{
    if (dest >= v || dest < 0 || src >= v || src < 0){
    return false;}
    list<int> queue;

    bool visited[v];

    
    for (int i = 0; i < v; i++) {
        visited[i] = false;
        dist[i] = INT_MAX;
        pred[i] = -1;
    }


    visited[src] = true;
    dist[src] = 0;
    queue.push_back(src);
    
    if (src == dest){
        return true;
    }


    while (!queue.empty()) {
        
        int u = queue.front();
        queue.pop_front();
        for (int i = 0; i < (int)adj[u].size(); i++) {
            if (visited[adj[u][i]] == false) {
                visited[adj[u][i]] = true;
                dist[adj[u][i]] = dist[u] + 1;
                pred[adj[u][i]] = u;
                queue.push_back(adj[u][i]);

                if (adj[u][i] == dest)
                    return true;
            }
        }
    }

    return false;
}


void printShortestDistance(vector<int> adj[], int s,
                        int dest, int v, map<int,int> sign)
{
    int pred[v], dist[v];

    if (BFS(adj, s, dest, v, pred, dist) == false) {
        cout << "IMPOSSIBLE" << endl;
        return;
    }

    vector<int> path;
    int crawl = dest;
    path.push_back(crawl);
    while (pred[crawl] != -1) {
        path.push_back(pred[crawl]);
        crawl = pred[crawl];
    }

    long long int prod = 1;

    for (int i = path.size() - 1; i >= 0; i--){
        prod=(prod*sign[path[i]])%1671404011 ;
    }
    cout << prod << endl;
}

int main()
{

    int n; ///< nombre de puces
    std::cin >> n;
    int m; ///< nombre de fils
    std::cin >> m;
    int r; ///< nombre de questions
    std::cin >> r;


    vector<int> adj[n];
    map<int,int> sign;
    map<int,pair<int,int>> quest;
    
    int a,b;
    
    for (int i = 0;i<n;i++){
        cin >> a;
        sign[i]=a;
    }
    for (int i = 0;i<m;i++){
        cin >> a >> b;
        add_edge(adj, a ,b);
    }
    for (int i = 0;i<r;i++){
        cin >> a >> b;
        quest[i]={a,b};
    }
    
    for (int i = 0;i<r;i++){
        printShortestDistance(adj,quest[i].first,quest[i].second,n,sign);
    }
    
    return 0;
}

Maybe my data structures like vectors or maps are full ^^ If anyone find where is the problem:)也许我的向量或地图等数据结构已满^^如果有人发现问题出在哪里:)

i recommend you to turn your compiler warnings on, passing -Wall -Wextra -Wpedantic as arguments when compiling the code should be a good start.我建议您打开编译器警告,在编译代码时将-Wall -Wextra -Wpedantic作为 arguments 传递应该是一个好的开始。

here's your code annotated with errors that might be causing the code to read unallocated memory:这是带有错误注释的代码,这些错误可能导致代码读取未分配的 memory:

// don't do this, this is not guaranteed to work in every compiler and
// will bring a lot of unused code to your file, slowing down your build
/*you are only using these headers:
#include <vector>
#include <iostream>
#include <list>
#include <climits>
#include <cstddef>
*/
#include <bits/stdc++.h>

#include <map>

// don't do this, it's only gonna cause obscure warning messages in the future.
// if you must, only import what you actually use like:
// using std::vector;
using namespace std;

// it seems you expecting to receive an array of vectors here
// but you are actually receiving an pointer to a vector
// this pointer 'might' point to an array of vector, but even then
// the length of this array is unknown
// i recommend you refactor your code to use vector<vector<int>>& instead
// also recommend changing src and dest to type size_t since that's the appropriate
// type that can represent all possible indexes of the array
void add_edge(vector<int> adj[], int src, int dest)
{
    adj[src].push_back(dest);
    adj[dest].push_back(src);
}
// same as above
bool BFS(vector<int> adj[], int src, int dest, int v,
        int pred[], int dist[])
{
    if (dest >= v || dest < 0 || src >= v || src < 0){
    return false;}
    list<int> queue;
// warning: variable length arrays are a C99 feature [-Wvla-extension]
// use a vector instead
    bool visited[v];

    
    for (int i = 0; i < v; i++) {
        visited[i] = false;
        dist[i] = INT_MAX;
        pred[i] = -1;
    }


    visited[src] = true;
    dist[src] = 0;
    queue.push_back(src);
    
    if (src == dest){
        return true;
    }


    while (!queue.empty()) {
        
        int u = queue.front();
        queue.pop_front();
        // warning: use of old-style cast [-Wold-style-cast]
        // don't do the cast, give the appropriate type to i (size_t)
        for (int i = 0; i < (int)adj[u].size(); i++) {  
            if (visited[adj[u][i]] == false) {
                // a lot of conversion warnings here, will problably get fixed after change to vector<vector<int>> and size_t
                // example of the warning
                // warning: implicit conversion changes signedness: 'int' to 'std::vector::size_type' (aka 'unsigned long') [-Wsign-conversion]
                visited[adj[u][i]] = true;
                dist[adj[u][i]] = dist[u] + 1;
                pred[adj[u][i]] = u;
                queue.push_back(adj[u][i]);

                if (adj[u][i] == dest)
                    return true;
            }
        }
    }

    return false;
}

// use vector<vector<int>>& instead
// use size_t for indexes
// use map<int,int>& to avoid copying the map
void printShortestDistance(vector<int> adj[], int s,
                        int dest, int v, map<int,int> sign)
{
    //warning: variable length arrays are a C99 feature [-Wvla-extension]
    // use vector instead
    int pred[v], dist[v];

    if (BFS(adj, s, dest, v, pred, dist) == false) {
        cout << "IMPOSSIBLE" << endl;
        return;
    }

    vector<int> path;
// use size_t here;
    int crawl = dest;
    path.push_back(crawl);
    while (pred[crawl] != -1) {
        path.push_back(pred[crawl]);
        crawl = pred[crawl];
    }

    // use size_t instead
    long long int prod = 1;
    // use size_t i = path.size() -1
    for (int i = path.size() - 1; i >= 0; i--){
        // what does the big number mean? give it a name.
        prod=(prod*sign[path[i]])%1671404011 ;
    }
    cout << prod << endl;
}

int main()
{

    int n; ///< nombre de puces
    std::cin >> n;
    int m; ///< nombre de fils
    std::cin >> m;
    int r; ///< nombre de questions
    std::cin >> r;

//warning: variable length arrays are a C99 feature [-Wvla-extension]
//use vector<vector<int>> instead
    vector<int> adj[n];
    map<int,int> sign;
    map<int,pair<int,int>> quest;
    
    int a,b;
    
    for (int i = 0;i<n;i++){
        cin >> a;
        sign[i]=a;
    }
    for (int i = 0;i<m;i++){
        cin >> a >> b;
        add_edge(adj, a ,b);
    }
    for (int i = 0;i<r;i++){
        cin >> a >> b;
        quest[i]={a,b};
    }
    
    for (int i = 0;i<r;i++){
        printShortestDistance(adj,quest[i].first,quest[i].second,n,sign);
    }
    
    return 0;
}

暂无
暂无

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

相关问题 AddressSanitizer:堆缓冲区溢出在地址 0x6020000000b4 在 pc 0x0000003a86fc bp 0x7ffeebd5f9d0 sp 0x7ffeebd5f9c8 - AddressSanitizer: heap-buffer-overflow on address 0x6020000000b4 at pc 0x0000003a86fc bp 0x7ffeebd5f9d0 sp 0x7ffeebd5f9c8 AddressSanitizer: SEGV on unknown address 0x000000000000 是什么意思? - What does AddressSanitizer: SEGV on unknown address 0x000000000000 mean? 错误:AddressSanitizer:地址 0x6020000001d4 在 pc 0x0000003a3e3e bp 0x7fffdafb66c0 sp 0x7fffdafb66b8 上的堆缓冲区溢出 - ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6020000001d4 at pc 0x0000003a3e3e bp 0x7fffdafb66c0 sp 0x7fffdafb66b8 错误:AddressSanitizer:地址 X 上的堆缓冲区溢出 pc Y bp Z sp W - ERROR: AddressSanitizer: heap-buffer-overflow on address X at pc Y bp Z sp W e等于C中的幂x - e to the power x in C 对于此C ++错误,“ permute_append.cpp :(。text + 0x0)”中的“(.text + 0x0)”是什么意思? - What does the “(.text+0x0)” in “permute_append.cpp:(.text+0x0)” mean for this C++ error? 在堆上写文本 - 这是什么意思? x[计数++] = c; - Writing text on heap - what does this mean? x[count++] = c; C++ 中的 while(x--) 是什么意思 - What does while(x--) mean in C++ C++ 中的“using namespace::X”中的前导 :: 是什么意思 - What does a leading :: mean in “using namespace ::X” in C++ 在C ++中,“ x(y)= z(w)”是什么意思? - What does “x(y) = z(w)” mean in C++?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM