From fa7cba7d5d55e07fdf12dc1f7595d185e702c2e5 Mon Sep 17 00:00:00 2001 From: Sascha Schumann Date: Sun, 27 Jun 1999 21:23:17 +0000 Subject: [PATCH] port over from php3 --- ext/dbase/dbase.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/ext/dbase/dbase.c b/ext/dbase/dbase.c index e7639651dc..6823619cfa 100644 --- a/ext/dbase/dbase.c +++ b/ext/dbase/dbase.c @@ -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) | +----------------------------------------------------------------------+ @@ -32,6 +32,10 @@ #include +#ifdef HAVE_SYS_TYPES_H +#include +#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) { -- 2.40.0