Re: [PATCH] Possible arithmetic with NULL pointer or test "stack_base_ptr != NULL" is irrelevant.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Ranier Vilela <ranier_gyn(at)hotmail(dot)com>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH] Possible arithmetic with NULL pointer or test "stack_base_ptr != NULL" is irrelevant.
Date: 2019-11-24 16:40:17
Message-ID: 1871.1574613617@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Ranier Vilela <ranier_gyn(at)hotmail(dot)com> writes:
> Of course, I don't know if it's the best solution, but it's the most obvious.
> Or the test at line 3326 is irrelavant.

> \backend\tcop\postgres.c
> if (stack_depth > max_stack_depth_bytes &&
> stack_base_ptr != NULL)
> return true;

> Otherwise, if is relevant, substraction with NULL pointer is technically,undefined behavior..

[ shrug... ] Stack overflow in itself is outside the realm of the C
specification. Also, if you want to get nitty-gritty about it,
I believe that the standard only promises defined results from the
subtraction of two pointers that point to elements of the same array
object. So the change you propose isn't going to make it any closer
to adhering to the letter of "defined-ness". In practice, this code
works fine on every platform that Postgres is ever likely to support,
so I see no need to change it.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2019-11-24 17:06:26 Re: [PATCH] Style, remove redudant test "if (zeropadlen > 0)"
Previous Message John W Higgins 2019-11-24 16:30:53 Re: [PATCH] Style, remove redudant test "if (zeropadlen > 0)"