App crashes due to QNetworkReply
-
Just because it does print 0 here it does not mean it's correctly initialized - it's by accident because your stack where
aaa
points to is currently filled with zeros. A good memory analyzer like e.g. valgrind will tell you that you're accessing uninitialized data.See https://godbolt.org/z/9vsrva15a - myPtr is not initialized anywhere before usage.
-
@Christian-Ehrlicher
double * aaa;
std::cout << "aaa=" << aaa << std::endl;
aaa=0@JoeCFD said in App crashes due to QNetworkReply:
double * aaa;
std::cout << "aaa=" << aaa << std::endl;
aaa=0This is the best way to create an application with random crashes!
Never use a uninitialized pointer.This is a very basic rule in C/C++.
-
@JoeCFD said in App crashes due to QNetworkReply:
double * aaa;
std::cout << "aaa=" << aaa << std::endl;
aaa=0This is the best way to create an application with random crashes!
Never use a uninitialized pointer.This is a very basic rule in C/C++.
@KroMignon I know. I always initialize all pointers.
-
Just because it does print 0 here it does not mean it's correctly initialized - it's by accident because your stack where
aaa
points to is currently filled with zeros. A good memory analyzer like e.g. valgrind will tell you that you're accessing uninitialized data.See https://godbolt.org/z/9vsrva15a - myPtr is not initialized anywhere before usage.
@Christian-Ehrlicher You are right. I tried it in middle of my app and uninitialized pointers are dangled. My memory is getting worse. I remember one of the differences between Linux and Windows is that variables on Linux have default values. I am wrong. But I do initialize all my pointers.
-
@Christian-Ehrlicher You are right. I tried it in middle of my app and uninitialized pointers are dangled. My memory is getting worse. I remember one of the differences between Linux and Windows is that variables on Linux have default values. I am wrong. But I do initialize all my pointers.
@JoeCFD
It's a C++ language thing, so not per-platform. What you may find, on any platform/compiler, is that there is a difference between what you find in uninitialized (stack) variables between debug versus release builds. Or that may apply to heap areas. It's all undefined :) -
@Christian-Ehrlicher You are right. I tried it in middle of my app and uninitialized pointers are dangled. My memory is getting worse. I remember one of the differences between Linux and Windows is that variables on Linux have default values. I am wrong. But I do initialize all my pointers.
@JoeCFD said in App crashes due to QNetworkReply:
I remember one of the differences between Linux and Windows is that variables on Linux have default values. I am wrong. But I do initialize all my pointers.
AFAIK, on Linux/GCC pointers are never initialized per default.
On Windows/MSVC, they are set to 0 in debug build, but not in release. -
@JoeCFD said in App crashes due to QNetworkReply:
I remember one of the differences between Linux and Windows is that variables on Linux have default values. I am wrong. But I do initialize all my pointers.
AFAIK, on Linux/GCC pointers are never initialized per default.
On Windows/MSVC, they are set to 0 in debug build, but not in release.@KroMignon Good to know. Thanks. I have not followed this for ages.
-
@JoeCFD said in App crashes due to QNetworkReply:
I remember one of the differences between Linux and Windows is that variables on Linux have default values. I am wrong. But I do initialize all my pointers.
AFAIK, on Linux/GCC pointers are never initialized per default.
On Windows/MSVC, they are set to 0 in debug build, but not in release.@KroMignon said in App crashes due to QNetworkReply:
On Windows/MSVC, they are set to 0 in debug build, but not in release.
Wrong again - it's 0xCCCCCCCC or 0xCDCDCDCD
See https://en.wikipedia.org/wiki/Magic_number_(programming)#Debug_values -
@KroMignon said in App crashes due to QNetworkReply:
On Windows/MSVC, they are set to 0 in debug build, but not in release.
Wrong again - it's 0xCCCCCCCC or 0xCDCDCDCD
See https://en.wikipedia.org/wiki/Magic_number_(programming)#Debug_values@Christian-Ehrlicher said in App crashes due to QNetworkReply:
Wrong again - it's 0xCCCCCCCC or 0xCDCDCDCD
Yes, I was wrong... sorry, too fare away.
I mixed up pointer initialization and variable initialization!! -
As the screenshot shows, you have a segfault here. Probably from accessing any invalid pointer.
You commented some lines?! Does it still crash when you run it like this?For example; I've noticed that you
deleteLater
yourapiData
, but there is also adelete apiData
in d'tor (commented but still there).