W
weaselboy1976
Hello,
If we have c code like what's below, we will get an error because in
the stringManipulator function we attempt to modify a string literal on
the second call to the function. My question is: in the
stringManipulator function, is there any way to identify if the char*
is pointing to writable memory space to to a string literal?
Sure, the example is trivial, but we run into such problems when the
function call stack gets 20 functions deep! Thanks in advance!
int stringManipulator(char *str)
{
/* check here to see if string is writable? */
str[0] = 'A';
str[1] = 'B';
}
int main()
{
char string_array[10] = "thisisok";
stringManipulator(string_array);
stringManipulator("thisisbad"); /* shouldn't do this */
}
If we have c code like what's below, we will get an error because in
the stringManipulator function we attempt to modify a string literal on
the second call to the function. My question is: in the
stringManipulator function, is there any way to identify if the char*
is pointing to writable memory space to to a string literal?
Sure, the example is trivial, but we run into such problems when the
function call stack gets 20 functions deep! Thanks in advance!
int stringManipulator(char *str)
{
/* check here to see if string is writable? */
str[0] = 'A';
str[1] = 'B';
}
int main()
{
char string_array[10] = "thisisok";
stringManipulator(string_array);
stringManipulator("thisisbad"); /* shouldn't do this */
}