Remove unnecessary casts on malloc and elsewhere

We had many unnecessary casts, most of them dealing with malloc and
other memory allocations. The variable type should take care of it;
no need to do it explicitly. In addition, I caught a const error while
removing the casts.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2007-05-14 03:16:55 -04:00
parent 5c930c318e
commit 2bcecbd62c
11 changed files with 31 additions and 31 deletions

View file

@ -50,7 +50,7 @@ alpm_list_t *alpm_list_new()
{
alpm_list_t *list = NULL;
list = (alpm_list_t *)malloc(sizeof(alpm_list_t));
list = malloc(sizeof(alpm_list_t));
if(list) {
list->data = NULL;
list->prev = NULL;

View file

@ -54,7 +54,7 @@ pmdepmissing_t *_alpm_depmiss_new(const char *target, pmdeptype_t type,
ALPM_LOG_FUNC;
miss = (pmdepmissing_t *)malloc(sizeof(pmdepmissing_t));
miss = malloc(sizeof(pmdepmissing_t));
if(miss == NULL) {
_alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes"), sizeof(pmdepmissing_t));
RET_ERR(PM_ERR_MEMORY, NULL);
@ -431,7 +431,7 @@ pmdepend_t SYMEXPORT *alpm_splitdep(const char *depstring)
return(NULL);
}
depend = (pmdepend_t *)malloc(sizeof(pmdepend_t));
depend = malloc(sizeof(pmdepend_t));
if(depend == NULL) {
_alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes"), sizeof(pmdepend_t));
return(NULL);
@ -628,7 +628,7 @@ int _alpm_resolvedeps(pmdb_t *local, alpm_list_t *dbs_sync, pmpkg_t *syncpkg,
_alpm_log(PM_LOG_ERROR, _("cannot resolve dependencies for \"%s\" (\"%s\" is not in the package set)"),
miss->target, miss->depend.name);
if(data) {
if((miss = (pmdepmissing_t *)malloc(sizeof(pmdepmissing_t))) == NULL) {
if((miss = malloc(sizeof(pmdepmissing_t))) == NULL) {
_alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes"), sizeof(pmdepmissing_t));
FREELIST(*data);
pm_errno = PM_ERR_MEMORY;
@ -668,7 +668,7 @@ int _alpm_resolvedeps(pmdb_t *local, alpm_list_t *dbs_sync, pmpkg_t *syncpkg,
} else {
_alpm_log(PM_LOG_ERROR, _("cannot resolve dependencies for \"%s\""), miss->target);
if(data) {
if((miss = (pmdepmissing_t *)malloc(sizeof(pmdepmissing_t))) == NULL) {
if((miss = malloc(sizeof(pmdepmissing_t))) == NULL) {
_alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes"), sizeof(pmdepmissing_t));
FREELIST(*data);
pm_errno = PM_ERR_MEMORY;

View file

@ -45,7 +45,7 @@ pmhandle_t *_alpm_handle_new()
{
pmhandle_t *handle;
handle = (pmhandle_t *)malloc(sizeof(pmhandle_t));
handle = malloc(sizeof(pmhandle_t));
if(handle == NULL) {
_alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes"), sizeof(pmhandle_t));
RET_ERR(PM_ERR_MEMORY, NULL);

View file

@ -230,7 +230,7 @@ static int parse_descfile(const char *descfile, pmpkg_t *info)
/*
char *lang_tmp;
info->desc_localized = alpm_list_add(info->desc_localized, strdup(ptr));
if((lang_tmp = (char *)malloc(strlen(setlocale(LC_ALL, "")))) == NULL) {
if((lang_tmp = malloc(strlen(setlocale(LC_ALL, "")))) == NULL) {
RET_ERR(PM_ERR_MEMORY, -1);
}
strncpy(lang_tmp, setlocale(LC_ALL, ""), strlen(setlocale(LC_ALL, "")));
@ -373,7 +373,7 @@ pmpkg_t *_alpm_pkg_load(const char *pkgfile)
char *str;
int fd;
if((str = (char *)malloc(PATH_MAX)) == NULL) {
if((str = malloc(PATH_MAX)) == NULL) {
RET_ERR(PM_ERR_MEMORY, (pmpkg_t *)-1);
}
fn = strdup("/tmp/alpm_XXXXXX");

View file

@ -49,7 +49,7 @@ pmserver_t *_alpm_server_new(const char *url)
ALPM_LOG_FUNC;
server = (pmserver_t *)malloc(sizeof(pmserver_t));
server = malloc(sizeof(pmserver_t));
if(server == NULL) {
_alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes"), sizeof(pmserver_t));
RET_ERR(PM_ERR_MEMORY, NULL);

View file

@ -60,7 +60,7 @@ pmsyncpkg_t *_alpm_sync_new(int type, pmpkg_t *spkg, void *data)
ALPM_LOG_FUNC;
if((sync = (pmsyncpkg_t *)malloc(sizeof(pmsyncpkg_t))) == NULL) {
if((sync = malloc(sizeof(pmsyncpkg_t))) == NULL) {
_alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes"), sizeof(pmsyncpkg_t));
return(NULL);
}
@ -615,7 +615,7 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
_alpm_log(PM_LOG_ERROR, _("unresolvable package conflicts detected"));
errorout = 1;
if(data) {
if((miss = (pmdepmissing_t *)malloc(sizeof(pmdepmissing_t))) == NULL) {
if((miss = malloc(sizeof(pmdepmissing_t))) == NULL) {
_alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes"), sizeof(pmdepmissing_t));
FREELIST(*data);
pm_errno = PM_ERR_MEMORY;
@ -631,7 +631,7 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
_alpm_log(PM_LOG_ERROR, _("unresolvable package conflicts detected"));
errorout = 1;
if(data) {
if((miss = (pmdepmissing_t *)malloc(sizeof(pmdepmissing_t))) == NULL) {
if((miss = malloc(sizeof(pmdepmissing_t))) == NULL) {
_alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes"), sizeof(pmdepmissing_t));
FREELIST(*data);
pm_errno = PM_ERR_MEMORY;
@ -729,7 +729,7 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
errorout = 1;
}
if(data) {
if((miss = (pmdepmissing_t *)malloc(sizeof(pmdepmissing_t))) == NULL) {
if((miss = malloc(sizeof(pmdepmissing_t))) == NULL) {
_alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes"), sizeof(pmdepmissing_t));
FREELIST(*data);
pm_errno = PM_ERR_MEMORY;
@ -863,7 +863,7 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
if((md5sum1 == NULL) && (sha1sum1 == NULL)) {
/* TODO wtf is this? malloc'd strings for error messages? */
if((ptr = (char *)malloc(512)) == NULL) {
if((ptr = calloc(512, sizeof(char))) == NULL) {
RET_ERR(PM_ERR_MEMORY, -1);
}
snprintf(ptr, 512, _("can't get md5 or sha1 checksum for package %s\n"), pkgname);
@ -875,7 +875,7 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
md5sum2 = _alpm_MDFile(str);
sha1sum2 = _alpm_SHAFile(str);
if(md5sum2 == NULL && sha1sum2 == NULL) {
if((ptr = (char *)malloc(512)) == NULL) {
if((ptr = calloc(512, sizeof(char))) == NULL) {
RET_ERR(PM_ERR_MEMORY, -1);
}
snprintf(ptr, 512, _("can't get md5 or sha1 checksum for package %s\n"), pkgname);
@ -885,7 +885,7 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
}
if((strcmp(md5sum1, md5sum2) != 0) && (strcmp(sha1sum1, sha1sum2) != 0)) {
int doremove=0;
if((ptr = (char *)malloc(512)) == NULL) {
if((ptr = calloc(512, sizeof(char))) == NULL) {
RET_ERR(PM_ERR_MEMORY, -1);
}
if(trans->flags & PM_TRANS_FLAG_ALLDEPS) {

View file

@ -59,7 +59,7 @@ pmtrans_t *_alpm_trans_new()
ALPM_LOG_FUNC;
if((trans = (pmtrans_t *)malloc(sizeof(pmtrans_t))) == NULL) {
if((trans = malloc(sizeof(pmtrans_t))) == NULL) {
_alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes"), sizeof(pmtrans_t));
return(NULL);
}
@ -594,14 +594,14 @@ int _alpm_check_freespace(pmtrans_t *trans, alpm_list_t **data)
if(pkgsize > freespace) {
if(data) {
long long *ptr;
if((ptr = (long long*)malloc(sizeof(long long)))==NULL) {
if((ptr = malloc(sizeof(long long)))==NULL) {
_alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes"), sizeof(long long));
pm_errno = PM_ERR_MEMORY;
return(-1);
}
*ptr = pkgsize;
*data = alpm_list_add(*data, ptr);
if((ptr = (long long*)malloc(sizeof(long long)))==NULL) {
if((ptr = malloc(sizeof(long long)))==NULL) {
_alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes"), sizeof(long long));
FREELIST(*data);
pm_errno = PM_ERR_MEMORY;

View file

@ -196,7 +196,7 @@ char *_alpm_strtrim(char *str)
return(str);
}
pch = (char *)(str + (strlen(str) - 1));
pch = (str + (strlen(str) - 1));
while(isspace((int)*pch)) {
pch--;
}

View file

@ -442,7 +442,7 @@ void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent,
}
/* convert above strings to wide chars */
oprlen = strlen(opr);
wcopr = (wchar_t*)calloc(oprlen, sizeof(wchar_t));
wcopr = calloc(oprlen, sizeof(wchar_t));
if(!wcopr) {
fprintf(stderr, "malloc failure: could not allocate %d bytes\n",
strlen(opr) * sizeof(wchar_t));
@ -519,10 +519,10 @@ void cb_dl_progress(const char *filename, int xfered, int total)
diff_sec = current_time.tv_sec - initial_time.tv_sec;
diff_usec = current_time.tv_usec - initial_time.tv_usec;
timediff = diff_sec + (diff_usec / 1000000.0);
rate = (float)total / (timediff * 1024.0);
rate = total / (timediff * 1024.0);
/* round elapsed time to the nearest second */
eta_s = (int)floorf(timediff + 0.5);
eta_s = floorf(timediff + 0.5);
} else {
/* compute current average values */
timediff = get_update_timediff(0);
@ -531,10 +531,10 @@ void cb_dl_progress(const char *filename, int xfered, int total)
/* return if the calling interval was too short */
return;
}
rate = (float)(xfered - xfered_last) / (timediff * 1024.0);
rate = (xfered - xfered_last) / (timediff * 1024.0);
/* average rate to reduce jumpiness */
rate = (float)(rate + 2*rate_last) / 3;
eta_s = (unsigned int)(total - xfered) / (rate * 1024.0);
rate = (rate + 2*rate_last) / 3;
eta_s = (total - xfered) / (rate * 1024.0);
rate_last = rate;
xfered_last = xfered;
}
@ -570,7 +570,7 @@ void cb_dl_progress(const char *filename, int xfered, int total)
}
}
f_xfered = (float) xfered / 1024.0; /* convert to K by default */
f_xfered = xfered / 1024.0; /* convert to K by default */
/* xfered_size = 'K'; was set above */
if(f_xfered > 2048.0) {
f_xfered /= 1024.0;

View file

@ -111,15 +111,15 @@ void dump_pkg_full(pmpkg_t *pkg, int level)
*/
void dump_pkg_sync(pmpkg_t *pkg, const char *treename)
{
char *descheader, *md5sum, *sha1sum;
const char *descheader, *md5sum, *sha1sum;
if(pkg == NULL) {
return;
}
descheader = _("Description : ");
md5sum = (char *)alpm_pkg_get_md5sum(pkg);
sha1sum = (char *)alpm_pkg_get_sha1sum(pkg);
md5sum = alpm_pkg_get_md5sum(pkg);
sha1sum = alpm_pkg_get_sha1sum(pkg);
printf(_("Repository : %s\n"), treename);
printf(_("Name : %s\n"), (char *)alpm_pkg_get_name(pkg));

View file

@ -216,7 +216,7 @@ char *strtrim(char *str)
memmove(str, pch, (strlen(pch) + 1));
}
pch = (char *)(str + (strlen(str) - 1));
pch = (str + (strlen(str) - 1));
while(isspace(*pch)) {
pch--;
}