Stop checking for NULL pointers! 

when passing a pointer to a C function, there is only one semantically-correct value for that pointer, as opposed to 264-1 invalid values. NULL may or may not be one of these invalid values. Let the MMU and operating system handle it.

membarrier.wordpress.com/2020/

Stop checking for NULL pointers! 

@danso this is why we can't have nice things.

Stop checking for NULL pointers! 

@Sophistifunk

not sure what you mean. clarify please?

Follow

@danso terrible advice like "checking for bad pointers is somebody else's problem" (and the refusal to let go of C) is why everything is broken all the time.

· · Web · 1 · 0 · 0

@Sophistifunk

i think the piece makes a pretty compelling argument for omitting a null pointer check in specific circumstances. have you read it?

@danso yes, and I think it's bad advice, of the kind that continues to give us segfaults, NPEs, and CVEs.

@Sophistifunk

hm. it seems to me that if an invalid pointer is passed to a function such as the one described in the article, a programming error has _already_ occurred. in your opinion, what should that function do if it gets an invalid argument?

@danso the entire concept of "it's somebody else's job to check this" and "just change the docs to call it undefined behaviour when X" is where most of these bugs come from.

@Sophistifunk

in the example given, that does not require a change to the documentation. the behaviour of that function is undefined if the pointer points to anything other than a null-terminated string.

C does not provide any mechanism to check most of these cases, so there is nothing to be done other than document them.

Sign in to participate in the conversation
No Agenda Social

The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!