Viewers of a nervous disposition should look away now
-
A recent post was about OP's code getting a
crtisvalidheappointer
error in a C code program. The code was usingmalloc/calloc
andfree
, so it was a fair guess what was going wrong. One or two answers and comments were posted with the usual suggestions. The OP then posted the following:Quote:
thanks but I solved in this way: if (pchTesto != NULL) { pchTesto = NULL; delete pchTesto; } if (pchBuffOut != NULL) { pchBuffOut = NULL; delete pchBuffOut; }
:omg:
-
A recent post was about OP's code getting a
crtisvalidheappointer
error in a C code program. The code was usingmalloc/calloc
andfree
, so it was a fair guess what was going wrong. One or two answers and comments were posted with the usual suggestions. The OP then posted the following:Quote:
thanks but I solved in this way: if (pchTesto != NULL) { pchTesto = NULL; delete pchTesto; } if (pchBuffOut != NULL) { pchBuffOut = NULL; delete pchBuffOut; }
:omg:
wow. reminds me of the time when a coworker, who was a bit of a PITA - never listened to good advice, was convinced he had found a bug in the compiler. Having had this fantasy once or twice myself, I've learned that it is almost certainly not the compilier :). Myself and one other took a look at his code and immediately found a buffer overrun. He insisted that it always worked correctly before and that could not be the issue. but back to that code fragment - :omg:
Charlie Gilley “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759 Has never been more appropriate.
-
Big whoopsie moment, I had a few of them, enugh that I made my own macro DDELETENULL(x) to avoid the same mistake.
#define DDELETENULL(x) if (x != NULL) {delete(x); x = NULL;}
I had a DFREENULL(x) which was identical but with free.
GCS/GE d--(d) s-/+ a C+++ U+++ P-- L+@ E-- W+++ N+ o+ K- w+++ O? M-- V? PS+ PE Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++* Weapons extension: ma- k++ F+2 X The shortest horror story: On Error Resume Next
My dear Watson, it's pretty sure
DFREENULL(x)
came before theDDELETENULL(x)
and theif
statement got carried away. In C++ you can delete NULL pointers without hearing a peep from the compiler. :laugh:Mircea
-
My dear Watson, it's pretty sure
DFREENULL(x)
came before theDDELETENULL(x)
and theif
statement got carried away. In C++ you can delete NULL pointers without hearing a peep from the compiler. :laugh:Mircea
First, it was C++/98, mostly (VisualStudio 6, in 201x, ugh) and it would create issues. Second, I do clean programming. If a pointer is NULL I don't delete it, despite what the compiler says. It's simply wrong. Third, DDELETENULL came first because I needed it before I realized I also had some pointers to deallocate with free (mostly the ones allocated with _mm_malloc).
GCS/GE d--(d) s-/+ a C+++ U+++ P-- L+@ E-- W+++ N+ o+ K- w+++ O? M-- V? PS+ PE Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++* Weapons extension: ma- k++ F+2 X The shortest horror story: On Error Resume Next
-
wow. reminds me of the time when a coworker, who was a bit of a PITA - never listened to good advice, was convinced he had found a bug in the compiler. Having had this fantasy once or twice myself, I've learned that it is almost certainly not the compilier :). Myself and one other took a look at his code and immediately found a buffer overrun. He insisted that it always worked correctly before and that could not be the issue. but back to that code fragment - :omg:
Charlie Gilley “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759 Has never been more appropriate.
charlieg wrote:
Having had this fantasy once or twice myself,
At one point I put a PostIt note on my monitor: "The stupid is on the other side of the screen" :laugh:
Mircea
-
wow. reminds me of the time when a coworker, who was a bit of a PITA - never listened to good advice, was convinced he had found a bug in the compiler. Having had this fantasy once or twice myself, I've learned that it is almost certainly not the compilier :). Myself and one other took a look at his code and immediately found a buffer overrun. He insisted that it always worked correctly before and that could not be the issue. but back to that code fragment - :omg:
Charlie Gilley “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759 Has never been more appropriate.
In the embedded world sometimes we actually find bugs in the compiler, though they are easier to spot since the disassembly is much leaner.
GCS/GE d--(d) s-/+ a C+++ U+++ P-- L+@ E-- W+++ N+ o+ K- w+++ O? M-- V? PS+ PE Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++* Weapons extension: ma- k++ F+2 X The shortest horror story: On Error Resume Next
-
A recent post was about OP's code getting a
crtisvalidheappointer
error in a C code program. The code was usingmalloc/calloc
andfree
, so it was a fair guess what was going wrong. One or two answers and comments were posted with the usual suggestions. The OP then posted the following:Quote:
thanks but I solved in this way: if (pchTesto != NULL) { pchTesto = NULL; delete pchTesto; } if (pchBuffOut != NULL) { pchBuffOut = NULL; delete pchBuffOut; }
:omg:
It's like taking leak in the morning and then waking up.
Advertise here – minimum three posts per day are guaranteed.
-
In the embedded world sometimes we actually find bugs in the compiler, though they are easier to spot since the disassembly is much leaner.
GCS/GE d--(d) s-/+ a C+++ U+++ P-- L+@ E-- W+++ N+ o+ K- w+++ O? M-- V? PS+ PE Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++* Weapons extension: ma- k++ F+2 X The shortest horror story: On Error Resume Next
I have heard of this happening but never experienced it. This had to do with the C compiler for OpenVMS. The people that worked on DEC's compilers were legendary.
Charlie Gilley “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759 Has never been more appropriate.
-
wow. reminds me of the time when a coworker, who was a bit of a PITA - never listened to good advice, was convinced he had found a bug in the compiler. Having had this fantasy once or twice myself, I've learned that it is almost certainly not the compilier :). Myself and one other took a look at his code and immediately found a buffer overrun. He insisted that it always worked correctly before and that could not be the issue. but back to that code fragment - :omg:
Charlie Gilley “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759 Has never been more appropriate.
charlieg wrote:
he had found a bug in the compiler. Having had this fantasy once or twice myself, I've learned that it is almost certainly not the compilier
Very long time ago I found a bug in the C++ compiler I was using. So I wrote a letter to the company (again long time ago.) I carefully pointed out how the C++ compiler did not do what Stroustrup documented in "The C++ Programming Language". The president of the company (I suspect the only employee) wrote back to tell me that Stroustrup was wrong. Years later when the ANSI C++ spec was finalized I saw that Stroustrup was still right.
-
charlieg wrote:
Having had this fantasy once or twice myself,
At one point I put a PostIt note on my monitor: "The stupid is on the other side of the screen" :laugh:
Mircea
I usually refer to the acronym PICNIC. Problem In Chair Not In Computer
Kelly Herald Software Developer
-
I usually refer to the acronym PICNIC. Problem In Chair Not In Computer
Kelly Herald Software Developer
-
charlieg wrote:
he had found a bug in the compiler. Having had this fantasy once or twice myself, I've learned that it is almost certainly not the compilier
Very long time ago I found a bug in the C++ compiler I was using. So I wrote a letter to the company (again long time ago.) I carefully pointed out how the C++ compiler did not do what Stroustrup documented in "The C++ Programming Language". The president of the company (I suspect the only employee) wrote back to tell me that Stroustrup was wrong. Years later when the ANSI C++ spec was finalized I saw that Stroustrup was still right.