diff options
author | Dan Fandrich <dan@coneharvesters.com> | 2007-03-06 19:55:11 +0000 |
---|---|---|
committer | Dan Fandrich <dan@coneharvesters.com> | 2007-03-06 19:55:11 +0000 |
commit | 4c3568bfd644e977cc6d56be6af56a29bea0cf5b (patch) | |
tree | c7c3021a746b681d188e0c1183127a5b72a4c9eb /src | |
parent | b4ef5e22e06ab8cb88394f2b92ff17e20ded8272 (diff) |
Fixed a couple of problems detected by valgrind in test cases 181 & 216
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/main.c b/src/main.c index a48be2437..fcc519245 100644 --- a/src/main.c +++ b/src/main.c @@ -787,17 +787,21 @@ static char *file2memory(FILE *file, long *size) if(file) { while((len = fread(buffer, 1, sizeof(buffer), file))) { if(string) { - newstring = realloc(string, len+stringlen); + newstring = realloc(string, len+stringlen+1); if(newstring) string = newstring; else break; /* no more strings attached! :-) */ } else - string = malloc(len); + string = malloc(len+1); memcpy(&string[stringlen], buffer, len); stringlen+=len; } + if (string) { + /* NUL terminate the buffer in case it's treated as a string later */ + string[stringlen] = 0; + } *size = stringlen; 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 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); else if(pval) { snprintf(value, sizeof(value), "%p", pval); |