Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix for double values on older PHP versions.

  • Loading branch information...
commit f283d361acbe8914bbd97246bd18265ad6588b7a 1 parent 12769b0
@nicolasff nicolasff authored
Showing with 15 additions and 4 deletions.
  1. +14 −3 library.c
  2. +1 −1  library.h
View
17 library.c
@@ -163,9 +163,15 @@ integer_length(int i) {
}
int
-double_length(double d) {
+double_length(double d, int *has_F) {
char *s;
int ret = spprintf(&s, 0, "%F", d);
+ *has_F = 1;
+ if(ret == 2 && strncmp(s, "%F", 2) == 0) { /* we don't have the 'F' format, get back to 'f' */
+ efree(s);
+ ret = spprintf(&s, 0, "%f", d);
+ *has_F = 0;
+ }
efree(s);
return ret;
}
@@ -227,7 +233,8 @@ redis_cmd_format_static(char **ret, char *keyword, char *format, ...) {
case 'f':
/* use spprintf here */
dbl = va_arg(ap, double);
- sz = double_length(dbl);
+ int has_F;
+ sz = double_length(dbl, &has_F);
if(stage == 1) {
memcpy((*ret) + total, "$", 1); /* dollar */
total++;
@@ -238,7 +245,11 @@ redis_cmd_format_static(char **ret, char *keyword, char *format, ...) {
memcpy((*ret) + total, _NL, 2); /* CRLF */
total += 2;
- sprintf((*ret) + total, "%F", dbl); /* float */
+ if(has_F) {
+ sprintf((*ret) + total, "%F", dbl); /* float */
+ } else {
+ sprintf((*ret) + total, "%f", dbl); /* float */
+ }
total += sz;
memcpy((*ret) + total, _NL, 2); /* CRLF */
View
2  library.h
@@ -1,6 +1,6 @@
void add_constant_long(zend_class_entry *ce, char *name, int value);
int integer_length(int i);
-int double_length(double d);
+int double_length(double d, int *has_F);
int redis_cmd_format(char **ret, char *format, ...);
PHPAPI char * redis_sock_read(RedisSock *redis_sock, int *buf_len TSRMLS_DC);
Please sign in to comment.
Something went wrong with that request. Please try again.