←back to thread

327 points AareyBaba | 2 comments | | HN request time: 0s | source
Show context
mainecoder ◴[] No.46193095[source]
Did they really have to tell their programmers this ? (see Page 52) AV Rule 174 (MISRA Rule 107) The null pointer shall not be de-referenced.
replies(3): >>46195261 #>>46196414 #>>46200255 #
1. jandrewrogers ◴[] No.46195261[source]
There are old idioms in C where null pointers are intentionally dereferenced to induce the expected outcome. Not the best way to write that code because beyond being less explicit about intent it also isn't guaranteed to work.

The rule is likely speaking to this code.

replies(1): >>46200391 #
2. AnimalMuppet ◴[] No.46200391[source]
I've done it, I think more than once.

I was getting to a point in the code. I could tell by a log statement or some such. But I didn't know in what circumstances I was getting there - what path through the code. So I put in something like

  char *p = 0;
  *p = 1;
in order to cause a core dump. That core dump gave me the stack trace, which let me see how I got there.

But I never checked that in. If I did, I would expect a severe verbal beating at the code review. Even more, it never made it into release.