diff options
Diffstat (limited to 'src/rdb.c')
-rw-r--r-- | src/rdb.c | 25 |
1 files changed, 10 insertions, 15 deletions
@@ -588,22 +588,11 @@ int rdbSaveDoubleValue(rio *rdb, double val) { len = 1; buf[0] = (val < 0) ? 255 : 254; } else { -#if (DBL_MANT_DIG >= 52) && (LLONG_MAX == 0x7fffffffffffffffLL) - /* Check if the float is in a safe range to be casted into a - * long long. We are assuming that long long is 64 bit here. - * Also we are assuming that there are no implementations around where - * double has precision < 52 bit. - * - * Under this assumptions we test if a double is inside an interval - * where casting to long long is safe. Then using two castings we - * make sure the decimal part is zero. If all this is true we use - * integer printing function that is much faster. */ - double min = -4503599627370495; /* (2^52)-1 */ - double max = 4503599627370496; /* -(2^52) */ - if (val > min && val < max && val == ((double)((long long)val))) - ll2string((char*)buf+1,sizeof(buf)-1,(long long)val); + long long lvalue; + /* Integer printing function is much faster, check if we can safely use it. */ + if (double2ll(val, &lvalue)) + ll2string((char*)buf+1,sizeof(buf)-1,lvalue); else -#endif snprintf((char*)buf+1,sizeof(buf)-1,"%.17g",val); buf[0] = strlen((char*)buf+1); len = buf[0]+1; @@ -2433,6 +2422,12 @@ robj *rdbLoadObject(int rdbtype, rio *rdb, sds key, int dbid, int *error) { return NULL; } + if (s->length && !raxSize(s->rax)) { + rdbReportCorruptRDB("Stream length inconsistent with rax entries"); + decrRefCount(o); + return NULL; + } + /* Consumer groups loading */ uint64_t cgroups_count = rdbLoadLen(rdb,NULL); if (cgroups_count == RDB_LENERR) { |