Hi!


On Tue, 5 May 1998, Henrik Nordstrom wrote:

> Marin D wrote:
> 
> > where PQgetvalue() returns a number as string.
> > 
> > For example while debugging PQgetvalue() returns "0" but lTotalInc
> > is not assigned 0 and stays unitialized.
> 
> A long shot, but how is PGgetvalue allocating the returned string? My
> first thought is a local (stack-based) array, that gets overwritten by
> the sscanf call.

Actually the passage is:

 SQLexec(pConnection,szQuery,&pResTemp,PGRES_TUPLES_OK);
 sscanf(PQgetvalue(pResTemp,0,1),"%ld",&lTotalInc);


pResTemp is pointer to a struct which contains the results of the
query, the status , so on. When the struct is filled the memory is
malloc-ated in the normal way. 

SQLexec() is a wrapper function which 
 
 1.calls PQclear() which frees the memory asociated with the pResTemp
   structure for its previous contents (if any)
 
 2.allocates space for the data returned as string,copies the data and
   assigns pResTemp the new address

PQgetvalue() just returns pointer to the appropriate part of the structure


And if the string was stack-based why would it be broken only after
optimizations? 

Thanx for the attention!

        Marin


                   -= What was my .signature guys? =-


Reply via email to