pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tristan Partin <tristan@neon.tech>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-hackers@lists.postgresql.org
Subject: Re: Make psql ignore trailing semicolons in \sf, \ef, etc
Date: Tue, 09 Jan 2024 10:27:54 -0600
Message-ID: <CYABFFJZJJ6S.259AZSIMLI8JZ@neon.tech> (raw)
In-Reply-To: <2071227.1704758905@sss.pgh.pa.us>
References: <2012251.1704746912@sss.pgh.pa.us>
	<CY9PTB44QXST.3UGGRFU6HAYRX@neon.tech>
	<2071227.1704758905@sss.pgh.pa.us>

On Mon Jan 8, 2024 at 6:08 PM CST, Tom Lane wrote:
> "Tristan Partin" <tristan@neon.tech> writes:
> > On Mon Jan 8, 2024 at 2:48 PM CST, Tom Lane wrote:
> >> +                                                (isascii((unsigned char) mybuf.data[mybuf.len - 1]) &&
> >> +                                                 isspace((unsigned char) mybuf.data[mybuf.len - 1]))))
>
> > Seems like if there was going to be any sort of casting, it would be to 
> > an int, which is what the man page says for these two function, though 
> > isascii(3) explicitly mentions "unsigned char."
>
> Casting to unsigned char is our standard pattern for using these
> functions.  If "char" is signed (which is the only case in which
> this changes anything) then casting to int would imply sign-extension
> of the char's high-order bit, which is exactly what must not happen
> in order to produce a legal value to be passed to these functions.
> POSIX says:
>
>     The c argument is an int, the value of which the application shall
>     ensure is a character representable as an unsigned char or equal
>     to the value of the macro EOF. If the argument has any other
>     value, the behavior is undefined.
>
> If we cast to unsigned char, then the subsequent implicit cast to int
> will do zero-extension which is what we need.

Thanks for the explanation.

> > Small English nit-pick: I would drop the hyphen between semi and colons.
>
> Me too, except that it's spelled like that in nearby comments.
> Shall I change them all?

I'll leave it up to you. Patch looks good as-is.

-- 
Tristan Partin
Neon (https://neon.tech)





view thread (6+ messages)  latest in thread

Message-ID: <CYABFFJZJJ6S.259AZSIMLI8JZ@neon.tech>
Permalink:  ../CYABFFJZJJ6S.259AZSIMLI8JZ@neon.tech/
Also on:    postgresql.org/message-id/CYABFFJZJJ6S.259AZSIMLI8JZ@neon.tech

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: tristan@neon.tech, tgl@sss.pgh.pa.us, pgsql-hackers@lists.postgresql.org
  Subject: Re: Make psql ignore trailing semicolons in \sf, \ef, etc
  In-Reply-To: <CYABFFJZJJ6S.259AZSIMLI8JZ@neon.tech>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox