Re: Silly coding in pgcrypto

From: Marko Tiikkaja <marko(at)joh(dot)to>
To: Noah Misch <noah(at)leadboat(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Silly coding in pgcrypto
Date: 2014-11-02 21:53:27
Message-ID: 5456A7D7.5010506@joh.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 11/2/14, 10:34 PM, Noah Misch wrote:
> On Sun, Nov 02, 2014 at 05:10:25AM +0100, Marko Tiikkaja wrote:
>> *** a/contrib/pgcrypto/pgp-decrypt.c
>> --- b/contrib/pgcrypto/pgp-decrypt.c
>> ***************
>> *** 1069,1075 **** pgp_skip_packet(PullFilter *pkt)
>>
>> while (res > 0)
>> res = pullf_read(pkt, 32 * 1024, &tmp);
>> ! return res < 0 ? res : 0;
>> }
>>
>> /*
>> --- 1069,1075 ----
>>
>> while (res > 0)
>> res = pullf_read(pkt, 32 * 1024, &tmp);
>> ! return res;
>
> Why is the old code silly and the new code correct?

When the loop terminates, res can only be <= 0. If res is less than 0,
res is returned. In all other cases (i.e. when res == 0), 0 is
returned. The ternary expression is completely unnecessary.

.marko

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2014-11-02 22:42:53 Re: Let's drop two obsolete features which are bear-traps for novices
Previous Message Tomas Vondra 2014-11-02 21:51:31 Re: Silly coding in pgcrypto