]> granicus.if.org Git - php/commitdiff
port over from php3
authorSascha Schumann <sas@php.net>
Sun, 27 Jun 1999 21:23:17 +0000 (21:23 +0000)
committerSascha Schumann <sas@php.net>
Sun, 27 Jun 1999 21:23:17 +0000 (21:23 +0000)
ext/dbase/dbase.c

index e7639651dc57ce7910511f1dda8b63f6a4994d88..6823619cfad8b76a700777598125e565084b15c0 100644 (file)
@@ -1,6 +1,6 @@
 /*
    +----------------------------------------------------------------------+
-   | PHP HTML Embedded Scripting Language Version 3.0                     |
+   | PHP HTML Embedded Scripting Language Version 4.0                     |
    +----------------------------------------------------------------------+
    | Copyright (c) 1997,1998 PHP Development Team (See Credits file)      |
    +----------------------------------------------------------------------+
 
 #include <stdlib.h>
 
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+
 #include "php.h"
 #include "safe_mode.h"
 #include "fopen-wrappers.h"
@@ -416,6 +420,7 @@ PHP_FUNCTION(dbase_get_record) {
        int dbh_type;
        dbfield_t *dbf, *cur_f;
        char *data, *fnp, *str_value;
+       size_t cursize = 0;
        DBase_TLS_VARS;
 
        if (ARG_COUNT(ht) != 2 || getParameters(ht,2,&dbh_id,&record)==FAILURE) {
@@ -441,11 +446,16 @@ PHP_FUNCTION(dbase_get_record) {
                RETURN_FALSE;
        }
 
-        fnp = (char *)emalloc(dbh->db_rlen);
+        fnp = NULL;
         for (cur_f = dbf; cur_f < &dbf[dbh->db_nfields]; cur_f++) {
                /* get the value */
                str_value = (char *)emalloc(cur_f->db_flen + 1);
-                sprintf(str_value, cur_f->db_format, get_field_val(data, cur_f, fnp));
+
+               if(cursize <= cur_f->db_flen) {
+                       cursize = cur_f->db_flen + 1;
+                       fnp = erealloc(fnp, cursize);
+               }
+                snprintf(str_value, cursize, cur_f->db_format, get_field_val(data, cur_f, fnp));
 
                /* now convert it to the right php internal type */
                switch (cur_f->db_type) {