分段故障-大小为8的读取无效
Segmentation Fault - Invalid read of size 8
由于某些原因,以下C++代码导致分段错误:
#include <sstream>
#include <vector>
using namespace std;
string charToString(char c)
{
stringstream ss;
string s;
ss << c;
ss >> s;
return s;
}
int main()
{
vector<string> stringTable;
for(int c = 0; c < 256; ++c){
string s = charToString(c);
stringTable[c] = s;
}
}
Valgrind在线上报告错误Invalid read of size 8
stringTable[c] = s;
但我看不出这行有什么毛病。那么这个代码出了什么问题?
您正在注销vector
的末尾。使用给vector
一个初始大小
vector<string> stringTable(256);
相关文章:
- 在 valgrind c++ 上读取大小 8 无效
- Valgrind 大小为 8 且地址 0x5b7e520 的读取无效,在大小为 16 的块内为 0 字节 free'd
- 在 c++ 中使用 getter 作为unordered_map会创建大小为 8 的无效读取
- 对唯一 ptr 无效读取的引用向量
- 瓦尔格林德:构造函数中大小为 1 的无效读取
- 将文本文件读取为 const char* 有时有效,有时无效
- 瓦尔格林德在文件*上的读取无效
- (SDL 渲染问题)C++ 引发异常:读取访问冲突.这是无效的
- 无效操作数以二进制读取结构的阵列
- 获取无效或损坏的文件LNK1107:尝试链接 OpenSceneGraph 教程.dll时无法0x378读取
- 如何修复"在大小为 64 的块内读取大小为 8 - 40 字节的无效 free'd"
- Valgrind 抱怨通过指向结构的指针访问结构成员时读取无效
- VALGRIND:大小为8的读取无效
- C++:写入/读取无效/越界数组索引
- 大小为8的读取无效
- 大小8的读取无效,大小8的写入无效(Valgrind)
- Valgrind调试日志:大小为8的读取无效
- 分段故障-大小为8的读取无效
- C++ valgrid 错误:大小为 8、地址 0x8 的读取无效,未堆叠、恶意或(最近)释放?
- 将char*转换为std::string的大小为1的读取无效