aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2004-05-12 08:26:56 +0000
committerDaniel Stenberg <daniel@haxx.se>2004-05-12 08:26:56 +0000
commitd301d69fbf0342b9510751dcf478487b2e710684 (patch)
tree40d921f89263922af1478b87e0f91f08faad44b2
parent34af02caca301a44f54c2df371f957a69e949df1 (diff)
bail out if we can't allocate the new range string, and make use of aprintf()
instead of using snprintf() + strdup().
-rw-r--r--lib/url.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/lib/url.c b/lib/url.c
index 99e239aa8..2d10998ab 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -2036,7 +2036,6 @@ static CURLcode CreateConnection(struct SessionHandle *data,
{
char *tmp;
CURLcode result=CURLE_OK;
- char resumerange[40]="";
struct connectdata *conn;
struct connectdata *conn_temp;
int urllen;
@@ -2484,9 +2483,9 @@ static CURLcode CreateConnection(struct SessionHandle *data,
if(conn->resume_from) {
if(!conn->bits.use_range) {
/* if it already was in use, we just skip this */
- snprintf(resumerange, sizeof(resumerange), "%" FORMAT_OFF_T "-",
- conn->resume_from);
- conn->range=strdup(resumerange); /* tell ourselves to fetch this range */
+ conn->range = aprintf("%" FORMAT_OFF_T "-", conn->resume_from);
+ if(!conn->range)
+ return CURLE_OUT_OF_MEMORY;
conn->bits.rangestringalloc = TRUE; /* mark as allocated */
conn->bits.use_range = 1; /* switch on range usage */
}
@@ -3004,19 +3003,21 @@ static CURLcode CreateConnection(struct SessionHandle *data,
*/
conn->resume_from = data->set.set_resume_from;
if (conn->resume_from) {
- snprintf(resumerange, sizeof(resumerange), "%" FORMAT_OFF_T "-",
- conn->resume_from);
if (conn->bits.rangestringalloc == TRUE)
free(conn->range);
+ conn->range = aprintf("%" FORMAT_OFF_T "-", conn->resume_from);
+ if(!conn->range)
+ return CURLE_OUT_OF_MEMORY;
/* tell ourselves to fetch this range */
- conn->range = strdup(resumerange);
conn->bits.use_range = TRUE; /* enable range download */
conn->bits.rangestringalloc = TRUE; /* mark range string allocated */
}
else if (data->set.set_range) {
/* There is a range, but is not a resume, useful for random ftp access */
conn->range = strdup(data->set.set_range);
+ if(!conn->range)
+ return CURLE_OUT_OF_MEMORY;
conn->bits.rangestringalloc = TRUE; /* mark range string allocated */
conn->bits.use_range = TRUE; /* enable range download */
}