News for hackers. Stuff that matters.
Re:Git's list of banned C functions by Kaze404 on Thursday March 04, 2021 @04:43PM (#26348816)
Why are these functions deprecated in favor of others but not removed? I know in Javascript this can happen so as to not break older websites, but in a compiled language this shouldn't be a problem right?
Re:Git's list of banned C functions by badsectoracula on Thursday March 04, 2021 @05:17PM (#26349230)
Removing anything breaks existing source code that has been tested to work. After all just because something may lead to issues it doesn't mean it will always lead to issues.

Also in many systems the C library is linked dynamically and shared among all programs so even though a program is compiled it still relies on the underlying system to provide the function.

Finally i'm certain that if a C standard removes something, it'll be treated as the equivalent to that standard not existing. C programmers are already a conservative bunch without such changes.

Re:Git's list of banned C functions by pjc50 on Thursday March 04, 2021 @04:53PM (#26348940)
In a compiled language, when you remove a function it fails to compile. So removing them from the standard library forces code changes - they're not usually drop in replacements because the semantics were wrong in the first place.

Removing strcpy would make the Python transition look easy.

Re:Git's list of banned C functions by lalaithion on Thursday March 04, 2021 @04:52PM (#26348932)
The expectation of a C89 programmer is that a valid C89 program can be compiled for any machine that has a C89 compiler, and likewise for C95, C99, C11, and C17. Furthermore, it's expected that any C89 program can be compiled unchanged on any future version of C, and the standard library is part of the definition of the language, and therefore functions cannot be removed.
Re:Git's list of banned C functions by DaiPlusPlus on Thursday March 04, 2021 @05:34PM (#26349435)
At a certain point we have to say that it’s wrong for someone to expect C89 should still be the LCD.

And yes: it should all still compile, but none of that prohibits the compiler from issuing flashing red/yellow warning messages to your terminal for using footgun functions, preferably with uncomfortable audible notifications too.

All of this is silly though, because even in a strict C89 environment you can still have your own safe wrappers over the unsafe functions. I find that very little of modern programming has a hard dependency on ultramodern compiler features (e.g. you can theoretically build React/Redux using only ES3 (1998ish) if you like. Generics using type-erasure can be implemented with macros. Etc.).

Also, C89 conformance doesn’t mean much: you can have a confirming C89 system that doesn’t even have a heap - nor a stack for autos! (IBM Z/series uses a linked-list for call-frames, crazy stuff!)

Re:Git's list of banned C functions by cestith on Thursday March 04, 2021 @06:26PM (#26349984)
I think for new code in environments that support newer standards C89 shouldn't be used. For the increasingly rare places new C is being written where C89 is the latest tooling available and the code handles strings, a safer string library is nearly a must. I strongly recommend a safer string library no matter which standard, but I'm nobody.

When updating existing code C89 (maybe K&R) might be what's used so minor code changes won't undo that.

I tend to write most of my code in something higher-level than C and only resort to C or assembly in performance-critical sections as found with a profiler. Plenty of general-purpose languages have memory-safe strings built into the language, and honestly I keep hoping the Cisco/Intel safestrings library or something like SDS gets the standard library blessing one day.

Re:Git's list of banned C functions by DaiPlusPlus on Thursday March 04, 2021 @07:00PM (#26350327)
> I think for new code in environments that support newer standards C89 shouldn't be used

Why stop there? Don't use C. Use Rust!

Re:Git's list of banned C functions by SAI_Peregrinus on Thursday March 04, 2021 @08:11PM (#26351077)
Rust doesn't (yet) support all the targets C does. Mostly weird embedded stuff that needs it, and gccrs might solve that problem, but it's not always possible.

When it is possible, I certainly agree that Rust is nicer.

Re:Git's list of banned C functions by badsectoracula on Thursday March 04, 2021 @07:58PM (#26350950)
> And yes: it should all still compile, but none of that prohibits the compiler from issuing flashing red/yellow warning messages to your terminal for using footgun functions, preferably with uncomfortable audible notifications too.

As long as it is done like in recent versions of Visual C++ where i can disable that useless compiler output pollution with a #define, usually with a snide remark about Visual C++ right above it.

Re:Git's list of banned C functions by DaiPlusPlus on Thursday March 04, 2021 @09:59PM (#26352013)
> disable that useless compiler output pollutio

The compiler is trying to help you write better code - suppressing warnings should not be taken lightly.

Re:Git's list of banned C functions by badsectoracula on Friday March 05, 2021 @01:56AM (#26353692)
This is not the same as the regular warnings though, what Visual C++ is doing isn't helping writing better code - it is suggesting to replace standard functions which are available everywhere in code where i actually know what i'm doing with functions that are available to Visual C++ and pretty much nowhere else.

As i wrote in another comment, something that may lead to issues isn't the same as something that will always lead to issues - e.g. if i check a string's length or actually calculate and allocate the necessary memory before calling strcpy it is perfectly fine and safe to use it, but Visual C++ doesn't know about that, it complains like some stupid greenhorn that read somewhere "never use gotos" and then is surprised when he sees some Linux kernel code with gotos everywhere for cleanup, thinking that those people writing the kernel do not know what they're doing.

Re:Git's list of banned C functions by maxlybbert on Thursday March 04, 2021 @05:09PM (#26349146)
The C Standard Committee doesn’t actually ship a compiler the way the people behind Java, Python, Lua, C#, Go, Rust, etc. do. The best they can do is deprecate particular functions and hope compiler writers and standard library writers follow along. But the compiler writers have vocal customers who insist the depreciations are overly-cautious.
Re:Git's list of banned C functions by syncsynchalt on Thursday March 04, 2021 @05:09PM (#26349144)
There are actually very few _dangerous_ functions in C (gets is the only one that comes to mind). Others have massive caveats (strncpy) but still have their place. Others are just known to have certain gotchas (strcpy, strcat, sprintf).

The reality of C is that if we deprecated every objectionable function in the stdlib we wouldn't have anything left.

Re:Git's list of banned C functions by a1369209993 on Friday March 05, 2021 @02:55AM (#26354065)
> There are actually very few _dangerous_ functions in C

I think you mean there are very few functions that cannot possibly be used correctly (namely gets). Most C functions are dangerous - can lead to crashes and security vulnerabilties if used incorrectly - but that's just a expected consequence of using a language with no provisions for memory-safety.

> The reality of C is that if we deprecated every objectionable function in the stdlib we wouldn't have anything left.

Somewhat ironically, malloc is actually perfectly safe[0] - using the return value has some issues, but calling it is always[0] fine.

0: Assuming the OS-level memory allocator is sanely configured WRT overcommit, anyway.

Re:Git's list of banned C functions by gvx on Thursday March 04, 2021 @05:40PM (#26349510)
It's not great if you're working on a new release and you realize you also need to change something unrelated because the language changed under you, especially if it's just a bugfix but a high-priority one, or consider the head-aches caused by source-only distributions suddenly breaking for all your new users (or existing users switching to a new computer or spinning up a fresh VM).
Re:Git's list of banned C functions by sudomakeup on Thursday March 04, 2021 @05:11PM (#26349167)
Why wouldn't it be an issue with a compiled language?

Its nearly the exact same reasoning as "we're not going to break older websites"

Re:Git's list of banned C functions by Kaze404 on Thursday March 04, 2021 @06:47PM (#26350196)
In Javascript there's an expectation that Javascript written 15 years ago for Netscape will also work on Firefox 89. Is that also the case with C, wrt compiler versions? I've always assumed it wasn't.
Re:Git's list of banned C functions by int_19h on Thursday March 04, 2021 @07:46PM (#26350826)
It's very much the case, so long as you stick to standard C (the full limitations of which very few people are actually aware of).

Runtime backwards compatibility is similarly extensive on platforms that care about it. You can still take a DOS app written in ANSI C89 the year that standard was released, and run it on (32-bit) Windows 10, and it'll work exactly the same. In fact, you can do this with apps all the way back to DOS 1.0.

Re:Git's list of banned C functions by Kaze404 on Thursday March 04, 2021 @09:19PM (#26351680)
Wow, that's super interesting. Thank you :)