diff options
author | thevenyp <thevenyp@211d60ee-9f03-0410-a15a-8952a2c7a4e4> | 2009-03-30 12:01:31 +0000 |
---|---|---|
committer | thevenyp <thevenyp@211d60ee-9f03-0410-a15a-8952a2c7a4e4> | 2009-03-30 12:01:31 +0000 |
commit | 82f43af1baa9f8a2ddcaf4e2e30a5e36ba81d3cd (patch) | |
tree | 4a34274f94b0f31adbbe7d4c5f45ea1130258fcb | |
parent | e964356aeedb0be91c9a0d12dd12491db527a089 (diff) | |
download | mpc-82f43af1baa9f8a2ddcaf4e2e30a5e36ba81d3cd.tar.gz |
src/mem.c tests/read_data.c tests/tstrtoc.c: Code simplification (sizeof (char) is always 1).
git-svn-id: svn://scm.gforge.inria.fr/svn/mpc/trunk@519 211d60ee-9f03-0410-a15a-8952a2c7a4e4
-rw-r--r-- | src/mem.c | 16 | ||||
-rw-r--r-- | tests/read_data.c | 3 | ||||
-rw-r--r-- | tests/tstrtoc.c | 4 |
3 files changed, 9 insertions, 14 deletions
@@ -28,9 +28,9 @@ mpc_alloc_str (size_t len) #ifdef mp_get_memory_functions /* GMP >= 4.2 */ void * (*allocfunc) (size_t); mp_get_memory_functions (&allocfunc, NULL, NULL); - return (char *) ((*allocfunc) (len * sizeof (char))); + return (char *) ((*allocfunc) (len)); #else /* GMP < 4.2 */ - return (char *) __gmp_allocate_func (len * sizeof (char)); + return (char *) __gmp_allocate_func (len); #endif } @@ -40,11 +40,9 @@ mpc_realloc_str (char * str, size_t oldlen, size_t newlen) #ifdef mp_get_memory_functions /* GMP >= 4.2 */ void * (*reallocfunc) (void *, size_t, size_t); mp_get_memory_functions (NULL, &reallocfunc, NULL); - return (char *) ((*reallocfunc) (str, oldlen * sizeof (char), - newlen * sizeof (char))); + return (char *) ((*reallocfunc) (str, oldlen, newlen)); #else /* GMP < 4.2 */ - return (char *) __gmp_reallocate_func (str, oldlen * sizeof (char), - newlen * sizeof (char)); + return (char *) __gmp_reallocate_func (str, oldlen, newlen); #endif } @@ -54,10 +52,8 @@ mpc_free_str (char *str) #ifdef mp_get_memory_functions /* GMP >= 4.2 */ void (*freefunc) (void *, size_t); mp_get_memory_functions (NULL, NULL, &freefunc); - (*freefunc) (str, (strlen (str) + 1) * sizeof (char)); + (*freefunc) (str, strlen (str) + 1); #else /* GMP < 4.2 */ - __gmp_free_func (str, (strlen (str) + 1) * sizeof (char)); + __gmp_free_func (str, strlen (str) + 1); #endif } - - diff --git a/tests/read_data.c b/tests/read_data.c index bb245be..42849ef 100644 --- a/tests/read_data.c +++ b/tests/read_data.c @@ -72,8 +72,7 @@ open_data_file (const char *file_name) if (src_dir == NULL) src_dir = "."; - pathname = malloc (((strlen (src_dir)) + strlen (file_name) + 2) - * sizeof (char)); + pathname = malloc ((strlen (src_dir)) + strlen (file_name) + 2); if (pathname == NULL) { printf ("Cannot allocate memory\n"); diff --git a/tests/tstrtoc.c b/tests/tstrtoc.c index 40950c4..a44a359 100644 --- a/tests/tstrtoc.c +++ b/tests/tstrtoc.c @@ -54,13 +54,13 @@ check_file (const char* file_name) fp = open_data_file (file_name); /* initializations */ - str = (char *) malloc (str_len * sizeof (char)); + str = (char *) malloc (str_len); if (str == NULL) { printf ("Cannot allocate memory\n"); exit (1); } - rstr = (char *) malloc (rstr_len * sizeof (char)); + rstr = (char *) malloc (rstr_len); if (rstr == NULL) { printf ("Cannot allocate memory\n"); |