logoalt Hacker News

amluto • today at 4:10 AM • 1 reply • view on HN

Even in C, if you have a function that takes an input buffer and output buffer of differing lengths, the right API has the caller pass both lengths.

But yes, gets is worse.


Replies

userbinator • today at 4:57 AM

takes an input buffer and output buffer of differing lengths, the right API has the caller pass both lengths.

If there is no fixed relationship between the two, then that makes sense; but in this case there is a very simple and well-defined relationship between them. But to specify two lengths which must always agree; and if not, then what? You've effectively invented an additional artificial error condition, an additional branch, and burdened all the callers up the chain to do something, which is a treacherous path to complexity and the production of even more bugs.

Or are you just preaching the same mindless idiocy that lead to Microsoft's memcpy_s() (the "s" is for "stupid")?

➕ show 1 reply