I have a function that have a char* as parameter to receive some informations from inside the function. (int foo(char* param1))
How can I be sure that this parameter have the enough allocated space to receive all the information I need to put in?
I can be sure if it is, or not, a valid pointer, but I haven’t found a way to be sure about the size/length allocated to the parameter.
I can’t change the function (can’t add another parameter with the size).
AFIAK, C++ does not have any facility to verify the amount of space allocated to a pointer. If the input points to a NULL-terminated array of chracters (i.e. a c-string), then you can use strlen(). Typically these kinds of functions in C and C++ must be well-documented as to what is expected from the parameters. The function is typically implemented assuming the the caller honors the documented contract.