Re: pgsql: Fix pg_size_pretty() to avoid overflow for inputs close to INT64

Поиск
Список
Период
Сортировка
От Dave Page
Тема Re: pgsql: Fix pg_size_pretty() to avoid overflow for inputs close to INT64
Дата
Msg-id BANLkTinyNpGi5wUh=HnHE-FFo3yrRQ1cRQ@mail.gmail.com
обсуждение исходный текст
Ответ на Re: pgsql: Fix pg_size_pretty() to avoid overflow for inputs close to INT64  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-committers
Looks like you committed this before I got to it - moa is green, so I
guess it works.

Thanks.

On Thursday, April 28, 2011, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Please see if the attached version works.
>
>                         regards, tom lane
>
>
> Datum
> pg_size_pretty(PG_FUNCTION_ARGS)
> {
>         int64           size = PG_GETARG_INT64(0);
>         char            buf[64];
>         int64           limit = 10 * 1024;
>         int64           limit2 = limit * 2 - 1;
>
>         if (size < limit)
>                 snprintf(buf, sizeof(buf), INT64_FORMAT " bytes", size);
>         else
>         {
>                 size >>= 9;                             /* keep one extra bit for rounding */
>                 if (size < limit2)
>                         snprintf(buf, sizeof(buf), INT64_FORMAT " kB",
>                                          (size + 1) / 2);
>                 else
>                 {
>                         size >>= 10;
>                         if (size < limit2)
>                                 snprintf(buf, sizeof(buf), INT64_FORMAT " MB",
>                                                  (size + 1) / 2);
>                         else
>                         {
>                                 size >>= 10;
>                                 if (size < limit2)
>                                         snprintf(buf, sizeof(buf), INT64_FORMAT " GB",
>                                                          (size + 1) / 2);
>                                 else
>                                 {
>                                         size >>= 10;
>                                         snprintf(buf, sizeof(buf), INT64_FORMAT " TB",
>                                                          (size + 1) / 2);
>                                 }
>                         }
>                 }
>         }
>
>         PG_RETURN_TEXT_P(cstring_to_text(buf));
> }
>

--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

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

Предыдущее
От: Bruce Momjian
Дата:
Сообщение: pgsql: Lowercase status labels in pg_stat_replication view.
Следующее
От: Tom Lane
Дата:
Сообщение: pgsql: Make CLUSTER lock the old table's toast table before copying dat