Re: overflow in snprintf() when printing INT64_MIN

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: overflow in snprintf() when printing INT64_MIN
Date: 2018-09-28 00:18:12
Message-ID: 24646.1538093892@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Andres Freund <andres(at)anarazel(dot)de> writes:
> I just noticed, while reviewing a patch that corrects overflow handing
> in snprintf, that we don't correctly handle INT64_MIN in snprintf.c:

Well, you still get the right answer, even if the "-value" is
nominally undefined.

> I suspect the best way to fix this, would be to instead do:

> /* Handle +/- */
> if (dosign && adjust_sign((value < 0), forcesign, &signvalue);
> uvalue = -(uint64) value;
> else
> uvalue = (uint64) value;

Hm, what does -x mean for an unsigned value? I'm not really
convinced this is conceptually better.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2018-09-28 00:23:07 Re: [patch]overallocate memory for curly braces in array_out
Previous Message Andres Freund 2018-09-28 00:11:21 overflow in snprintf() when printing INT64_MIN