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 Qt下使用tcp获取数据的详细操作
  • ¥15 idea右下角设置编码是灰色的
  • ¥15 全志H618ROM新增分区
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符