Author: turnstep
Date: Sun Aug 19 15:19:26 2007
New Revision: 9862

Modified:
   DBD-Pg/trunk/Pg.xs
   DBD-Pg/trunk/dbdimp.c
   DBD-Pg/trunk/dbdimp.h

Log:
Better SV slinging in pg_getline, from Andrew Dunstan (Dec 29, 2006)


Modified: DBD-Pg/trunk/Pg.xs
==============================================================================
--- DBD-Pg/trunk/Pg.xs  (original)
+++ DBD-Pg/trunk/Pg.xs  Sun Aug 19 15:19:26 2007
@@ -512,7 +512,7 @@
                buf = SvGROW(bufsv, 3);
                if (len > 3)
                        buf = SvGROW(bufsv, len);
-               ret = pg_db_getline(dbh, buf, (int)len);
+               ret = pg_db_getline(dbh, bufsv, (int)len);
                sv_setpv((SV*)ST(1), buf);
                SvSETMAGIC(ST(1));
                ST(0) = (-1 != ret) ? &sv_yes : &sv_no;
@@ -532,7 +532,7 @@
                buf = SvGROW(bufsv, 3);
                if (len > 3)
                        buf = SvGROW(bufsv, len);
-               ret = pg_db_getline(dbh, buf, (int)len);
+               ret = pg_db_getline(dbh, bufsv, (int)len);
                sv_setpv((SV*)ST(1), buf);
                SvSETMAGIC(ST(1));
                ST(0) = (-1 != ret) ? &sv_yes : &sv_no;

Modified: DBD-Pg/trunk/dbdimp.c
==============================================================================
--- DBD-Pg/trunk/dbdimp.c       (original)
+++ DBD-Pg/trunk/dbdimp.c       Sun Aug 19 15:19:26 2007
@@ -3232,11 +3232,14 @@
 
 /* ================================================================== */
 int
-pg_db_getline (SV * dbh, char * buffer, int length)
+pg_db_getline (SV * dbh, SV * svbuf, int length)
 {
        D_imp_dbh(dbh);
        int    copystatus;
        char * tempbuf;
+       char * buffer;
+
+       buffer = SvPV_nolen(svbuf);
 
        if (dbis->debug >= 4)
                (void)PerlIO_printf(DBILOGFP, "dbdpg: pg_db_getline\n");
@@ -3262,8 +3265,7 @@
                pg_error(dbh, PGRES_FATAL_ERROR, PQerrorMessage(imp_dbh->conn));
        }
        else {
-               strncpy(buffer, tempbuf, strlen(tempbuf)+1);
-               buffer[strlen(tempbuf)] = '\0';
+               sv_setpv(svbuf, tempbuf);
                PQfreemem(tempbuf);
        }
        return 0;

Modified: DBD-Pg/trunk/dbdimp.h
==============================================================================
--- DBD-Pg/trunk/dbdimp.h       (original)
+++ DBD-Pg/trunk/dbdimp.h       Sun Aug 19 15:19:26 2007
@@ -110,7 +110,7 @@
 int dbd_db_getfd (SV *dbh, imp_dbh_t *imp_dbh);
 SV * dbd_db_pg_notifies (SV *dbh, imp_dbh_t *imp_dbh);
 int pg_db_putline (SV *dbh, const char *buffer);
-int pg_db_getline (SV *dbh, char *buffer, int length);
+int pg_db_getline (SV *dbh, SV * svbuf, int length);
 int pg_db_endcopy (SV * dbh);
 void pg_db_pg_server_trace (SV *dbh, FILE *fh);
 void pg_db_pg_server_untrace (SV *dbh);

Reply via email to