On Sun, 05 Oct 2008 18:22:13 +0300, Giorgos Keramidas <keramida@ceid. upatras.grwrote :
My apologies. I should have been less hasty to hit `post'. If showtext()
is passed a null pointer, it may attempt to dereference the null pointer.
A better definition of the function would be:
static void
showtext(const char **ptr)
{
if (ptr == NULL) {
printf("invalid argument\n");
return;
}
if (*ptr == NULL)
printf("a null pointer\n");
else
printf("a pointer to the text `%s'\n", *ptr);
}
See for example what this short program will print:
[...]
static void
showtext(const char **ptr)
{
if (ptr == NULL)
printf("invalid argument\n");
if (*ptr == NULL)
printf("a null pointer\n");
else
printf("a pointer to the text `%s'\n", *ptr);
}
[...]
static void
showtext(const char **ptr)
{
if (ptr == NULL)
printf("invalid argument\n");
if (*ptr == NULL)
printf("a null pointer\n");
else
printf("a pointer to the text `%s'\n", *ptr);
}
is passed a null pointer, it may attempt to dereference the null pointer.
A better definition of the function would be:
static void
showtext(const char **ptr)
{
if (ptr == NULL) {
printf("invalid argument\n");
return;
}
if (*ptr == NULL)
printf("a null pointer\n");
else
printf("a pointer to the text `%s'\n", *ptr);
}
Comment