ljt326053002 2015-05-27 14:06 采纳率: 0%
浏览 2539

c++内存问题!!!!!!!

#include
#include
#include
using namespace std;
int main() {
string a, b;
int i, x, y;
vector v1, v2;
while (cin >> a >> b) {
for (i = 0; i < v1.size(); i++) {
if (v1[i] == a) {
x = i;
break;
}
}
if (i == v1.size())
x = i;
for (i = 0; i < v2.size(); i++) {
if (v2[i] == b) {
y = i;
break;
}
}
if (i == v2.size())
y = i;
if (x == v1.size() && y == v2.size()) {
cout << b << " registered." << endl;
v1.push_back(a);
v2.push_back(b);
}
else if (v1[y] == a && v2[x] == b) {
cout << b << " signed in." << endl;
}
else if (x != v1.size() && y == v2.size()) {
cout << "GOTCHA: MAC address already occupied by ";
cout << v2[x] << "." << endl;
}
else
{ cout << "GOTCHA: " << b << " MAC address not consistent." << endl;
}
}
return 0;
}
Invalid read of size 8
| at 0x3F8CC9C0D0: std::string::size() const (in /usr/lib64/libstdc++.so.6.0.13)
| by 0x40175D: gnu_cxx::enable_ifstd::__is_char<char::__value, bool>::__type std::operator==(std::basic_string, std::allocator > const&, std::basic_string, std::allocator > const&) (basic_string.h:2243)
| by 0x4012B5: main (main.cpp:30)
| Address 0x4c29498 is 8 bytes before a block of size 8 alloc'd
| at 0x4A075BC: operator new(unsigned long) (vg_replace_malloc.c:298)
| by 0x402184: gnu_cxx::new_allocatorstd::string::allocate(unsigned long, void const*) (new_allocator.h:89)
| by 0x401F80: std::_Vector_base >::_M_allocate(unsigned long) (stl_vector.h:140)
| by 0x401BBB: std::vector >::_M_insert_aux(
gnu_cxx::__normal_iterator > >, std::string const&) (vector.tcc:322)
| by 0x401877: std::vector >::push_back(std::string const&) (stl_vector.h:741)
| by 0x40122E: main (main.cpp:27)
|
|Invalid read of size 8
| at 0x3F8CC9C0D3: std::string::size() const (in /usr/lib64/libstdc++.so.6.0.13)
| by 0x40175D: gnu_cxx::enable_ifstd::__is_char<char::__value, bool>::__type std::operator==(std::basic_string, std::allocator > const&, std::basic_string, std::allocator > const&) (basic_string.h:2243)
| by 0x4012B5: main (main.cpp:30)
| Address 0xffffffffffffffe8 is not stack'd, malloc'd or (recently) free'd
|
|
|Process terminating with default action of signal 11 (SIGSEGV)
| Access not within mapped region at address 0xFFFFFFFFFFFFFFE8
| at 0x3F8CC9C0D3: std::string::size() const (in /usr/lib64/libstdc++.so.6.0.13)
| by 0x40175D: gnu_cxx::enable_ifstd::__is_char<char::__value, bool>::__type std::operator==(std::basic_string, std::allocator > const&, std::basic_string, std::allocator > const&) (basic_string.h:2243)
| by 0x4012B5: main (main.cpp:30)
| If you believe this happened as a result of a stack
| overflow in your program's main thread (unlikely but
| possible), you can try to increase the size of the
| main thread stack using the --main-stacksize= flag.
| The main thread stack size used in this run was 10485760.
|66 bytes in 2 blocks are possibly lost in loss record 3 of 4
| at 0x4A075BC: operator new(unsigned long) (vg_replace_malloc.c:298)
| by 0x3F8CC9C3C8: std::string::_Rep::_S_create(unsigned long, unsigned long, std::allocator const&) (in /usr/lib64/libstdc++.so.6.0.13)
| by 0x3F8CC9D19A: std::string::_Rep::_M_clone(std::allocator const&, unsigned long) (in /usr/lib64/libstdc++.so.6.0.13)
| by 0x3F8CC9D5EB: std::string::reserve(unsigned long) (in /usr/lib64/libstdc++.so.6.0.13)
| by 0x3F8CC7B05A: std::basic_istream >& std::operator>>, std::allocator >(std::basic_istream >&, std::basic_string, std::allocator >&) (in /usr/lib64/libstdc++.so.6.0.13)
| by 0x401431: main (main.cpp:8)
|
|114 bytes in 2 blocks are possibly lost in loss record 4 of 4
| at 0x4A075BC: operator new(unsigned long) (vg_replace_malloc.c:298)
| by 0x3F8CC9C3C8: std::string::_Rep::_S_create(unsigned long, unsigned long, std::allocator const&) (in /usr/lib64/libstdc++.so.6.0.13)
| by 0x3F8CC9D19A: std::string::_Rep::_M_clone(std::allocator const&, unsigned long) (in /usr/lib64/libstdc++.so.6.0.13)
| by 0x3F8CC9D5EB: std::string::reserve(unsigned long) (in /usr/lib64/libstdc++.so.6.0.13)
| by 0x3F8CC7B05A: std::basic_istream >& std::operator>>, std::allocator >(std::basic_istream >&, std::basic_string, std::allocator >&) (in /usr/lib64/libstdc++.so.6.0.13)
| by 0x40141F: main (main.cpp:8)
怎么破! 求大神

  • 写回答

5条回答

  • oyljerry 2015-05-27 14:54
    关注

    应该是对vector,string的
    误报。

    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记