Re: Fix memcmp() with different sizes.

From: Kurt Roeckx <Q(at)ping(dot)be>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-patches(at)postgresql(dot)org
Subject: Re: Fix memcmp() with different sizes.
Date: 2004-02-03 17:04:30
Message-ID: 20040203170430.GA19049@ping.be
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches

On Mon, Feb 02, 2004 at 09:27:46PM -0500, Tom Lane wrote:
> Kurt Roeckx <Q(at)ping(dot)be> writes:
> > - if (memcmp(re_array[i].cre_pat, text_re, text_re_len) == 0 &&
> > + if (VARSIZE(re_array[i].cre_pat) == text_re_len &&
> > + memcmp(re_array[i].cre_pat, text_re, text_re_len) == 0 &&
>
> This is not actually broken. The first four bytes of what memcmp is
> comparing are the length, and so it'll fall out immediately anyway if
> the lengths differ.

That assumes the memcmp starts from the first char and not from
the last. If it starts from the last you have undefined
behaviour.

Kurt

In response to

Responses

Browse pgsql-patches by date

  From Date Subject
Next Message Tom Lane 2004-02-03 17:09:10 Re: Fix memcmp() with different sizes.
Previous Message Tom Lane 2004-02-03 16:56:06 Re: [PATCHES] log session end - again