Turn on thread page Beta

Question for C and C++ programmers watch

Announcements
  • View Poll Results: Do you know what a buffer over flow is?
    Yes
    30
    90.91%
    No
    3
    9.09%

    • Thread Starter
    Offline

    0
    ReputationRep:
    I'm just curious if people know about this...
    Offline

    0
    ReputationRep:
    I'd think most, if not all, C/C++ programmers know about this. Any documentation I've seen about arrays warn about this very clearly and early on.
    Offline

    0
    ReputationRep:
    Yep one of the primary reasons you never ever use the gets() function.
    Offline

    17
    ReputationRep:
    char reply[4] = "yes";

    Offline

    0
    I once managed to fry the Linux kernel on a PS2 development kit with a buffer overflow. . . so in answer to your question: yes.

    They do have their uses, though (modchips spring to mind).
    Offline

    16
    ReputationRep:
    (Original post by Wineblood)
    I'd think most, if not all, C/C++ programmers know about this. Any documentation I've seen about arrays warn about this very clearly and early on.
    Isn't it also possible with pointers? Or is that where you don't free memory and it just gets eaten up.
    Offline

    0
    ReputationRep:
    (Original post by trance addict)
    Isn't it also possible with pointers? Or is that where you don't free memory and it just gets eaten up.
    Memory Leak.
    • Thread Starter
    Offline

    0
    ReputationRep:
    Good, i'm into computer security so i know about buffer overflows.
    It's just I have a "Sams Teach yourself C++ in 24hours" and I don't remember seeing the function malloc once, or any mention of buffer overflow prevention.

    Maybe I should have asked do you know how to prevent buffer overflows.
    Offline

    0
    ReputationRep:
    If you were being taught C++, you would have used new and delete instead of malloc and free.
    Offline

    0
    ReputationRep:
    (Original post by slugonamission)
    If you were being taught C++, you would have used new and delete instead of malloc and free.
    Doesn't new create new objects whereas malloc just allocates space?
    Offline

    0
    ReputationRep:
    You can use new like malloc, for example, instead of:

    Code:
    char* string = malloc(my_string_length * sizeof(char));
    You'd do this in C++:

    Code:
    char* string = new char[my_string_length];
    (well, in reality you'd do std::string* foo = new std::string();, but let's forget about that!)

    new is just the OO version of malloc, similarly for delete and free. You can delete malloc'd areas of memory, and free objects (although if you did, you'd be burned at the stake by C++ programmers :P)
    Offline

    17
    ReputationRep:
    Burning them at the stake is for their own good.

    new and delete call constructors/destructors when used with objects which malloc/free won't do.
    Offline

    14
    ReputationRep:
    new and delete can be overloaded can't they? That's what I like about C++. You can overload pretty much everything. It can be as high level as you want to make it with properly designed classes.
    Offline

    17
    ReputationRep:
    Yea. Overloading is great.
    In my chat client I overloaded "<<" to send data to the server cout style.
    It's a shame the newer languages don't seem to support it.
 
 
 
Poll
Have you ever experienced bullying?
Useful resources

The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

Write a reply...
Reply
Hide
Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.