Commit 1437a56a authored by Max Kellermann's avatar Max Kellermann

input_curl: added local variable "value"

Replaced the local variable "colon" (which had only temporary meaning) with the variable "value". It is a pointer to the first byte of the header value.
parent d401589e
...@@ -279,35 +279,43 @@ static size_t ...@@ -279,35 +279,43 @@ static size_t
input_curl_headerfunction(void *ptr, size_t size, size_t nmemb, void *stream) input_curl_headerfunction(void *ptr, size_t size, size_t nmemb, void *stream)
{ {
struct input_stream *is = stream; struct input_stream *is = stream;
const char *header = ptr, *end, *colon; const char *header = ptr, *end, *value;
char name[64]; char name[64];
size *= nmemb; size *= nmemb;
end = header + size; end = header + size;
colon = memchr(header, ':', size); value = memchr(header, ':', size);
if (colon == NULL || (size_t)(colon - header) >= sizeof(name)) if (value == NULL || (size_t)(value - header) >= sizeof(name))
return size; return size;
memcpy(name, header, colon - header); memcpy(name, header, value - header);
name[colon - header] = 0; name[value - header] = 0;
/* skip the colon */
++value;
/* strip the value */
while (value < end && g_ascii_isspace(*value))
++value;
while (end > value && g_ascii_isspace(end[-1]))
--end;
if (strcasecmp(name, "accept-ranges") == 0) if (strcasecmp(name, "accept-ranges") == 0)
is->seekable = true; is->seekable = true;
else if (strcasecmp(name, "content-length") == 0) { else if (strcasecmp(name, "content-length") == 0) {
char value[64]; char buffer[64];
header = colon + 1;
while (header < end && header[0] == ' ')
++header;
if ((size_t)(end - header) >= sizeof(value)) if ((size_t)(end - header) >= sizeof(buffer))
return size; return size;
memcpy(value, header, end - header); memcpy(buffer, value, end - value);
value[end - header] = 0; buffer[end - value] = 0;
is->size = is->offset + g_ascii_strtoull(value, NULL, 10); is->size = is->offset + g_ascii_strtoull(buffer, NULL, 10);
} }
return size; return size;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment