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.
Banned C standard library functions in Git source code
121–130 of 329 posts
Re: Banned C standard library functions in Git source code
#122I'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
And in all of the CPS code.
Re: Banned C standard library functions in Git source code
#123For context, this header file was introduced during the period of Microsoft's acquisition of GitHub. Git's banned.h roughly approximates the banned functions according to Microsoft's Security Development Lifecycle: https://docs.microsoft.com/en-us/previous-versions/bb288454(... It seems Microsoft once published their own banned.h, but this file is not readily available from the MSDN anymore.
What are you saying is the connection between GitHub's acquisition and this header? This code is from git, not GitHub.
Re: Banned C standard library functions in Git source code
#124Earlier quoted context omitted.
strlcpy() is a nice alternative, it's from OpenBSD from 1996. Was later added to the other BSDs, Solaris and macOS. But, last I checked, Linux never added them. :( https://www.sudo.ws/todd/papers/strlcpy.html
strlcpy is a terrible alternative. I have never seen it used correctly. It takes more and uglier code to use it correctly than to use strlen and strcpy. People who use it don't bother. Finding use of strlcpy in a program is a red warning of sloppy code. There are good reasons it was kept out of glibc for so long.
Re: Banned C standard library functions in Git source code
#125Re: Banned C standard library functions in Git source code
#126Earlier 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
It also has a stack managed in runtime. I'm not sure that would work for any other application than the fun example here.
Re: Banned C standard library functions in Git source code
#127Earlier quoted context omitted.
Nice catch! You can send a "PR", but note that they have their own custom "PR" procedure, not the standard "PR" procedure in GitHub. > Git Source Code Mirror - This is a publish-only repository and all pull requests are ignored. Please follow https://github.com/git/git/blob/master/Documentation/Submitt... procedure for any of your improvements.
> not the standard "PR" procedure in GitHub If it is specific to one implementation, then it is not standard, pretty much by definition.
Re: Banned C standard library functions in Git source code
#128I'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
You can build coroutines from them, too, which is really cool and useful.
Re: Banned C standard library functions in Git source code
#129Earlier quoted context omitted.
Synchronous reentry is a problem. Say some loop using strtok calls a function... how do you know that that function doesn't use strtok (or call another function that does...). Any use of non-const static variables in general has this problem, and strtok is just one example.
> Say some loop using strtok calls a function... how do you know that that function doesn't use strtok (or call another function that does...). I’m constantly surprised that C isn’t specified in such a way that lack-of-reentrancy can be determined at compile time. You’d “just” need a symbol table, sort of like the debug symbol table, in each compiled object, holding for each visible symbol the set of function calls m…
Whereas with a term like reentry I think of two strtok frames on the stack at the same time, which is not possible.
I think it's a bit easier to conceptualize with a function that produces a simple return value in a static buffer. Take getpwnam(). It fills a global structure with info about a given user. So you may keep a pointer to that on your stack. Then you call some other function foo(). foo looks up another user. Suddenly you can't rely on that other call to getpwnam() not having overwritten the data in the result you got back the first time.
Re: Banned C standard library functions in Git source code
#130That'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.