pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Frankie Lam <frankie@ucr.com.hk>
To: pgsql-interfaces@postgresql.org
Subject: Re: Segmentation Fault
Date: Thu, 3 Apr 2003 17:31:16 +0800
Message-ID: <b6gutt$18tj$1@news.hub.org> (raw)
References: <b6gku9$2llu$1@news.hub.org>

Oh, I'm so sorry....
I've made a stupid mistake... and this mistake is at the cost of 3 days
work.
The segmentation fault is totally irrelevant to the time functions in
previous thread.

Buggy Code Fragment FYI
--8<------------------------
..
..
   len =strlen(PQgetvalue(res, 0, i)) * 2 + 1;  // <=========
   printf("***********length=%d\n", len);
   tmp2 = (char *) calloc(sizeof(char), len);
   strcat(p2, "'");

   PQescapeString(tmp2, PQgetvalue(res, 0, i), len); // <========= this
line,
   // PQescapeString won't stop at '\0', so it will go out
   // of range of the returning value by PQgetvalue().

   strcat(p2, tmp2);
   strcat(p2, "', ");
   free(tmp2);
   tmp2 = NULL;
..
..
---------->8--------------

Here I have one more question, is there any debugging tools other than GDB?
I'm not quite used to it, debugging segmentation fault is really a pain. :-(

Thx,
Frankie Lam

"Frankie Lam" <frankie@ucr.com.hk> wrote in message
news:b6gku9$2llu$1@news.hub.org...
> Hi,
>
> I want to ask what does the error message mean by
> "0x40023abb in resetPQExpBuffer () from /usr/local/pgsql/lib/libpq.so.3"?
> I got this message using GDB to trace the program.
> (Segmentation fault occurswhen run the program directly.)
>
> I reviewed the program many times, and found this is only to happen when
> I call the `ctime()'  or `time()' in a program function.
>
> code fragment FYI
> --8<------------------------
> // `res = PQexec(conn, sql)' here..
> ...
> ...
>   }
>   else if (!strcmp(PQfname(res, i), SYNCTIME_FIELD_NAME))
>   {
> //   puts("7");
>    //char chP[30];
>    printf("timer=%ld\n", time(timer)); // <====== without this line, the
> program works
> //   printf("%s", ctime(time(NULL)));
> //   printf("%s", asctime(localtime(&timer)));
>    sprintf(tmp, "'1999-12-11 09:50:58'::timestamp, ");
>    strcat(p2, tmp);
>   }
>   else if (!strcmp(PQfname(res, i), SERVERID_FIELD_NAME))
>   {
>    puts("8");
>    sprintf(tmp, "'%s'", PQgetvalue(res, 0, i));
>    strcat(p2, tmp);
>   }
>  }
> ...
> ...
> freeing resources here
> ---------->8--------------
>
> Thank you very much.
>
> Frankie Lam.
>
>




view thread (10+ messages)  latest in thread

Message-ID: <b6gutt$18tj$1@news.hub.org>
Permalink:  ../b6gutt$18tj$1@news.hub.org/
Also on:    postgresql.org/message-id/b6gutt$18tj$1@news.hub.org

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: frankie@ucr.com.hk
  Subject: Re: Segmentation Fault
  In-Reply-To: <b6gutt$18tj$1@news.hub.org>

* 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