Skip to content

Commit 120446c

Browse files
committed
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. git-svn-id: http://svn.php.net/repository/pecl/dbase/trunk@340794 c90b9560-bf6c-de11-be94-00142212c4b1
1 parent 26803ce commit 120446c

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

dbase.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -234,24 +234,18 @@ static void php_dbase_put_record(INTERNAL_FUNCTION_PARAMETERS, int replace)
234234
RETURN_FALSE;
235235
}
236236

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

241241
formatted = _php_math_number_format_ex(Z_DVAL_P(field), cur_f->db_fdc, ".", 1, "", 0);
242-
formatted_len = ZSTR_LEN(formatted);
243-
if (formatted_len <= cur_f->db_flen) {
244-
size_t delta = cur_f->db_flen - formatted_len;
245-
memset(t_cp, ' ', delta);
246-
memcpy(t_cp + delta, ZSTR_VAL(formatted), formatted_len);
247-
} else {
248-
memcpy(t_cp, ZSTR_VAL(formatted), cur_f->db_flen);
249-
}
242+
ZVAL_STRING(field, ZSTR_VAL(formatted));
250243
zend_string_free(formatted);
251-
} else {
252-
convert_to_string(field);
253-
snprintf(t_cp, cur_f->db_flen+1, cur_f->db_format, Z_STRVAL_P(field));
254244
}
245+
246+
convert_to_string(field);
247+
snprintf(t_cp, cur_f->db_flen+1, cur_f->db_format, Z_STRVAL_P(field));
248+
255249
t_cp += cur_f->db_flen;
256250
}
257251

0 commit comments

Comments
 (0)