Why not use the calloc to replace malloc?

Поиск
Список
Период
Сортировка
От Wen Yi
Тема Why not use the calloc to replace malloc?
Дата
Msg-id TYAP286MB0636A72D4EC3E52779FDB4F0A9669@TYAP286MB0636.JPNP286.PROD.OUTLOOK.COM
обсуждение исходный текст
Ответы Re: Why not use the calloc to replace malloc?  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
HI team,
I'm a newbie to the postgres.
When I learn the code of libpq, the achieve of PQmakeEmptyPGresult, cause my  curiosity.

The old version code:
 
PQmakeEmptyPGresult(PGconn *conn, ExecStatusType status)
{
      PGresult   *result;

      result = (PGresult *) malloc(sizeof(PGresult));
      if (!result)
            return NULL;

      result->ntups = 0;
      result->numAttributes = 0;
      result->attDescs = NULL;
      result->tuples = NULL;
      result->tupArrSize = 0;
      result->numParameters = 0;
      result->paramDescs = NULL;
      result->resultStatus = status;
      result->cmdStatus[0] = '\0';
      result->binary = 0;
      result->events = NULL;
      result->nEvents = 0;
      result->errMsg = NULL;
      result->errFields = NULL;
      result->errQuery = NULL;
      result->null_field[0] = '\0';
      result->curBlock = NULL;
      result->curOffset = 0;
      result->spaceLeft = 0;
      result->memorySize = sizeof(PGresult);
      /*
            .............
      */
      return result;
}

My version:

PQmakeEmptyPGresult(PGconn *conn, ExecStatusType status)
{
      PGresult   *result;

      result = (PGresult *) calloc(sizeof(PGresult));
      if (!result)
            return NULL;

      result->memorySize = sizeof(PGresult);
      /*
            .............
      */
      return result;
}

Why not have a change?I don't know.
I'm a newbie, so I don't think I can commit a patch for postgres, just instead of send mail to ask.

Yours,
Wenyi.

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: SCROLLABLE/UPDATABLE cursor question
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Why not use the calloc to replace malloc?