summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2007-05-14 03:16:55 -0400
committerDan McGee <dan@archlinux.org>2007-05-14 03:16:55 -0400
commit2bcecbd62cb2bda681a3aba46bb0bbf690ba7219 (patch)
treecc7f9d60e04c65453527354bbd18312a9c323ed4
parent5c930c318e7b80af3a322ddc7ddf9fe100e9c16b (diff)
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>
-rw-r--r--lib/libalpm/alpm_list.c2
-rw-r--r--lib/libalpm/deps.c8
-rw-r--r--lib/libalpm/handle.c2
-rw-r--r--lib/libalpm/package.c4
-rw-r--r--lib/libalpm/server.c2
-rw-r--r--lib/libalpm/sync.c14
-rw-r--r--lib/libalpm/trans.c6
-rw-r--r--lib/libalpm/util.c2
-rw-r--r--src/pacman/callback.c14
-rw-r--r--src/pacman/package.c6
-rw-r--r--src/pacman/util.c2
11 files changed, 31 insertions, 31 deletions
diff --git a/lib/libalpm/alpm_list.c b/lib/libalpm/alpm_list.c
index 4977f1ac..037f57ba 100644
--- a/lib/libalpm/alpm_list.c
+++ b/lib/libalpm/alpm_list.c
@@ -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;
diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c
index 51b3207f..b6f8cc80 100644
--- a/lib/libalpm/deps.c
+++ b/lib/libalpm/deps.c
@@ -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;
diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c
index cbbdeff5..47abcb32 100644
--- a/lib/libalpm/handle.c
+++ b/lib/libalpm/handle.c
@@ -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);
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index d0aba7ba..e8dd5d60 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -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");
diff --git a/lib/libalpm/server.c b/lib/libalpm/server.c
index c34c9215..1d972bdb 100644
--- a/lib/libalpm/server.c
+++ b/lib/libalpm/server.c
@@ -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);
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index ef8af5c6..87f8c720 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -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) {
diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c
index cb873e7a..2637197c 100644
--- a/lib/libalpm/trans.c
+++ b/lib/libalpm/trans.c
@@ -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;
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index f821beb2..15e69b79 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -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--;
}
diff --git a/src/pacman/callback.c b/src/pacman/callback.c
index be209b44..5f391306 100644
--- a/src/pacman/callback.c
+++ b/src/pacman/callback.c
@@ -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;
diff --git a/src/pacman/package.c b/src/pacman/package.c
index 03c2d88c..c91384d9 100644
--- a/src/pacman/package.c
+++ b/src/pacman/package.c
@@ -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));
diff --git a/src/pacman/util.c b/src/pacman/util.c
index 0057a85b..f38be60c 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -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--;
}