/*
+--------------------------------------------------------------------+
- | libmemcached - C/C++ Client Library for memcached |
+ | libmemcached-awesome - C/C++ Client Library for memcached |
+--------------------------------------------------------------------+
| Redistribution and use in source and binary forms, with or without |
| modification, are permitted under the terms of the BSD license. |
| the terms online at: https://opensource.org/licenses/BSD-3-Clause |
+--------------------------------------------------------------------+
| Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ |
- | Copyright (c) 2020 Michael Wallner <mike@php.net> |
+ | Copyright (c) 2020-2021 Michael Wallner https://awesome.co/ |
+--------------------------------------------------------------------+
*/
errno = 0;
result->item_flags = (uint32_t) strtoul(next_ptr, &string_ptr, 10);
- if (errno != 0 or end_ptr == string_ptr) {
+ if (errno or end_ptr == string_ptr) {
goto read_error;
}
errno = 0;
value_length = (size_t) strtoull(next_ptr, &string_ptr, 10);
- if (errno != 0 or end_ptr == string_ptr) {
+ if (errno or end_ptr == string_ptr) {
goto read_error;
}
result->item_cas = strtoull(next_ptr, &string_ptr, 10);
}
- if (errno != 0 or end_ptr < string_ptr) {
+ if (errno or end_ptr < string_ptr) {
goto read_error;
}
and buffer[5] == 'O' and buffer[6] == 'N') /* VERSION */
{
/* Find the space, and then move one past it to copy version */
- char *response_ptr = index(buffer, ' ');
+ char *response_ptr = strchr(buffer, ' ');
char *endptr;
errno = 0;
long int version = strtol(response_ptr, &endptr, 10);
- if (errno != 0 or version == LONG_MIN or version == LONG_MAX or version > UINT8_MAX
+ if (errno or version == LONG_MIN or version == LONG_MAX or version > UINT8_MAX
or version == 0) {
instance->major_version = instance->minor_version = instance->micro_version = UINT8_MAX;
return memcached_set_error(
endptr++;
errno = 0;
version = strtol(endptr, &endptr, 10);
- if (errno != 0 or version == LONG_MIN or version == LONG_MAX or version > UINT8_MAX) {
+ if (errno or version == LONG_MIN or version == LONG_MAX or version > UINT8_MAX) {
instance->major_version = instance->minor_version = instance->micro_version = UINT8_MAX;
return memcached_set_error(
*instance, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT,
endptr++;
errno = 0;
version = strtol(endptr, &endptr, 10);
- if (errno != 0 or version == LONG_MIN or version == LONG_MAX or version > UINT8_MAX) {
+ if (errno or version == LONG_MIN or version == LONG_MAX or version > UINT8_MAX) {
instance->major_version = instance->minor_version = instance->micro_version = UINT8_MAX;
return memcached_set_error(
*instance, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT,
result->numeric_value = UINT64_MAX;
return memcached_set_error(*instance, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT,
memcached_literal_param("Numeric response was out of range"));
- } else if (errno != 0) {
+ } else if (errno) {
result->numeric_value = UINT64_MAX;
return memcached_set_error(*instance, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT,
memcached_literal_param("Numeric response was out of range"));
return MEMCACHED_SUCCESS;
}
- default: break;
+ default:
+ break;
}
buffer[total_read] = 0;
} break;
case PROTOCOL_BINARY_CMD_SASL_LIST_MECHS: {
- if (header.response.keylen != 0 || bodylen + 1 > buffer_length) {
+ if (header.response.keylen || bodylen + 1 > buffer_length) {
return MEMCACHED_UNKNOWN_READ_FAILURE;
} else {
if ((rc = memcached_safe_read(instance, buffer, bodylen)) != MEMCACHED_SUCCESS) {
char *endptr;
errno = 0;
long int version = strtol(version_buffer, &endptr, 10);
- if (errno != 0 or version == LONG_MIN or version == LONG_MAX or version > UINT8_MAX
+ if (errno or version == LONG_MIN or version == LONG_MAX or version > UINT8_MAX
or version == 0) {
instance->major_version = instance->minor_version = instance->micro_version = UINT8_MAX;
return memcached_set_error(
endptr++;
errno = 0;
version = strtol(endptr, &endptr, 10);
- if (errno != 0 or version == LONG_MIN or version == LONG_MAX or version > UINT8_MAX) {
+ if (errno or version == LONG_MIN or version == LONG_MAX or version > UINT8_MAX) {
instance->major_version = instance->minor_version = instance->micro_version = UINT8_MAX;
return memcached_set_error(
*instance, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT,
endptr++;
errno = 0;
version = strtol(endptr, &endptr, 10);
- if (errno != 0 or version == LONG_MIN or version == LONG_MAX or version > UINT8_MAX) {
+ if (errno or version == LONG_MIN or version == LONG_MAX or version > UINT8_MAX) {
instance->major_version = instance->minor_version = instance->micro_version = UINT8_MAX;
return memcached_set_error(
*instance, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT,
case PROTOCOL_BINARY_CMD_ADDQ:
case PROTOCOL_BINARY_CMD_REPLACEQ:
case PROTOCOL_BINARY_CMD_APPENDQ:
- case PROTOCOL_BINARY_CMD_PREPENDQ: return MEMCACHED_FETCH_NOTFINISHED;
+ case PROTOCOL_BINARY_CMD_PREPENDQ:
+ return MEMCACHED_FETCH_NOTFINISHED;
- default: break;
+ default:
+ break;
}
}
rc = MEMCACHED_SUCCESS;
- if (header.response.status != 0) {
+ if (header.response.status) {
switch (header.response.status) {
- case PROTOCOL_BINARY_RESPONSE_KEY_ENOENT: rc = MEMCACHED_NOTFOUND; break;
+ case PROTOCOL_BINARY_RESPONSE_KEY_ENOENT:
+ rc = MEMCACHED_NOTFOUND;
+ break;
- case PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS: rc = MEMCACHED_DATA_EXISTS; break;
+ case PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS:
+ rc = MEMCACHED_DATA_EXISTS;
+ break;
- case PROTOCOL_BINARY_RESPONSE_NOT_STORED: rc = MEMCACHED_NOTSTORED; break;
+ case PROTOCOL_BINARY_RESPONSE_NOT_STORED:
+ rc = MEMCACHED_NOTSTORED;
+ break;
- case PROTOCOL_BINARY_RESPONSE_E2BIG: rc = MEMCACHED_E2BIG; break;
+ case PROTOCOL_BINARY_RESPONSE_E2BIG:
+ rc = MEMCACHED_E2BIG;
+ break;
- case PROTOCOL_BINARY_RESPONSE_ENOMEM: rc = MEMCACHED_MEMORY_ALLOCATION_FAILURE; break;
+ case PROTOCOL_BINARY_RESPONSE_ENOMEM:
+ rc = MEMCACHED_MEMORY_ALLOCATION_FAILURE;
+ break;
- case PROTOCOL_BINARY_RESPONSE_AUTH_CONTINUE: rc = MEMCACHED_AUTH_CONTINUE; break;
+ case PROTOCOL_BINARY_RESPONSE_AUTH_CONTINUE:
+ rc = MEMCACHED_AUTH_CONTINUE;
+ break;
- case PROTOCOL_BINARY_RESPONSE_AUTH_ERROR: rc = MEMCACHED_AUTH_FAILURE; break;
+ case PROTOCOL_BINARY_RESPONSE_AUTH_ERROR:
+ rc = MEMCACHED_AUTH_FAILURE;
+ break;
case PROTOCOL_BINARY_RESPONSE_EINVAL:
case PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND:
rc = textual_read_one_response(instance, buffer, buffer_length, result);
}
- if (memcached_fatal(rc) && rc != MEMCACHED_TIMEOUT) {
+ if (memcached_fatal(rc)) {
memcached_io_reset(instance);
}