Re: log message in proto.c

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: log message in proto.c
Date: 2019-09-24 17:15:59
Message-ID: CA+Tgmob1vsEr+kPrWjqdr7QK7Gx8R3mX4G+Ha9pwrQys66Hupw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Sep 24, 2019 at 5:41 AM Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:
> src/backend/replication/logical/proto.c
> action = pq_getmsgbyte(in);
> if (action != 'N')
> elog(ERROR, "expected new tuple but got %d",
> action);
>
> "%d" in the above message should be "%c" because the type of
> the variable "action" is char? There are other log messages that
> "%c" is used for such variable, in proto.c. Seems the above is
> only message that "%d" is used for such variable.

The potential problem with using %c to print characters is that the
character might be a null byte or something else that ends up making
the log file invalid under the relevant encoding.

However, if the goal of using %d is to protect against such problems,
it has to be done consistently.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2019-09-24 17:53:03 Re: WIP/PoC for parallel backup
Previous Message Tom Lane 2019-09-24 16:43:17 Re: PostgreSQL12 and older versions of OpenSSL