Re: NULL passed as an argument to memcmp() in parse_func.c

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Piotr Stefaniak <postgres(at)piotr-stefaniak(dot)me>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: NULL passed as an argument to memcmp() in parse_func.c
Date: 2015-06-22 18:55:22
Message-ID: 7856.1434999322@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Piotr Stefaniak <postgres(at)piotr-stefaniak(dot)me> writes:
> There are two places in parse_func.c where memcmp() conditionally gets a
> NULL as its first argument, which invokes undefined behavior. I guess
> gcc -O2 will make some assumptions based on memcpy's __nonnull attribute.

If I recall that code correctly, the assumption was that if the third
argument is zero then memcmp() must not fetch any bytes (not should not,
but MUST not) and therefore it doesn't matter if we pass a NULL. Are
you seeing any observable problem here, and if so what is it?

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Piotr Stefaniak 2015-06-22 19:15:35 Re: NULL passed as an argument to memcmp() in parse_func.c
Previous Message Jim Nasby 2015-06-22 18:54:38 Re: Further issues with jsonb semantics, documentation