Live data from Hacker News

Banned C standard library functions in Git source code

github.com

91–100 of 329 posts

Re: Banned C standard library functions in Git source code

#91

Why is there no brief explanations in this code why each function is banned?

Because Git's own developers know to use git-blame, git-show, and write good commit messages. Comments are not the only place to store meta-info about why code is the way it is.

Re: Banned C standard library functions in Git source code

#92
post #26

I'm glad to see that setjmp() and longjmp() are still allowed. I'm just kidding by the way. For those C programmers who haven't encountered these before, it is a powerful way to do a "goto" in C. Powerful in the sense that you can jump anywhere, not limited to the same function. If it's used at all these days, it's used for exception handling. More info: https://en.wikipedia.org/wiki/Setjmp.h

I've always wondered why goto is actually considered harmful. I really should read the original paper by Djikstra...

Re: Banned C standard library functions in Git source code

#93
post #87
post #67

Earlier quoted context omitted.

You can build coroutines from them, too, which is really cool and useful.

I think you mean fibers, and no you can't.

Here is an implementation of coroutines on top of setjmp/longjmp: https://fanf.livejournal.com/105413.html

Re: Banned C standard library functions in Git source code

#94

musl libc (an alternative libc) provides implementations of these functions that are memory-safe. (It only works on Linux though.)

What functions does musl provide?

It provides everything that libc does.

Re: Banned C standard library functions in Git source code

#95

Why is there no brief explanations in this code why each function is banned?

A C programmer reading this list knows exactly why they are there. It is not at all a controversial list. Edit: I guess some down voter doesn't believe me but it continues to be true. They are all string functions. Most of them do not take an output buffer size, so a source string exceeding the destination buffer will overflow. Others, like strncpy, take an output buffer size but will not null terminate when exceeded…

FYI that response insinuates that noname120 is not a C programmer...

Re: Banned C standard library functions in Git source code

#96
post #84

Earlier quoted context omitted.

Your macro refers to a twice; it might be better as a function.

What has referring to a variable twice got to do with whether it should be a macro or function?

Because it's a standard pitfall: https://gcc.gnu.org/onlinedocs/cpp/Duplication-of-Side-Effec...

Re: Banned C standard library functions in Git source code

#97

That's a surprisingly small list, missing e.g. sscanf / gets / strtok / all the other "usual suspects" at least

I don't see a huge problem with strtok as long as it isn't a multi threaded program. It is not in gets territory which is literally impossible to use correctly.

git does use multiple threads for some longer operations, like gc and pack, so using strtok would be a disaster.

Re: Banned C standard library functions in Git source code

#98
post #2

I guess they care too much about portability to use "pragma GCC poison"?

To rephrase adrianN's comment:

It wouldn't mean breaking things on compilers other than GCC. It would simply add compile-time checks when building with GCC, and would do nothing on other compilers.

Re: Banned C standard library functions in Git source code

#99
post #93
post #87

Earlier quoted context omitted.

I think you mean fibers, and no you can't.

Here is an implementation of coroutines on top of setjmp/longjmp: https://fanf.livejournal.com/105413.html

Looks more like an implementation of undefined behaviour to me.
Post reply on HN