pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Wen Yi <chuxuec@outlook.com>
To: PostgreSQL General <pgsql-general@lists.postgresql.org>
Subject: Why not use the calloc to replace malloc?
Date: Sun, 23 Apr 2023 03:44:32 +0000
Message-ID: <TYAP286MB0636A72D4EC3E52779FDB4F0A9669@TYAP286MB0636.JPNP286.PROD.OUTLOOK.COM> (raw)

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.


view thread (4+ messages)  latest in thread

Message-ID: <TYAP286MB0636A72D4EC3E52779FDB4F0A9669@TYAP286MB0636.JPNP286.PROD.OUTLOOK.COM>
Permalink:  ../TYAP286MB0636A72D4EC3E52779FDB4F0A9669@TYAP286MB0636.JPNP286.PROD.OUTLOOK.COM/
Also on:    postgresql.org/message-id/TYAP286MB0636A72D4EC3E52779FDB4F0A9669@TYAP286MB0636.JPNP286.PROD.OUTLOOK.COM

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: chuxuec@outlook.com
  Subject: Re: Why not use the calloc to replace malloc?
  In-Reply-To: <TYAP286MB0636A72D4EC3E52779FDB4F0A9669@TYAP286MB0636.JPNP286.PROD.OUTLOOK.COM>
  References: <TYAP286MB0636A72D4EC3E52779FDB4F0A9669@TYAP286MB0636.JPNP286.PROD.OUTLOOK.COM>

* 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