#include "redis.h"
#include <math.h>
+#include <ctype.h>
robj *createObject(int type, void *ptr) {
robj *o = zmalloc(sizeof(*o));
if (o->encoding == REDIS_ENCODING_RAW) {
errno = 0;
value = strtod(o->ptr, &eptr);
- if (eptr[0] != '\0' || errno == ERANGE || isnan(value))
+ if (isspace(((char*)o->ptr)[0]) || eptr[0] != '\0' ||
+ errno == ERANGE || isnan(value))
return REDIS_ERR;
} else if (o->encoding == REDIS_ENCODING_INT) {
value = (long)o->ptr;
redisPanic("Unknown string encoding");
}
}
-
*target = value;
return REDIS_OK;
}
}
return REDIS_ERR;
}
-
*target = value;
return REDIS_OK;
}
if (o->encoding == REDIS_ENCODING_RAW) {
errno = 0;
value = strtold(o->ptr, &eptr);
- if (eptr[0] != '\0' || errno == ERANGE || isnan(value))
+ if (isspace(((char*)o->ptr)[0]) || eptr[0] != '\0' ||
+ errno == ERANGE || isnan(value))
return REDIS_ERR;
} else if (o->encoding == REDIS_ENCODING_INT) {
value = (long)o->ptr;
}
return REDIS_ERR;
}
-
*target = value;
return REDIS_OK;
}
} else {
redisAssertWithInfo(NULL,o,o->type == REDIS_STRING);
if (o->encoding == REDIS_ENCODING_RAW) {
+ errno = 0;
value = strtoll(o->ptr, &eptr, 10);
- if (eptr[0] != '\0') return REDIS_ERR;
- if (errno == ERANGE && (value == LLONG_MIN || value == LLONG_MAX))
+ if (isspace(((char*)o->ptr)[0]) || eptr[0] != '\0' ||
+ errno == ERANGE)
return REDIS_ERR;
} else if (o->encoding == REDIS_ENCODING_INT) {
value = (long)o->ptr;
redisPanic("Unknown string encoding");
}
}
-
if (target) *target = value;
return REDIS_OK;
}
}
return REDIS_ERR;
}
-
*target = value;
return REDIS_OK;
}
}
return REDIS_ERR;
}
-
*target = value;
return REDIS_OK;
}