Live data from Hacker News

Banned C standard library functions in Git source code

github.com

231–240 of 329 posts

Re: Banned C standard library functions in Git source code

#231

What surprises me in C developers is that C exists for probably 40 years but they still don't have proper strings (not just pointers). In many cases there is no large performance penalty for storing string length, and checking it, but they still use pointers or a separate pair of variables for pointer and buffer size instead of single object.

I've used talloc [1] where appropriate to greatly simplify memory allocation and string handling.

[1] https://talloc.samba.org/talloc/doc/html/index.html

Re: Banned C standard library functions in Git source code

#232
post #170

Earlier quoted context omitted.

Additionally we get to enjoy bounds checked arrays(std::...), and iterators on debug builds, with possibility to selectively enable them in release mode. While Windows by all means still has its security issues, the toolchain is much more security oriented than most FOSS alternatives thanks to the Windows XP wake up call. Android and ChromeOS are probably the mostly locked down alternatives on the FOSS space.

Tangential but the fact that I had to open up the machine and remove a screw to completely replace ChromeOS with linux bothers the fuck out of me.

That's how secure boot should work. Replacing the root of trust should require serious physical access that can be tamper-evident. And yeah, out of the box, the trust is with the vendor — who else would be trusted in a device that doesn't have an owner yet?

Re: Banned C standard library functions in Git source code

#233
post #170

Earlier quoted context omitted.

Additionally we get to enjoy bounds checked arrays(std::...), and iterators on debug builds, with possibility to selectively enable them in release mode. While Windows by all means still has its security issues, the toolchain is much more security oriented than most FOSS alternatives thanks to the Windows XP wake up call. Android and ChromeOS are probably the mostly locked down alternatives on the FOSS space.

Tangential but the fact that I had to open up the machine and remove a screw to completely replace ChromeOS with linux bothers the fuck out of me.

My Chromebook just made me enable developer mode.

Re: Banned C standard library functions in Git source code

#234
post #168

Earlier quoted context omitted.

I agree that strlcpy is braindamaged, but why in God's Green Earth isn't there a sensible replacement in stdlib in 2019? This shouldn't be that hard, yet the best alternative is I think snprintf, which is just so ugly. For a long time it wasn't used because compiler support was spotty, but it's been 20 years now so that shouldn't be a major issue anymore.

The (more-or-less) sensible replacement is std::string. Adoption has been spotty, for practical, ideological, and fetishistic reasons. The first step is to compile the C program with a C++ compiler. Next, start making improvements. If you skip the first step, the ceiling on improvements is limited.

C++≠C, and making the jump isn't always feasible.

Re: Banned C standard library functions in Git source code

#235
post #201

Earlier quoted context omitted.

I agree that strlcpy is braindamaged, but why in God's Green Earth isn't there a sensible replacement in stdlib in 2019? This shouldn't be that hard, yet the best alternative is I think snprintf, which is just so ugly. For a long time it wasn't used because compiler support was spotty, but it's been 20 years now so that shouldn't be a major issue anymore.

There is, it's strncpy_s and it was added in C11. And I know, nobody uses C11: that's a security failure.

strncpy_s performs a lot of checks that might not be useful, though.

Re: Banned C standard library functions in Git source code

#236
post #211

Earlier quoted context omitted.

Creating a lightweight library would make C programming much more productive, and I'm sure many have tried, but I wonder why none of them see widespread applications, instead of writing some half-baked, ad-hoc helper functions. One reason, I guess, is the diverse range of applications of C, another reason is the lack of advanced features like generics and templates. But it would still be useful to create a simple lib…

If I had to guess why there are no such lightweight library, it is because when somehow the library API doesn't provide what you want, you cannot hack the library itself easily. If you import the source code you may have trouble building it, and maintening such "patch" is not a lot of fun.

Yes. I guess the fact C doesn't have advanced features like generics and templates probably have made the problem worse, making it difficult to create a "drop-in" API.

Re: Banned C standard library functions in Git source code

#237
post #91

Earlier quoted context omitted.

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.

Git is open source, it doesn't have its own developers, every developer is "gits own developers". They really should make this more explicit.

They probably don't want the source code to start resembling a Literate Programming example.

Re: Banned C standard library functions in Git source code

#238

Earlier quoted context omitted.

These are used /everywhere/ in PostgreSQL, exactly for exception handling. The result isn't bad at all, but indeed, too powerful a tool for 99% of developers

Fortunately, 99% of developers, like 99% of drivers, are better than average.

> 99% ... are better than average.

I'm thinking there's a flaw in your mathematics...

Re: Banned C standard library functions in Git source code

#239

Earlier quoted context omitted.

Goto requires the fail block to be in the same frame. It can be a working error strategy for failing critical errors in such a way from a failing module. You have to be aware that lots of stuff is prone to leak (which can be avoided by i.e. using some memory arena) and locks/mutexes/... might be in unclear state, so code has to be aware of that.

The destination of the goto is usually the clean-up code.

That's nice for the single frame.

Let's take the example of PostgreSQL, which was mentioned in this thread: A potential implementation (I have no knowledge of pgsql internals) might be that for a single user session all memory is from a single arena, all locks and other handles are tied to the session handle, then it can be an efficient strategy to longjmp out on a critical error (i.e. IO error) and clean the arena as well as things tied to the session. instead of bubbling this up through all frames.

Re: Banned C standard library functions in Git source code

#240

Earlier quoted context omitted.

Fortunately, 99% of developers, like 99% of drivers, are better than average.

> 99% ... are better than average. I'm thinking there's a flaw in your mathematics...

No flaw with math/stats here, that can actually happen. I think you're confusing average/mean with median (50-percentile).

PS: I'm not sure where he's getting his numbers though

Post reply on HN