test function looks a bit strange ...

View: New views
2 Messages — Rating Filter:   Alert me  

test function looks a bit strange ...

by Guenter Knauf-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,
in abts.c we have:

void abts_ptr_notnull(abts_case *tc, const void *ptr, int lineno)
{
    update_status();
    if (tc->failed) return;

    if (ptr != NULL) return;

    tc->failed = TRUE;
    if (verbose) {
        fprintf(stderr, "Line %d: Expected NULL, but saw <%p>\n",
lineno, ptr);
        fflush(stderr);
    }
}

it looks like the function returns if ptr != NULL (which also fits to
its name), but if ptr == NULL then we write a wrong error message, and
then try to print that NULL pointer ...?
Shouldnt that be:
-        fprintf(stderr, "Line %d: Expected NULL, but saw <%p>\n",
lineno, ptr);
+        fprintf(stderr, "Line %d: Expected non-NULL, but got NULL\n",
lineno);

??

Gün.



Re: test function looks a bit strange ...

by Jeff Trawick :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Mon, Oct 12, 2009 at 5:31 PM, Guenter Knauf <fuankg@...> wrote:

> Hi,
> in abts.c we have:
>
> void abts_ptr_notnull(abts_case *tc, const void *ptr, int lineno)
> {
>    update_status();
>    if (tc->failed) return;
>
>    if (ptr != NULL) return;
>
>    tc->failed = TRUE;
>    if (verbose) {
>        fprintf(stderr, "Line %d: Expected NULL, but saw <%p>\n",
> lineno, ptr);
>        fflush(stderr);
>    }
> }
>
> it looks like the function returns if ptr != NULL (which also fits to
> its name), but if ptr == NULL then we write a wrong error message, and
> then try to print that NULL pointer ...?
> Shouldnt that be:
> -        fprintf(stderr, "Line %d: Expected NULL, but saw <%p>\n",
> lineno, ptr);
> +        fprintf(stderr, "Line %d: Expected non-NULL, but got NULL\n",
> lineno);

+1