-1

I initialize a pointer from a list of pointers. I can read data from this pointer without a problem(line 2), but when I try to write any data(line 3), it crashes.

When i put a breakpoint on line 3, the debugger shows that the pointer is pointing to the correct object based on its variables.

DimensionItem *DI = DimItems[j];
qDebug() << "DI xposition: " << DI->pos().x();
DI->setPos(1,1);

If I breakpoint on line 3, my application output is:

::Debug::{(../Zedspex/Widgets/automeasurewidget.cpp:434)}:: DI xposition:  5.15645e-312

And I can see data in DI in the debugger: DI in debugger before seg fault

A pop-up saying a seg fault occurred. This is the only message from the dubugger:

signal 11 (Segmentation fault), address is 0x2c from 0x4340cec4
[bt]: (1) /usr/lib/libQt5Widgets.so.5(_ZN13QGraphicsItem6setPosERK7QPointF+0x8c) [0x4340cec4]
seg
  • 31
  • 8

1 Answers1

-1

The contents of memory might stick around even after you have released it, so reading from invalid pointers may appear to work. On the other hand, if you write to that location you may get an exception.

signal 11 (Segmentation fault), address is 0x2c from 0x4340cec4

An address of 0x2c is very low and suggests that the pointer is null.

The very little evidence you have provided suggests that the pointer is in fact not valid. It may have been released (usually with delete in C++) at some point or overridden with a bad address.

Heath Raftery
  • 3,643
  • 17
  • 34