[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pecl-cvs
Subject:    [PECL-CVS] =?utf-8?q?svn:_/pecl/dbase/trunk/_dbase.c?=
From:       Christoph_Michael_Becker <cmb () php ! net>
Date:       2016-10-30 8:24:24
Message-ID: svn-cmb-1477815864-340794-913111050 () svn ! php ! net
[Download RAW message or body]

cmb                                      Sun, 30 Oct 2016 08:24:24 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=340794

Log:
Simplify writing of floats

There is no need to write floats directly to the output buffer. Instead
it suffices to only do the string conversion and let snprintf() do the
actual writing.

Changed paths:
    U   pecl/dbase/trunk/dbase.c

Modified: pecl/dbase/trunk/dbase.c
===================================================================
--- pecl/dbase/trunk/dbase.c	2016-10-30 05:17:34 UTC (rev 340793)
+++ pecl/dbase/trunk/dbase.c	2016-10-30 08:24:24 UTC (rev 340794)
@@ -234,24 +234,18 @@
 			RETURN_FALSE;
 		}

+		/* force cast to string as if in C locale */
 		if (Z_TYPE_P(field) == IS_DOUBLE) {
 			zend_string *formatted;
-			size_t formatted_len;

 			formatted = _php_math_number_format_ex(Z_DVAL_P(field), cur_f->db_fdc, ".", 1, "", 0);
-			formatted_len = ZSTR_LEN(formatted);
-			if (formatted_len <= cur_f->db_flen) {
-				size_t delta = cur_f->db_flen - formatted_len;
-				memset(t_cp, ' ', delta);
-				memcpy(t_cp + delta, ZSTR_VAL(formatted), formatted_len);
-			} else {
-				memcpy(t_cp, ZSTR_VAL(formatted), cur_f->db_flen);
-			}
+			ZVAL_STRING(field, ZSTR_VAL(formatted));
 			zend_string_free(formatted);
-		} else {
-			convert_to_string(field);
-			snprintf(t_cp, cur_f->db_flen+1, cur_f->db_format, Z_STRVAL_P(field));
 		}
+
+		convert_to_string(field);
+		snprintf(t_cp, cur_f->db_flen+1, cur_f->db_format, Z_STRVAL_P(field));
+
 		t_cp += cur_f->db_flen;
 	}




-- 
PECL CVS Mailing List 
To unsubscribe, visit: http://www.php.net/unsub.php

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic