mirror of
https://github.com/curl/curl.git
synced 2026-07-31 11:58:05 +03:00
remove unnecessary typecasting of malloc()
This commit is contained in:
parent
a622fd90b4
commit
59e378f48f
31 changed files with 68 additions and 72 deletions
|
|
@ -160,7 +160,7 @@ size_t Curl_base64_encode(struct SessionHandle *data,
|
|||
if(0 == insize)
|
||||
insize = strlen(indata);
|
||||
|
||||
base64data = output = (char*)malloc(insize*4/3+4);
|
||||
base64data = output = malloc(insize*4/3+4);
|
||||
if(NULL == output)
|
||||
return 0;
|
||||
|
||||
|
|
@ -171,7 +171,7 @@ size_t Curl_base64_encode(struct SessionHandle *data,
|
|||
* so we copy it to a buffer, translate it, and use that instead.
|
||||
*/
|
||||
if(data) {
|
||||
convbuf = (char*)malloc(insize);
|
||||
convbuf = malloc(insize);
|
||||
if(!convbuf) {
|
||||
free(output);
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ inflate_stream(struct connectdata *conn,
|
|||
|
||||
/* Dynamically allocate a buffer for decompression because it's uncommonly
|
||||
large to hold on the stack */
|
||||
decomp = (char*)malloc(DSIZ);
|
||||
decomp = malloc(DSIZ);
|
||||
if(decomp == NULL) {
|
||||
return exit_zlib(z, &k->zlib_init, CURLE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -711,7 +711,7 @@ struct CookieInfo *Curl_cookie_init(struct SessionHandle *data,
|
|||
char *lineptr;
|
||||
bool headerline;
|
||||
|
||||
char *line = (char *)malloc(MAX_COOKIE_LINE);
|
||||
char *line = malloc(MAX_COOKIE_LINE);
|
||||
if(line) {
|
||||
while(fgets(line, MAX_COOKIE_LINE, fp)) {
|
||||
if(checkprefix("Set-Cookie:", line)) {
|
||||
|
|
@ -789,7 +789,7 @@ struct Cookie *Curl_cookie_getlist(struct CookieInfo *c,
|
|||
/* and now, we know this is a match and we should create an
|
||||
entry for the return-linked-list */
|
||||
|
||||
newco = (struct Cookie *)malloc(sizeof(struct Cookie));
|
||||
newco = malloc(sizeof(struct Cookie));
|
||||
if(newco) {
|
||||
/* first, copy the whole source cookie: */
|
||||
memcpy(newco, co, sizeof(struct Cookie));
|
||||
|
|
|
|||
|
|
@ -612,7 +612,7 @@ CURL *curl_easy_duphandle(CURL *incurl)
|
|||
* get setup on-demand in the code, as that would probably decrease
|
||||
* the likeliness of us forgetting to init a buffer here in the future.
|
||||
*/
|
||||
outcurl->state.headerbuff=(char*)malloc(HEADERSIZE);
|
||||
outcurl->state.headerbuff = malloc(HEADERSIZE);
|
||||
if(!outcurl->state.headerbuff) {
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -222,7 +222,7 @@ static FormInfo * AddFormInfo(char *value,
|
|||
FormInfo *parent_form_info)
|
||||
{
|
||||
FormInfo *form_info;
|
||||
form_info = (FormInfo *)malloc(sizeof(FormInfo));
|
||||
form_info = malloc(sizeof(FormInfo));
|
||||
if(form_info) {
|
||||
memset(form_info, 0, sizeof(FormInfo));
|
||||
if(value)
|
||||
|
|
@ -327,7 +327,7 @@ static char *memdup(const char *src, size_t buffer_length)
|
|||
/* no length and a NULL src pointer! */
|
||||
return strdup("");
|
||||
|
||||
buffer = (char*)malloc(length+add);
|
||||
buffer = malloc(length+add);
|
||||
if(!buffer)
|
||||
return NULL; /* fail */
|
||||
|
||||
|
|
@ -838,8 +838,7 @@ static CURLcode AddFormData(struct FormData **formp,
|
|||
size_t length,
|
||||
curl_off_t *size)
|
||||
{
|
||||
struct FormData *newform = (struct FormData *)
|
||||
malloc(sizeof(struct FormData));
|
||||
struct FormData *newform = malloc(sizeof(struct FormData));
|
||||
if(!newform)
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
newform->next = NULL;
|
||||
|
|
@ -849,7 +848,7 @@ static CURLcode AddFormData(struct FormData **formp,
|
|||
if(!length)
|
||||
length = strlen((char *)line);
|
||||
|
||||
newform->line = (char *)malloc(length+1);
|
||||
newform->line = malloc(length+1);
|
||||
if(!newform->line) {
|
||||
free(newform);
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
|
|
@ -1729,7 +1728,7 @@ char *Curl_FormBoundary(void)
|
|||
|
||||
static const char table16[]="abcdef0123456789";
|
||||
|
||||
retstring = (char *)malloc(BOUNDARY_LENGTH+1);
|
||||
retstring = malloc(BOUNDARY_LENGTH+1);
|
||||
|
||||
if(!retstring)
|
||||
return NULL; /* failed */
|
||||
|
|
|
|||
|
|
@ -550,7 +550,7 @@ static CURLcode ftp_readresp(curl_socket_t sockfd,
|
|||
|
||||
if(clipamount) {
|
||||
ftpc->cache_size = clipamount;
|
||||
ftpc->cache = (char *)malloc((int)ftpc->cache_size);
|
||||
ftpc->cache = malloc((int)ftpc->cache_size);
|
||||
if(ftpc->cache)
|
||||
memcpy(ftpc->cache, ftpc->linestart_resp, (int)ftpc->cache_size);
|
||||
else
|
||||
|
|
@ -2751,7 +2751,7 @@ static CURLcode ftp_statemach_act(struct connectdata *conn)
|
|||
|
||||
case FTP_PWD:
|
||||
if(ftpcode == 257) {
|
||||
char *dir = (char *)malloc(nread+1);
|
||||
char *dir = malloc(nread+1);
|
||||
char *store=dir;
|
||||
char *ptr=&data->state.buffer[4]; /* start on the first letter */
|
||||
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ Curl_hash_init(struct curl_hash *h,
|
|||
h->size = 0;
|
||||
h->slots = slots;
|
||||
|
||||
h->table = (struct curl_llist **) malloc(slots * sizeof(struct curl_llist *));
|
||||
h->table = malloc(slots * sizeof(struct curl_llist *));
|
||||
if(h->table) {
|
||||
for (i = 0; i < slots; ++i) {
|
||||
h->table[i] = Curl_llist_alloc((curl_llist_dtor) hash_element_dtor);
|
||||
|
|
@ -96,7 +96,7 @@ Curl_hash_alloc(int slots,
|
|||
return NULL; /* failure */
|
||||
}
|
||||
|
||||
h = (struct curl_hash *) malloc(sizeof(struct curl_hash));
|
||||
h = malloc(sizeof(struct curl_hash));
|
||||
if(h) {
|
||||
if(Curl_hash_init(h, slots, hfunc, comparator, dtor)) {
|
||||
/* failure */
|
||||
|
|
@ -113,8 +113,7 @@ Curl_hash_alloc(int slots,
|
|||
static struct curl_hash_element *
|
||||
mk_hash_element(const void *key, size_t key_len, const void *p)
|
||||
{
|
||||
struct curl_hash_element *he =
|
||||
(struct curl_hash_element *) malloc(sizeof(struct curl_hash_element));
|
||||
struct curl_hash_element *he = malloc(sizeof(struct curl_hash_element));
|
||||
|
||||
if(he) {
|
||||
void *dupkey = malloc(key_len);
|
||||
|
|
|
|||
|
|
@ -971,7 +971,7 @@ static
|
|||
send_buffer *add_buffer_init(void)
|
||||
{
|
||||
send_buffer *blonk;
|
||||
blonk=(send_buffer *)malloc(sizeof(send_buffer));
|
||||
blonk = malloc(sizeof(send_buffer));
|
||||
if(blonk) {
|
||||
memset(blonk, 0, sizeof(send_buffer));
|
||||
return blonk;
|
||||
|
|
@ -1193,7 +1193,7 @@ CURLcode add_buffer(send_buffer *in, const void *inptr, size_t size)
|
|||
new_rb = realloc(in->buffer, new_size);
|
||||
else
|
||||
/* create a new buffer */
|
||||
new_rb = (char *)malloc(new_size);
|
||||
new_rb = malloc(new_size);
|
||||
|
||||
if(!new_rb) {
|
||||
/* If we failed, we cleanup the whole buffer and return error */
|
||||
|
|
|
|||
|
|
@ -309,7 +309,7 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn,
|
|||
}
|
||||
else {
|
||||
conn->trlMax=128;
|
||||
ptr = (char*)malloc(conn->trlMax);
|
||||
ptr = malloc(conn->trlMax);
|
||||
}
|
||||
if(!ptr)
|
||||
return CHUNKE_OUT_OF_MEMORY;
|
||||
|
|
|
|||
|
|
@ -320,7 +320,7 @@ CURLcode Curl_output_digest(struct connectdata *conn,
|
|||
Curl_md5it(md5buf, md5this);
|
||||
free(md5this); /* free this again */
|
||||
|
||||
ha1 = (unsigned char *)malloc(33); /* 32 digits and 1 zero byte */
|
||||
ha1 = malloc(33); /* 32 digits and 1 zero byte */
|
||||
if(!ha1)
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ Curl_llist_alloc(curl_llist_dtor dtor)
|
|||
{
|
||||
struct curl_llist *list;
|
||||
|
||||
list = (struct curl_llist *)malloc(sizeof(struct curl_llist));
|
||||
list = malloc(sizeof(struct curl_llist));
|
||||
if(NULL == list)
|
||||
return NULL;
|
||||
|
||||
|
|
@ -62,8 +62,7 @@ int
|
|||
Curl_llist_insert_next(struct curl_llist *list, struct curl_llist_element *e,
|
||||
const void *p)
|
||||
{
|
||||
struct curl_llist_element *ne =
|
||||
(struct curl_llist_element *) malloc(sizeof(struct curl_llist_element));
|
||||
struct curl_llist_element *ne = malloc(sizeof(struct curl_llist_element));
|
||||
if(!ne)
|
||||
return 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -1068,7 +1068,7 @@ static int alloc_addbyter(int output, FILE *data)
|
|||
unsigned char outc = (unsigned char)output;
|
||||
|
||||
if(!infop->buffer) {
|
||||
infop->buffer=(char *)malloc(32);
|
||||
infop->buffer = malloc(32);
|
||||
if(!infop->buffer) {
|
||||
infop->fail = 1;
|
||||
return -1; /* fail */
|
||||
|
|
|
|||
|
|
@ -1427,7 +1427,7 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
|
|||
}
|
||||
|
||||
/* now add a node to the Curl_message linked list with this info */
|
||||
msg = (struct Curl_message *)malloc(sizeof(struct Curl_message));
|
||||
msg = malloc(sizeof(struct Curl_message));
|
||||
|
||||
if(!msg)
|
||||
return CURLM_OUT_OF_MEMORY;
|
||||
|
|
|
|||
18
lib/nss.c
18
lib/nss.c
|
|
@ -298,8 +298,8 @@ nss_load_cert(const char *filename, PRBool cacert)
|
|||
else
|
||||
slotID = 1;
|
||||
|
||||
slotname = (char *)malloc(SLOTSIZE);
|
||||
nickname = (char *)malloc(PATH_MAX);
|
||||
slotname = malloc(SLOTSIZE);
|
||||
nickname = malloc(PATH_MAX);
|
||||
snprintf(slotname, SLOTSIZE, "PEM Token #%ld", slotID);
|
||||
snprintf(nickname, PATH_MAX, "PEM Token #%ld:%s", slotID, n);
|
||||
|
||||
|
|
@ -460,7 +460,7 @@ static int nss_load_key(struct connectdata *conn, char *key_file)
|
|||
|
||||
slotID = 1; /* hardcoded for now */
|
||||
|
||||
slotname = (char *)malloc(SLOTSIZE);
|
||||
slotname = malloc(SLOTSIZE);
|
||||
snprintf(slotname, SLOTSIZE, "PEM Token #%ld", slotID);
|
||||
|
||||
slot = PK11_FindSlotByName(slotname);
|
||||
|
|
@ -485,7 +485,7 @@ static int nss_load_key(struct connectdata *conn, char *key_file)
|
|||
SECMOD_WaitForAnyTokenEvent(mod, 0, 0);
|
||||
PK11_IsPresent(slot);
|
||||
|
||||
parg = (pphrase_arg_t *) malloc(sizeof(*parg));
|
||||
parg = malloc(sizeof(pphrase_arg_t));
|
||||
parg->retryCount = 0;
|
||||
parg->data = conn->data;
|
||||
/* parg is initialized in nss_Init_Tokens() */
|
||||
|
|
@ -581,7 +581,7 @@ static SECStatus nss_Init_Tokens(struct connectdata * conn)
|
|||
SECStatus ret, status = SECSuccess;
|
||||
pphrase_arg_t *parg = NULL;
|
||||
|
||||
parg = (pphrase_arg_t *) malloc(sizeof(*parg));
|
||||
parg = malloc(sizeof(pphrase_arg_t));
|
||||
parg->retryCount = 0;
|
||||
parg->data = conn->data;
|
||||
|
||||
|
|
@ -800,7 +800,7 @@ static SECStatus SelectClientCert(void *arg, PRFileDesc *sock,
|
|||
|
||||
if(!strncmp(nickname, "PEM Token", 9)) {
|
||||
CK_SLOT_ID slotID = 1; /* hardcoded for now */
|
||||
char * slotname = (char *)malloc(SLOTSIZE);
|
||||
char * slotname = malloc(SLOTSIZE);
|
||||
snprintf(slotname, SLOTSIZE, "PEM Token #%ld", slotID);
|
||||
slot = PK11_FindSlotByName(slotname);
|
||||
privKey = PK11_FindPrivateKeyFromCert(slot, cert, NULL);
|
||||
|
|
@ -956,7 +956,7 @@ CURLcode Curl_nss_connect(struct connectdata *conn, int sockindex)
|
|||
NSS_SetDomesticPolicy();
|
||||
|
||||
#ifdef HAVE_PK11_CREATEGENERICOBJECT
|
||||
configstring = (char *)malloc(PATH_MAX);
|
||||
configstring = malloc(PATH_MAX);
|
||||
|
||||
PR_snprintf(configstring, PATH_MAX, "library=%s name=PEM", pem_library);
|
||||
|
||||
|
|
@ -1091,7 +1091,7 @@ CURLcode Curl_nss_connect(struct connectdata *conn, int sockindex)
|
|||
char *n;
|
||||
char *nickname;
|
||||
|
||||
nickname = (char *)malloc(PATH_MAX);
|
||||
nickname = malloc(PATH_MAX);
|
||||
if(is_file(data->set.str[STRING_CERT])) {
|
||||
n = strrchr(data->set.str[STRING_CERT], '/');
|
||||
if(n) {
|
||||
|
|
@ -1159,7 +1159,7 @@ CURLcode Curl_nss_connect(struct connectdata *conn, int sockindex)
|
|||
if (data->set.str[STRING_SSL_ISSUERCERT]) {
|
||||
char *n;
|
||||
char *nickname;
|
||||
nickname = (char *)malloc(PATH_MAX);
|
||||
nickname = malloc(PATH_MAX);
|
||||
if(is_file(data->set.str[STRING_SSL_ISSUERCERT])) {
|
||||
n = strrchr(data->set.str[STRING_SSL_ISSUERCERT], '/');
|
||||
if (n) {
|
||||
|
|
|
|||
|
|
@ -185,7 +185,7 @@ int GetOrSetUpData(int id, libdata_t **appData,
|
|||
NXLock(gLibLock);
|
||||
|
||||
if(!(app_data = (libdata_t *) get_app_data(id))) {
|
||||
app_data = (libdata_t *) malloc(sizeof(libdata_t));
|
||||
app_data = malloc(sizeof(libdata_t));
|
||||
|
||||
if(app_data) {
|
||||
memset(app_data, 0, sizeof(libdata_t));
|
||||
|
|
@ -246,7 +246,7 @@ int GetOrSetUpData(int id, libdata_t **appData,
|
|||
** important, this just helps to demonstrate that we can have arbitrarily
|
||||
** complex per-thread data.
|
||||
*/
|
||||
thread_data = (libthreaddata_t *) malloc(sizeof(libthreaddata_t));
|
||||
thread_data = malloc(sizeof(libthreaddata_t));
|
||||
|
||||
if(thread_data) {
|
||||
thread_data->_errno = 0;
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ struct curl_slist *curl_slist_append(struct curl_slist *list,
|
|||
struct curl_slist *last;
|
||||
struct curl_slist *new_item;
|
||||
|
||||
new_item = (struct curl_slist *) malloc(sizeof(struct curl_slist));
|
||||
new_item = malloc(sizeof(struct curl_slist));
|
||||
if(new_item) {
|
||||
char *dupdata = strdup(data);
|
||||
if(dupdata) {
|
||||
|
|
|
|||
|
|
@ -36,8 +36,7 @@
|
|||
CURLSH *
|
||||
curl_share_init(void)
|
||||
{
|
||||
struct Curl_share *share =
|
||||
(struct Curl_share *)malloc(sizeof(struct Curl_share));
|
||||
struct Curl_share *share = malloc(sizeof(struct Curl_share));
|
||||
if(share) {
|
||||
memset (share, 0, sizeof(struct Curl_share));
|
||||
share->specifier |= (1<<CURL_LOCK_DATA_SHARE);
|
||||
|
|
|
|||
|
|
@ -394,7 +394,7 @@ int main(int argc, argv_item_t argv[])
|
|||
|
||||
for (i = 0; i < MAX; i++) {
|
||||
struct timeval key;
|
||||
ptrs[i] = t = (struct Curl_tree *)malloc(sizeof(struct Curl_tree));
|
||||
ptrs[i] = t = malloc(sizeof(struct Curl_tree));
|
||||
|
||||
key.tv_sec = 0;
|
||||
#ifdef TEST2
|
||||
|
|
|
|||
12
lib/ssh.c
12
lib/ssh.c
|
|
@ -379,7 +379,7 @@ static CURLcode ssh_getworkingpath(struct connectdata *conn,
|
|||
|
||||
/* Check for /~/ , indicating relative to the user's home directory */
|
||||
if(conn->protocol & PROT_SCP) {
|
||||
real_path = (char *)malloc(working_path_len+1);
|
||||
real_path = malloc(working_path_len+1);
|
||||
if(real_path == NULL) {
|
||||
free(working_path);
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
|
|
@ -393,7 +393,7 @@ static CURLcode ssh_getworkingpath(struct connectdata *conn,
|
|||
else if(conn->protocol & PROT_SFTP) {
|
||||
if((working_path_len > 1) && (working_path[1] == '~')) {
|
||||
size_t homelen = strlen(homedir);
|
||||
real_path = (char *)malloc(homelen + working_path_len + 1);
|
||||
real_path = malloc(homelen + working_path_len + 1);
|
||||
if(real_path == NULL) {
|
||||
free(working_path);
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
|
|
@ -409,7 +409,7 @@ static CURLcode ssh_getworkingpath(struct connectdata *conn,
|
|||
}
|
||||
}
|
||||
else {
|
||||
real_path = (char *)malloc(working_path_len+1);
|
||||
real_path = malloc(working_path_len+1);
|
||||
if(real_path == NULL) {
|
||||
free(working_path);
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
|
|
@ -1403,12 +1403,12 @@ static CURLcode ssh_statemach_act(struct connectdata *conn)
|
|||
break;
|
||||
}
|
||||
}
|
||||
if((sshc->readdir_filename = (char *)malloc(PATH_MAX+1)) == NULL) {
|
||||
if((sshc->readdir_filename = malloc(PATH_MAX+1)) == NULL) {
|
||||
state(conn, SSH_SFTP_CLOSE);
|
||||
sshc->actualcode = CURLE_OUT_OF_MEMORY;
|
||||
break;
|
||||
}
|
||||
if((sshc->readdir_longentry = (char *)malloc(PATH_MAX+1)) == NULL) {
|
||||
if((sshc->readdir_longentry = malloc(PATH_MAX+1)) == NULL) {
|
||||
Curl_safefree(sshc->readdir_filename);
|
||||
sshc->readdir_filename = NULL;
|
||||
state(conn, SSH_SFTP_CLOSE);
|
||||
|
|
@ -1477,7 +1477,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn)
|
|||
if((sshc->readdir_attrs.flags & LIBSSH2_SFTP_ATTR_PERMISSIONS) &&
|
||||
((sshc->readdir_attrs.permissions & LIBSSH2_SFTP_S_IFMT) ==
|
||||
LIBSSH2_SFTP_S_IFLNK)) {
|
||||
sshc->readdir_linkPath = (char *)malloc(PATH_MAX + 1);
|
||||
sshc->readdir_linkPath = malloc(PATH_MAX + 1);
|
||||
if(sshc->readdir_linkPath == NULL) {
|
||||
Curl_safefree(sshc->readdir_filename);
|
||||
sshc->readdir_filename = NULL;
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ char *curlx_strdup(const char *str)
|
|||
if(len >= ((size_t)-1) / sizeof(char))
|
||||
return (char *)NULL;
|
||||
|
||||
newstr = (char *) malloc((len+1)*sizeof(char));
|
||||
newstr = malloc((len+1)*sizeof(char));
|
||||
if(!newstr)
|
||||
return (char *)NULL;
|
||||
|
||||
|
|
|
|||
|
|
@ -2136,7 +2136,7 @@ static char *concat_url(const char *base, const char *relurl)
|
|||
|
||||
urllen = strlen(url_clone);
|
||||
|
||||
newest=(char *)malloc( urllen + 1 + /* possible slash */
|
||||
newest = malloc( urllen + 1 + /* possible slash */
|
||||
newlen + 1 /* zero byte */);
|
||||
|
||||
if(!newest) {
|
||||
|
|
|
|||
|
|
@ -675,7 +675,7 @@ CURLcode Curl_open(struct SessionHandle **curl)
|
|||
|
||||
/* We do some initial setup here, all those fields that can't be just 0 */
|
||||
|
||||
data->state.headerbuff=(char*)malloc(HEADERSIZE);
|
||||
data->state.headerbuff = malloc(HEADERSIZE);
|
||||
if(!data->state.headerbuff) {
|
||||
DEBUGF(fprintf(stderr, "Error: malloc of headerbuff failed\n"));
|
||||
res = CURLE_OUT_OF_MEMORY;
|
||||
|
|
@ -4154,12 +4154,12 @@ static CURLcode create_conn(struct SessionHandle *data,
|
|||
*/
|
||||
|
||||
Curl_safefree(data->state.pathbuffer);
|
||||
data->state.pathbuffer=(char *)malloc(urllen+2);
|
||||
data->state.pathbuffer = malloc(urllen+2);
|
||||
if(NULL == data->state.pathbuffer)
|
||||
return CURLE_OUT_OF_MEMORY; /* really bad error */
|
||||
data->state.path = data->state.pathbuffer;
|
||||
|
||||
conn->host.rawalloc=(char *)malloc(urllen+2);
|
||||
conn->host.rawalloc = malloc(urllen+2);
|
||||
if(NULL == conn->host.rawalloc)
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue