Commit 4a51a2e7 authored by deuce's avatar deuce
Browse files

Don't use alloca() when possible (considered harmful)

parent b545a623
......@@ -252,7 +252,7 @@ int recvfilesocket(int sock, int file, off_t *offset, off_t count)
return(-1);
}
if((buf=(char*)alloca((size_t)count))==NULL) {
if((buf=(char*)malloc((size_t)count))==NULL) {
errno=ENOMEM;
return(-1);
}
......@@ -262,14 +262,17 @@ int recvfilesocket(int sock, int file, off_t *offset, off_t count)
return(-1);
rd=read(sock,buf,(size_t)count);
if(rd!=count)
if(rd!=count) {
free(buf);
return(-1);
}
wr=write(file,buf,rd);
if(offset!=NULL)
(*offset)+=wr;
free(buf);
return(wr);
}
......
......@@ -412,7 +412,7 @@ static str_list_t str_list_read_file(FILE* fp, str_list_t* lp, size_t max_line_l
if(fp!=NULL) {
count=strListCount(*lp);
while(!feof(fp)) {
if(buf==NULL && (buf=(char*)alloca(max_line_len+1))==NULL)
if(buf==NULL && (buf=(char*)malloc(max_line_len+1))==NULL)
return(NULL);
if(fgets(buf,max_line_len+1,fp)==NULL)
......@@ -420,6 +420,8 @@ static str_list_t str_list_read_file(FILE* fp, str_list_t* lp, size_t max_line_l
strListAppend(lp, buf, count++);
}
}
if(buf)
free(buf);
return(*lp);
}
......
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