Re: Fix memcmp() with different sizes.

Поиск
Список
Период
Сортировка
От Kurt Roeckx
Тема Re: Fix memcmp() with different sizes.
Дата
Msg-id 20040203170430.GA19049@ping.be
обсуждение исходный текст
Ответ на Re: Fix memcmp() with different sizes.  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: Fix memcmp() with different sizes.  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-patches
On Mon, Feb 02, 2004 at 09:27:46PM -0500, Tom Lane wrote:
> Kurt Roeckx <Q@ping.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


В списке pgsql-patches по дате отправления:

Предыдущее
От: Bruce Momjian
Дата:
Сообщение: Re: fix memcpy() overlap
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Fix memcmp() with different sizes.