[Not really OT] Crowdstrike Analysis: It was a NULL pointer from the memory unsafe C++ language.

Walter Bright newshound2 at digitalmars.com
Sat Jul 27 01:12:09 UTC 2024


You're right that ref's can be null, too. C++ says they can't be null, but it's 
trivial to make one in C++, so a fat lot of good that does.

Let's say we have a linked list. It will have a `next` pointer:

```
struct List {
     int payload;
     List* next;
}
```

A null value is perfectly valid for `next`, as that is how the end is found. At 
least in my coding, I use null values all the time to signify there is nothing 
there.

It it wasn't null, some other value would have to be there to signify "not a 
valid item". If there must be something there, then the value would have to be 
checked against the "not a valid item" value. What should I then do if it 
unexpectedly is the "not a valid item"? The only sensible thing is to abort the 
program, as it's a program bug.

But with null, I don't have to check, because the hardware does it for free.

The only time a null pointer dereference is an actual problem is when running on 
a machine that does not have memory protection, which are decades in obsolescence.

The real issue with null pointer seg faults is the screen dump of mysterious 
numbers and letters.

The real biggest mistake in C is the eager decay of arrays to pointers, and the 
tragedy of C is nobody has any interest in fixing it.


More information about the Digitalmars-d mailing list