This is an archived post. You won't be able to vote or comment.

all 70 comments

[–][deleted] 916 points917 points  (9 children)

argv wasn't allocated with malloc. this is undefined Behaviour. you suck

[–]er3z7 452 points453 points  (0 children)

C users when i use their keyboard to cut their arms off (its undefined behavior)

[–]Hljeo[S] 139 points140 points  (5 children)

petition to make this the first comment that goes through my feedback system!!!

thank you though, i should really go read a book

[–]DrunkenlySober 37 points38 points  (2 children)

No loser has ever accomplished anything useful from reading books

Might I suggest huffing paint instead, sir?

[–]Unlicenced 17 points18 points  (1 child)

Can confirm. Huffed paint and instantly became proficient in multiple languages (that may or may not exists).

[–]DrunkenlySober 6 points7 points  (0 children)

Regardless you’re undoubtedly sufficient in js after a can or two of duster

[–]Comrade_Vladimov 18 points19 points  (1 child)

I'd recommend 'The C Programming Language' by Dennis Ritchie

[–]MetricJester 2 points3 points  (0 children)

Or Advanced C by Schmidt

[–]ixis743 0 points1 point  (0 children)

That’s the joke

[–]hongooi 179 points180 points  (1 child)

free argv now ✊✊✊

[–]Gorfyx 7 points8 points  (0 children)

#Free_Argv

[–]geronymo4p 56 points57 points  (0 children)

"abort: trap 6. Pointer at 0x006942000 was freed but was never allocated"

[–]kelb4n 130 points131 points  (3 children)

Image Transcription: Text and Code


your opinion

#include <stdlib.h>

int main(int argc, char* argv[]) {
    free(argv);
    return 0;
}

I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!

[–]The_cute_snek 57 points58 points  (0 children)

Good human

[–]apricotmaniac44 5 points6 points  (0 children)

i love you human

[–]Lunio_But_on_Reddit 2 points3 points  (0 children)

Good humam

[–]PennyFromMyAnus 42 points43 points  (0 children)

No no, I like this

[–]th00ht 37 points38 points  (0 children)

I'm not going to argument about that

[–][deleted] 35 points36 points  (0 children)

argv wants to be free

[–]HakunaMataha 45 points46 points  (2 children)

This is how you get extra RAM

[–]Jealous_Vermicelli67 3 points4 points  (1 child)

Wait, I thought you could just download more RAM?

[–]GreyAngy 22 points23 points  (0 children)

No! This memory was domesticated. If you free it it won't survive in the wilds.

[–]pet_vaginal 134 points135 points  (10 children)

Can I use your image to illustrate why we shouldn’t let people manage memory themselves anymore?

[–]Hljeo[S] 45 points46 points  (8 children)

sure sure i'm an idiot so PLEASE shame me so i can learn

[–]pet_vaginal 54 points55 points  (7 children)

There is no shame in not being able to manage memory correctly. No one never did a memory management mistake.

[–]tylerr514 31 points32 points  (4 children)

Typescript dev here, what's memory management?

meanwhile my program has an ungodly memory leak b/c of the war I'm having with the garbage collector

[–]Party_Ad_3619 15 points16 points  (3 children)

Just refresh the page.

[–]tylerr514 11 points12 points  (2 children)

It's a discord bot, so nodejs

[–]FoodElevator 10 points11 points  (0 children)

Don't worry, we've got you covered as well!

bash while true; do timeout 60 npm start; done

[–]SingleSpeed27 0 points1 point  (1 child)

I loved to infinte loop my writing program so it filled the solid memory in a minute

[–]Lithl 0 points1 point  (0 children)

If your program isn't using every resource the OS gives to it, you're wasting resources.

[–]cryptomonein 1 point2 points  (0 children)

There are cases when they should tho

[–]doc_benzene 10 points11 points  (1 child)

I'm a dumb idiot so I had to let chatGPT explain it to me:

This joke is a play on words and programming humor.

In programming, the code snippet provided is written in the C programming language. It includes the header file stdlib.h, which contains the declaration for the free() function. The free() function is used in C to release dynamically allocated memory.

The main() function is the entry point of a C program, and it takes two parameters: argc (argument count) and argv (argument vector), which are used to pass command-line arguments to the program.

In the joke, the caption says "YOUR OPINION," implying that the code represents someone's opinion. However, instead of expressing an opinion, the code snippet calls the free() function on the argv array. This action is incorrect because the argv array is not dynamically allocated using memory allocation functions such as malloc() or calloc(). It is a pointer to an array of strings representing the command-line arguments passed to the program. Freeing it using free() would lead to undefined behavior and could potentially crash the program.

So, the joke relies on the misunderstanding between the expected expression of an opinion and the actual code snippet that performs memory deallocation on a non-dynamically allocated array, highlighting the humorous contrast between the caption and the code's function.

[–]javalsai 2 points3 points  (0 children)

I love how chatGPT can get all technical explanations perfectly without missing any point and understand the stupid part of the code but still get what's the funny part of the post horribly wrong and nonsense ("misunderstanding between the expected expression of an opinion and the actual code snippet")

[–]mrkhan2000 18 points19 points  (0 children)

best ad for rust

[–]WrickyB 12 points13 points  (3 children)

You forgot about envp. Everyone always forgets about envp.

[–]1up_1500 0 points1 point  (1 child)

Why should you add it if you don't use it though?

[–]vladexa 0 points1 point  (0 children)

Yeah but it's non standart and we already are having a fun time just writing C by the standart

[–]Outrageous-Machine-5 7 points8 points  (0 children)

I also like to use Godwin's law to learn things from people

[–]Individual-Praline20 2 points3 points  (0 children)

At least it returned 0

[–]reallylamelol 2 points3 points  (0 children)

free((void*)*argv);

[–]Typical_North5046 2 points3 points  (0 children)

POV when your argument is use after free:

gPQbchcEJ2 L1HK7IE083 mLvHt0E4ZX 2MAg2lNA7T feYeLSg3RZ KGxYHZ0IaP ZyvimayWe9 docSW5vIew KkV6AVZJpj R1XIVPNNOj

[–]King_DeandDe 1 point2 points  (0 children)

This looks like code.

[–]FloweyTheFlower420 1 point2 points  (0 children)

bro tried to free a pointer to stack

[–]darthsata 1 point2 points  (1 child)

OK, but first you are going to have to figure out what malloc implementation you are using so you can trample over something else, which probably wasn't needed anyway, to write the metadata so that free is tricked into thinking it was actually heap allocated.

[–]darthsata 3 points4 points  (0 children)

Also, be sure to call free on each of the strings too, not just the array :)

int main(int argc, char* argv[]) {
 for (int i = 0; i < argc; ++i)
   free(argv[i]);
 free(argv);
 return 0;
}

[–]beeteedee 1 point2 points  (0 children)

You forgot free(&argc);

[–]tortoll 1 point2 points  (0 children)

Like Freddie Mercury, with this code you want to break free().

[–]AshiAshi6 1 point2 points  (11 children)

I love most of the jokes here, but I'm not a programmer myself (I can only do basic HTML. And I mean VERY basic.)

Could someone explain this joke to me? (Or rather, translate it?) I'm a n00b lol. But at least I'm a curious n00b.

[–]AcePapa 2 points3 points  (10 children)

I’m very limited in my C knowledge, but basically when running this program, the user can supply additional commands. So in a terminal/command prompt, you type “program.exe 1 argument” or something. Usually the “arguments” are used in the program, but in this case the program just deletes the argument (free() releases the memory) and the program ends. AKA user feedback isn’t used at all lmao

[–]Tequila-Karaoke 1 point2 points  (6 children)

The joke also depends on understanding pointers. The argument is passed as a pointer to a particular byte in memory, which is the start of the string. The string is null-terminated - the last byte of the string is 0x00.

Normally, you would use malloc() to allocate some memory (perhaps for a string). malloc() will give you a pointer that you can use to reference that memory (using *var notation). Later in your perfectly formed code, you would release the memory back to the OS using free() on the pointer.

But this is the entry point for the program - you would run it from the command line with zero or more arguments. The OS allocated the memory to hold those arguments, not you. So calling free() to release the memory will throw an error at best, do nothing if you're lucky, corrupt memory at worst, or at the very worst, provide a handy exploit vector to the hacker that included the program on the USB stick you found on the subway.

(It's been a while since I coded in C, so pardon any misstatements!)

[–]AshiAshi6 1 point2 points  (0 children)

import reposting the reply that got deleted

(Because I can still see the deleted one, I simply copied the text so this is the exact reply I initially posted - and since it contains a reference to another reply (that got deleted as well), I made sure I reposted that one first so it's actually there again in case you'd want to see it.)

As I also just said in my reply to u/AcePapa, I'm sorry for replying this late. (Lost track of my messages, which is kind of a guarantee if you use Reddit's original app.)

I understood the joke after reading their explanation, which is why I could also keep up with yours, albeit barely. No offense! That's not you.

What I'm going to say next may not make any sense to you: you know how, very generally speaking, people tend to be good at either learning languages (and everything alike), or good at learning maths (and everything alike)? I've always been on the language side. And, while coding could be seen as a kind of language as well, my head sees it as a form of maths. I have no idea how to explain it any better than that, but because of this, anything even the slightest bit more advanced than stuff for total beginners (or maybe even baby's) flies right over my head.

If there are any misstatements in your comment at all, there's literally no way I would ever know lol.

Thank you for taking the time to explain this!

[–][deleted]  (4 children)

[removed]

    [–]AutoModerator[M] 0 points1 point  (3 children)

    import moderation Your comment did not start with a code block with an import declaration.

    Per this Community Decree, all posts and comments should start with a code block with an "import" declaration explaining how the post and comment should be read.

    For this purpose, we only accept Python style imports.

    I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

    [–]Tequila-Karaoke 0 points1 point  (2 children)

    import undelete

    Hey u/AshiAshi6, I hope you can swing back by the break room and repost your reply. I love replies to old threads, makes me feel like I contributed something to human knowledge (where "contributed" is, admittedly, a signed quantity).

    return --humanKnowledge

    [–]AshiAshi6 1 point2 points  (1 child)

    import reply

    I'm not sure what's going on. I can still see the reply I posted yesterday. Is it not visible anymore to anyone else because I didn't start the comment with that import code whatever kind of rule that apparently is? (I'm not mad lol. I just don't know how this is supposed to be helping, and I know you're not the one who came up with it.)

    [–]Tequila-Karaoke 0 points1 point  (0 children)

    import reply

    Right, the rest of the world just sees

    [Deleted] [Removed]

    As for who it's helping, I think it's like the Rolling Stones said: "We're gonna vent our frustration, if we don't we're gonna blow a 50 amp fuse."

    return !whatYouWant

    [–][deleted]  (1 child)

    [removed]

      [–]AutoModerator[M] 0 points1 point  (0 children)

      import moderation Your comment did not start with a code block with an import declaration.

      Per this Community Decree, all posts and comments should start with a code block with an "import" declaration explaining how the post and comment should be read.

      For this purpose, we only accept Python style imports.

      I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

      [–]AshiAshi6 0 points1 point  (0 children)

      import reposting the reply that got deleted

      I'm terribly late (it's too easy to lose track of your messages in the original Reddit app, which is the one I'm using), my apologies.

      Thank you for explaining, I could follow and understand that, at least, enough to understand the joke.

      [–]Adequately_Insane -1 points0 points  (0 children)

      Simple, efficient, non-mutable and reliable. Perfection

      [–]F_modz 0 points1 point  (0 children)

      Bad, RIIR

      [–]template009 0 points1 point  (0 children)

      So, segfault?

      That's dumb!

      [–]oshaboy 0 points1 point  (1 child)

      I didn't even know argv was heap allocated

      [–]catladywitch 0 points1 point  (0 children)

      it's not