Thread: int GetData(unsigned char* aBuffer);

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    20

    int GetData(unsigned char* aBuffer);

    The following function is used to get some data from an external source (whatever is this source) and store them into the provided buffer.


    int GetData(unsigned char* aBuffer);



    Why is this function “dangerous”? How would you improve it so that it is not dangerous? (Hint: the question is not about the return value or the details of how the data is received).

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    buffer overrun
    add buffer length as a parameter
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User
    Join Date
    Dec 2003
    Posts
    20

    typedef

    thanx for that

    another question , is the following sytax correct ?

    typedef int myfunc(void*) myDefinedFunc();

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    I don't think so...
    this syntax resembles some definition of the pointer to the function, but where is the * indication that?

    And you cannot define type "function" only "pointer to function" is possible
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > another question , is the following sytax correct ?
    > typedef int myfunc(void*) myDefinedFunc();
    Type it into a C program and compile it to find out.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory leak
    By aruna1 in forum C++ Programming
    Replies: 3
    Last Post: 08-17-2008, 10:28 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Replies: 2
    Last Post: 03-24-2006, 08:36 PM
  4. getting a headache
    By sreetvert83 in forum C++ Programming
    Replies: 41
    Last Post: 09-30-2005, 05:20 AM
  5. Quack! It doesn't work! >.<
    By *Michelle* in forum C++ Programming
    Replies: 8
    Last Post: 03-02-2003, 12:26 AM