Earlier quoted context omitted.
Yes, and interestingly, because even when used correctly they "complicate audits". This is an interesting use of preprocessor macros, I'm strongly debating introducing something like this at work.
I'm not an expert in C, but then what's the issue with strncpy() or any "n" functions? It prevents overflow AFAIK. Also what is the alternative (memcpy?) and why?
Banned C standard library functions in Git source code
31–40 of 329 posts
Re: Banned C standard library functions in Git source code
#32Re: Banned C standard library functions in Git source code
#33Re: Banned C standard library functions in Git source code
#34Edit: also interesting is a search for alloca: https://github.com/git/git/search?utf8=&q=alloca&type=
Re: Banned C standard library functions in Git source code
#35I'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
Re: Banned C standard library functions in Git source code
#36What does Git use instead for copying strings? snprintf? Edit: also interesting is a search for alloca: https://github.com/git/git/search?utf8=&q=alloca&type=
Re: Banned C standard library functions in Git source code
#37Why is there no brief explanations in this code why each function is banned?
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, so the buffer size must be reduced by 1 by the caller and potentially manually terminates, which is too easy to not consider. But any C programmer with significant experience already knows these pitfalls. So it's not controversial.
Re: Banned C standard library functions in Git source code
#38Looks like Git has its own string type: https://github.com/git/git/blob/master/strbuf.h https://github.com/git/git/blob/master/strbuf.c See this for the story of why strncpy/strncat are insecure: https://en.wikipedia.org/wiki/C_string_handling#Replacements
Like essentially all C programs.
Re: Banned C standard library functions in Git source code
#39Re: Banned C standard library functions in Git source code
#40But they cannot ban while (* p++ = * q++); now can they.