Update for protocol (and a single fix).
[m6w6/libmemcached] / libmemcached / response.cc
index faf20ff94149f15448c4c6a36a7d0d456419cb37..4ba856489f81e9a16aa121a81843dbcc537e4bf9 100644 (file)
@@ -236,9 +236,9 @@ static memcached_return_t textual_read_one_response(memcached_server_write_insta
       {
         /* Find the space, and then move one past it to copy version */
         char *response_ptr= index(buffer, ' ');
-        response_ptr++;
 
-        long int version= strtol(response_ptr, (char **)NULL, 10);
+        char *endptr;
+        long int version= strtol(response_ptr, &endptr, 10);
         if (version == LONG_MIN or version == LONG_MAX or errno == EINVAL or version > UINT8_MAX or version == 0)
         {
           instance->major_version= instance->minor_version= instance->micro_version= UINT8_MAX;
@@ -246,10 +246,8 @@ static memcached_return_t textual_read_one_response(memcached_server_write_insta
         }
         instance->major_version= uint8_t(version);
 
-        response_ptr= index(response_ptr, '.');
-        response_ptr++;
-
-        version= strtol(response_ptr, (char **)NULL, 10);
+        endptr++;
+        version= strtol(endptr, &endptr, 10);
         if (version == LONG_MIN or version == LONG_MAX or errno == EINVAL or version > UINT8_MAX)
         {
           instance->major_version= instance->minor_version= instance->micro_version= UINT8_MAX;
@@ -257,10 +255,8 @@ static memcached_return_t textual_read_one_response(memcached_server_write_insta
         }
         instance->minor_version= uint8_t(version);
 
-        response_ptr= index(response_ptr, '.');
-        response_ptr++;
-
-        version= strtol(response_ptr, (char **)NULL, 10);
+        endptr++;
+        version= strtol(endptr, &endptr, 10);
         if (version == LONG_MIN or version == LONG_MAX or errno == EINVAL or version > UINT8_MAX)
         {
           instance->major_version= instance->minor_version= instance->micro_version= UINT8_MAX;
@@ -598,8 +594,8 @@ static memcached_return_t binary_read_one_response(memcached_server_write_instan
           return MEMCACHED_UNKNOWN_READ_FAILURE;
         }
 
-        char *p;
-        long int version= strtol(version_buffer, &p, 10);
+        char *endptr;
+        long int version= strtol(version_buffer, &endptr, 10);
         if (version == LONG_MIN or version == LONG_MAX or errno == EINVAL or version > UINT8_MAX or version == 0)
         {
           instance->major_version= instance->minor_version= instance->micro_version= UINT8_MAX;
@@ -607,16 +603,18 @@ static memcached_return_t binary_read_one_response(memcached_server_write_instan
         }
         instance->major_version= uint8_t(version);
 
-        version= strtol(p +1, &p, 10);
+        endptr++;
+        version= strtol(endptr, &endptr, 10);
         if (version == LONG_MIN or version == LONG_MAX or errno == EINVAL 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, memcached_literal_param("strtol() failed to parse micro version"));
+          return memcached_set_error(*instance, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT, memcached_literal_param("strtol() failed to parse minor version"));
         }
         instance->minor_version= uint8_t(version);
 
-        version= strtol(p + 1, NULL, 10);
-        if (errno == ERANGE)
+        endptr++;
+        version= strtol(endptr, &endptr, 10);
+        if (version == LONG_MIN or version == LONG_MAX or errno == EINVAL 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, memcached_literal_param("strtol() failed to parse micro version"));