Fixed a couple of problems detected by valgrind in test cases 181 & 216
This commit is contained in:
parent
b4ef5e22e0
commit
4c3568bfd6
10
src/main.c
10
src/main.c
@ -787,17 +787,21 @@ static char *file2memory(FILE *file, long *size)
|
|||||||
if(file) {
|
if(file) {
|
||||||
while((len = fread(buffer, 1, sizeof(buffer), file))) {
|
while((len = fread(buffer, 1, sizeof(buffer), file))) {
|
||||||
if(string) {
|
if(string) {
|
||||||
newstring = realloc(string, len+stringlen);
|
newstring = realloc(string, len+stringlen+1);
|
||||||
if(newstring)
|
if(newstring)
|
||||||
string = newstring;
|
string = newstring;
|
||||||
else
|
else
|
||||||
break; /* no more strings attached! :-) */
|
break; /* no more strings attached! :-) */
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
string = malloc(len);
|
string = malloc(len+1);
|
||||||
memcpy(&string[stringlen], buffer, len);
|
memcpy(&string[stringlen], buffer, len);
|
||||||
stringlen+=len;
|
stringlen+=len;
|
||||||
}
|
}
|
||||||
|
if (string) {
|
||||||
|
/* NUL terminate the buffer in case it's treated as a string later */
|
||||||
|
string[stringlen] = 0;
|
||||||
|
}
|
||||||
*size = stringlen;
|
*size = stringlen;
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
@ -3333,7 +3337,7 @@ CURLcode _my_setopt(CURL *curl, const char *name, CURLoption tag, ...)
|
|||||||
}
|
}
|
||||||
/* attempt to figure out if it is a string (since the tag numerical doesn't
|
/* attempt to figure out if it is a string (since the tag numerical doesn't
|
||||||
offer this info) and then output it as a string if so */
|
offer this info) and then output it as a string if so */
|
||||||
else if(pval && isgraph(ptr[0]) && isgraph(ptr[1]))
|
else if(pval && isgraph(ptr[0]) && isgraph(ptr[1]) && isgraph(ptr[2]))
|
||||||
snprintf(value, sizeof(value), "\"%s\"", (char *)ptr);
|
snprintf(value, sizeof(value), "\"%s\"", (char *)ptr);
|
||||||
else if(pval) {
|
else if(pval) {
|
||||||
snprintf(value, sizeof(value), "%p", pval);
|
snprintf(value, sizeof(value), "%p", pval);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user