redisAssert(o->encoding == REDIS_ENCODING_HT);
de = dictFind(o->ptr, field);
- if (de == NULL) {
- return -1;
- }
-
+ if (de == NULL) return -1;
*value = dictGetVal(de);
return 0;
}
incrRefCount(aux);
value = aux;
}
-
} else {
redisPanic("Unknown hash encoding");
}
-
return value;
}
unsigned int vlen = UINT_MAX;
long long vll = LLONG_MAX;
- if (hashTypeGetFromZiplist(o, field, &vstr, &vlen, &vll) == 0) {
- return 1;
- }
-
+ if (hashTypeGetFromZiplist(o, field, &vstr, &vlen, &vll) == 0) return 1;
} else if (o->encoding == REDIS_ENCODING_HT) {
robj *aux;
- if (hashTypeGetFromHashTable(o, field, &aux) == 0) {
- return 1;
- }
-
+ if (hashTypeGetFromHashTable(o, field, &aux) == 0) return 1;
} else {
redisPanic("Unknown hash encoding");
}
-
return 0;
}
redisAssert(vptr != NULL);
fptr = ziplistNext(zl, vptr);
}
-
- if (fptr == NULL) {
- return REDIS_ERR;
- }
+ if (fptr == NULL) return REDIS_ERR;
/* Grab pointer to the value (fptr points to the field) */
vptr = ziplistNext(zl, fptr);
/* fptr, vptr now point to the first or next pair */
hi->fptr = fptr;
hi->vptr = vptr;
-
} else if (hi->encoding == REDIS_ENCODING_HT) {
- if ((hi->de = dictNext(hi->di)) == NULL) {
- return REDIS_ERR;
- }
-
+ if ((hi->de = dictNext(hi->di)) == NULL) return REDIS_ERR;
} else {
redisPanic("Unknown hash encoding");
}
-
return REDIS_OK;
}
}
void hincrbyCommand(redisClient *c) {
- long long value, incr;
+ long long value, incr, oldvalue;
robj *o, *current, *new;
if (getLongLongFromObjectOrReply(c,c->argv[3],&incr,NULL) != REDIS_OK) return;
value = 0;
}
+ oldvalue = value;
+ if ((incr < 0 && oldvalue < 0 && incr < (LLONG_MIN-oldvalue)) ||
+ (incr > 0 && oldvalue > 0 && incr > (LLONG_MAX-oldvalue))) {
+ addReplyError(c,"increment or decrement would overflow");
+ return;
+ }
value += incr;
new = createStringObjectFromLongLong(value);
hashTypeTryObjectEncoding(o,&c->argv[2],NULL);