this post was submitted on 17 Mar 2025
39 points (100.0% liked)

Programmer Humor

21779 readers
1509 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
 

Please leave recursion to math and keep it out of (in particular C) software: it kills and will kill again.

Kind regards from libexpat, see CVE-2022-25313 and CVE-2024-8176 for proof.

https://blog.hartwork.org/posts/expat-2-7-0-released/

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 1 points 3 days ago (1 children)

I mean, "criticism" is a little extreme even, because it's a humour post, and I was just riffing back.

Apparently GCC does indeed do tail-call optimization at -O2

Hmm, I wonder why it's considered O2 heavy. The concept of turning tail recursion into loops is simple.

But in that case, I’m not sure why the solution to the denial of service vulnerability isn’t just “compile with -foptimize-sibling-calls.”

Probably because some of the recursion involved is non-tail. Actually, it looks like GCC might still be able to cases of corecursion where the functions are "stack compatibale", but presumably most functions aren't, and who knows what little knots they tied the parsing functions in this XML library into.

[–] [email protected] 1 points 3 days ago (1 children)

I think generally C compilers prefer to keep the stack intact for debugging and such.

[–] [email protected] 1 points 2 days ago

Yes, definitely. Rereading the StackOverflow, "stack compatible" just means it can mutate the stack frame in place without resizing it in the optimised code. There's a number of ways trying to handle tail (co)recursion sucks if you try and get around that. Here's a Dr. Dobbs about it.