| ▲ | hathawsh 4 hours ago | |||||||
If I were doing a code review, I would probably accept the code either with or without the assertion. The context of curl_getenv() makes it clear that null is not acceptable. If the author of curl_getenv() had evidence that callers are frequently breaking the contract by passing null, then perhaps the assertion would help shed some light on violators. Otherwise, I would expect everyone to play by the rules, making the assertion unnecessary. | ||||||||
| ▲ | vintagedave 18 minutes ago | parent | next [-] | |||||||
That is exactly why you have a precondition or assertion. If everyone expects specific behavior - ie it’s in the contract - you require that contract. | ||||||||
| ||||||||
| ▲ | favorited 3 hours ago | parent | prev [-] | |||||||
It's also just a wrapper around getenv that provides consistent behavior across platforms, and passing a NULL name to the POSIX getenv function is UB. | ||||||||