diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2008-03-23 23:00:04 +0100 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2008-03-23 23:00:04 +0100 |
commit | 57323fa71effad75d78b36a45d5457b1bd782963 (patch) | |
tree | 50d7a5bacacebcdf59d5bf38dff84c83bf557d31 /src/core | |
parent | 14feea7ab84df3e367bc3732e8ba1470e1a3f5a7 (diff) | |
download | weechat-57323fa71effad75d78b36a45d5457b1bd782963.zip |
Removed sizeof(char) and useless type casts from void* to another pointer type (patch from Leonid Evdokimov)
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/wee-command.c | 4 | ||||
-rw-r--r-- | src/core/wee-config-file.c | 13 | ||||
-rw-r--r-- | src/core/wee-hook.c | 32 | ||||
-rw-r--r-- | src/core/wee-input.c | 4 | ||||
-rw-r--r-- | src/core/wee-list.c | 5 | ||||
-rw-r--r-- | src/core/wee-log.c | 5 | ||||
-rw-r--r-- | src/core/wee-string.c | 21 | ||||
-rw-r--r-- | src/core/wee-upgrade.c | 2 | ||||
-rw-r--r-- | src/core/wee-utf8.c | 2 | ||||
-rw-r--r-- | src/core/wee-util.c | 6 | ||||
-rw-r--r-- | src/core/weechat.c | 3 |
11 files changed, 47 insertions, 50 deletions
diff --git a/src/core/wee-command.c b/src/core/wee-command.c index f7a7108d4..5948720b5 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -526,7 +526,7 @@ command_builtin (void *data, struct t_gui_buffer *buffer, else { length = strlen (argv_eol[1]) + 2; - command = (char *)malloc (length * sizeof (char)); + command = malloc (length); if (command) { snprintf (command, length, "/%s", argv_eol[1]); @@ -1950,7 +1950,7 @@ command_upgrade (void *data, struct t_gui_buffer *buffer, } filename_length = strlen (weechat_home) + strlen (WEECHAT_SESSION_NAME) + 2; - filename = (char *)malloc (filename_length * sizeof (char)); + filename = malloc (filename_length); if (!filename) return -2; snprintf (filename, filename_length, "%s%s" WEECHAT_SESSION_NAME, diff --git a/src/core/wee-config-file.c b/src/core/wee-config-file.c index 2a932b2bf..5b5c7c2e4 100644 --- a/src/core/wee-config-file.c +++ b/src/core/wee-config-file.c @@ -86,7 +86,7 @@ config_file_new (struct t_weechat_plugin *plugin, char *filename, if (config_file_search (filename)) return NULL; - new_config_file = (struct t_config_file *)malloc (sizeof (struct t_config_file)); + new_config_file = malloc (sizeof (*new_config_file)); if (new_config_file) { new_config_file->plugin = plugin; @@ -157,7 +157,7 @@ config_file_new_section (struct t_config_file *config_file, char *name, if (!config_file || !name) return NULL; - new_section = (struct t_config_section *)malloc (sizeof (struct t_config_section)); + new_section = malloc (sizeof (*new_section)); if (new_section) { new_section->name = strdup (name); @@ -275,7 +275,7 @@ config_file_new_option (struct t_config_file *config_file, return NULL; } - new_option = (struct t_config_option *)malloc (sizeof (struct t_config_option)); + new_option = malloc (sizeof (*new_option)); if (new_option) { new_option->name = strdup (name); @@ -849,8 +849,7 @@ config_file_write_internal (struct t_config_file *config_file, /* build filename */ filename_length = strlen (weechat_home) + strlen (config_file->filename) + 2; - filename = - (char *)malloc (filename_length * sizeof (char)); + filename = malloc (filename_length); if (!filename) return -2; snprintf (filename, filename_length, "%s%s%s", @@ -858,7 +857,7 @@ config_file_write_internal (struct t_config_file *config_file, /* build temporary filename, this temp file will be renamed to filename after write */ - filename2 = (char *)malloc ((filename_length + 32) * sizeof (char)); + filename2 = malloc (filename_length + 32); if (!filename2) { free (filename); @@ -972,7 +971,7 @@ config_file_read (struct t_config_file *config_file) /* build filename */ filename_length = strlen (weechat_home) + strlen (config_file->filename) + 2; - filename = (char *)malloc (filename_length * sizeof (char)); + filename = malloc (filename_length); if (!filename) return -2; snprintf (filename, filename_length, "%s%s%s", diff --git a/src/core/wee-hook.c b/src/core/wee-hook.c index 4816ff2fc..ba579decb 100644 --- a/src/core/wee-hook.c +++ b/src/core/wee-hook.c @@ -330,10 +330,10 @@ hook_command (struct t_weechat_plugin *plugin, char *command, char *description, } } - new_hook = (struct t_hook *)malloc (sizeof (struct t_hook)); + new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; - new_hook_command = (struct t_hook_command *)malloc (sizeof (struct t_hook_command)); + new_hook_command = malloc (sizeof (*new_hook_command)); if (!new_hook_command) { free (new_hook); @@ -441,10 +441,10 @@ hook_timer (struct t_weechat_plugin *plugin, long interval, int align_second, struct t_hook_timer *new_hook_timer; struct timezone tz; - new_hook = (struct t_hook *)malloc (sizeof (struct t_hook)); + new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; - new_hook_timer = (struct t_hook_timer *)malloc (sizeof (struct t_hook_timer)); + new_hook_timer = malloc (sizeof (*new_hook_timer)); if (!new_hook_timer) { free (new_hook); @@ -623,10 +623,10 @@ hook_fd (struct t_weechat_plugin *plugin, int fd, int flag_read, if ((fd < 0) || hook_search_fd (fd)) return NULL; - new_hook = (struct t_hook *)malloc (sizeof (struct t_hook)); + new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; - new_hook_fd = (struct t_hook_fd *)malloc (sizeof (struct t_hook_fd)); + new_hook_fd = malloc (sizeof (*new_hook_fd)); if (!new_hook_fd) { free (new_hook); @@ -740,10 +740,10 @@ hook_print (struct t_weechat_plugin *plugin, struct t_gui_buffer *buffer, struct t_hook *new_hook; struct t_hook_print *new_hook_print; - new_hook = (struct t_hook *)malloc (sizeof (struct t_hook)); + new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; - new_hook_print = (struct t_hook_print *)malloc (sizeof (struct t_hook_print)); + new_hook_print = malloc (sizeof (*new_hook_print)); if (!new_hook_print) { free (new_hook); @@ -883,10 +883,10 @@ hook_signal (struct t_weechat_plugin *plugin, char *signal, if (!signal || !signal[0]) return NULL; - new_hook = (struct t_hook *)malloc (sizeof (struct t_hook)); + new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; - new_hook_signal = (struct t_hook_signal *)malloc (sizeof (struct t_hook_signal)); + new_hook_signal = malloc (sizeof (*new_hook_signal)); if (!new_hook_signal) { free (new_hook); @@ -947,10 +947,10 @@ hook_config (struct t_weechat_plugin *plugin, char *type, char *option, struct t_hook *new_hook; struct t_hook_config *new_hook_config; - new_hook = (struct t_hook *)malloc (sizeof (struct t_hook)); + new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; - new_hook_config = (struct t_hook_config *)malloc (sizeof (struct t_hook_config)); + new_hook_config = malloc (sizeof (*new_hook_config)); if (!new_hook_config) { free (new_hook); @@ -1020,10 +1020,10 @@ hook_completion (struct t_weechat_plugin *plugin, char *completion, if (!completion || !completion[0] || strchr (completion, ' ')) return NULL; - new_hook = (struct t_hook *)malloc (sizeof (struct t_hook)); + new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; - new_hook_completion = (struct t_hook_completion *)malloc (sizeof (struct t_hook_completion)); + new_hook_completion = malloc (sizeof (*new_hook_completion)); if (!new_hook_completion) { free (new_hook); @@ -1092,10 +1092,10 @@ hook_modifier (struct t_weechat_plugin *plugin, char *modifier, if (!modifier || !modifier[0]) return NULL; - new_hook = (struct t_hook *)malloc (sizeof (struct t_hook)); + new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; - new_hook_modifier = (struct t_hook_modifier *)malloc (sizeof (struct t_hook_modifier)); + new_hook_modifier = malloc (sizeof (*new_hook_modifier)); if (!new_hook_modifier) { free (new_hook); diff --git a/src/core/wee-input.c b/src/core/wee-input.c index e0f18cf3a..4f22b759e 100644 --- a/src/core/wee-input.c +++ b/src/core/wee-input.c @@ -122,9 +122,9 @@ input_exec_command (struct t_gui_buffer *buffer, char *string, /*if (cfg_irc_send_unknown_commands) { if (ptr_args) - unknown_command = (char *)malloc ((strlen (command + 1) + 1 + strlen (ptr_args) + 1) * sizeof (char)); + unknown_command = malloc (strlen (command + 1) + 1 + strlen (ptr_args) + 1); else - unknown_command = (char *)malloc ((strlen (command + 1) + 1) * sizeof (char)); + unknown_command = malloc (strlen (command + 1) + 1); if (unknown_command) { diff --git a/src/core/wee-list.c b/src/core/wee-list.c index 70ed465de..ac1e595ab 100644 --- a/src/core/wee-list.c +++ b/src/core/wee-list.c @@ -42,7 +42,7 @@ weelist_new () { struct t_weelist *new_weelist; - new_weelist = (struct t_weelist *)malloc (sizeof (struct t_weelist)); + new_weelist = malloc (sizeof (*new_weelist)); if (new_weelist) { new_weelist->items = NULL; @@ -146,7 +146,8 @@ weelist_add (struct t_weelist *weelist, char *data, char *where) if (!weelist || !data || !data[0] || !where || !where[0]) return NULL; - if ((new_item = ((struct t_weelist_item *)malloc (sizeof (struct t_weelist_item))))) + new_item = malloc (sizeof (*new_item)); + if (new_item) { new_item->data = strdup (data); weelist_insert (weelist, new_item, where); diff --git a/src/core/wee-log.c b/src/core/wee-log.c index e7229797e..65027ca40 100644 --- a/src/core/wee-log.c +++ b/src/core/wee-log.c @@ -63,8 +63,7 @@ log_open (char *filename, char *mode) else { filename_length = strlen (weechat_home) + 64; - weechat_log_filename = - (char *)malloc (filename_length * sizeof (char)); + weechat_log_filename = malloc (filename_length); snprintf (weechat_log_filename, filename_length, "%s/%s", weechat_home, WEECHAT_LOG_NAME); } @@ -204,7 +203,7 @@ log_crash_rename () log_close (); length = strlen (weechat_home) + 128; - new_name = (char *)malloc (length * sizeof (char)); + new_name = malloc (length); if (new_name) { time_now = time (NULL); diff --git a/src/core/wee-string.c b/src/core/wee-string.c index 3fc7f9866..1c6a33669 100644 --- a/src/core/wee-string.c +++ b/src/core/wee-string.c @@ -59,7 +59,7 @@ string_strndup (char *string, int length) if ((int)strlen (string) < length) return strdup (string); - result = (char *)malloc ((length + 1) * sizeof (char)); + result = malloc (length + 1); if (!result) return NULL; @@ -361,7 +361,7 @@ string_replace (char *string, char *search, char *replace) length_new = strlen (string) - (count * length1) + (count * length2) + 1; /* allocate new string */ - new_string = (char *)malloc (length_new * sizeof (char)); + new_string = malloc (length_new); if (!new_string) return strdup (string); @@ -478,7 +478,7 @@ string_convert_hex_chars (char *string) int pos_output; long number; - output = (char *)malloc ((strlen (string) + 1) * sizeof (char)); + output = malloc (strlen (string) + 1); if (output) { pos_output = 0; @@ -587,7 +587,7 @@ string_explode (char *string, char *separators, int keep_eol, if ((num_items_max != 0) && (n_items > num_items_max)) n_items = num_items_max; - array = (char **)malloc ((n_items + 1) * sizeof (char *)); + array = malloc ((n_items + 1) * sizeof (array[0])); ptr1 = string2; ptr2 = string2; @@ -632,8 +632,7 @@ string_explode (char *string, char *separators, int keep_eol, } else { - array[i] = - (char *)malloc ((ptr2 - ptr1 + 1) * sizeof (char)); + array[i] = malloc (ptr2 - ptr1 + 1); strncpy (array[i], ptr1, ptr2 - ptr1); array[i][ptr2 - ptr1] = '\0'; } @@ -694,7 +693,7 @@ string_build_with_exploded (char **exploded_string, char *separator) length += strlen (exploded_string[i]) + length_separator; } - result = (char *)malloc ((length + 1) * sizeof (char)); + result = malloc (length + 1); result[0] = '\0'; for (i = 0; exploded_string[i]; i++) @@ -733,11 +732,11 @@ string_split_command (char *command, char separator) ptr = ++p; } - array = (char **)malloc ((nb_substr + 1) * sizeof (char *)); + array = malloc ((nb_substr + 1) * sizeof (array[0])); if (!array) return NULL; - buffer = (char *)malloc ((strlen(command) + 1) * sizeof (char)); + buffer = malloc (strlen(command) + 1); if (!buffer) { free (array); @@ -787,7 +786,7 @@ string_split_command (char *command, char separator) free (buffer); - array = (char **)realloc (array, (arr_idx + 1) * sizeof(char *)); + array = realloc (array, (arr_idx + 1) * sizeof(array[0])); return array; } @@ -838,7 +837,7 @@ string_iconv (int from_utf8, char *from_code, char *to_code, char *string) ptr_inbuf = inbuf; inbytesleft = strlen (inbuf); outbytesleft = inbytesleft * 4; - outbuf = (char *)malloc ((outbytesleft + 2) * sizeof (char)); + outbuf = malloc (outbytesleft + 2); ptr_outbuf = outbuf; ptr_inbuf_shift = NULL; done = 0; diff --git a/src/core/wee-upgrade.c b/src/core/wee-upgrade.c index 4f9419860..f1b5380b0 100644 --- a/src/core/wee-upgrade.c +++ b/src/core/wee-upgrade.c @@ -600,7 +600,7 @@ session_read_str (FILE *file, char **string) if (string) { - (*string) = (char *)malloc ((length + 1) * sizeof (char)); + (*string) = malloc (length + 1); if (!(*string)) return 0; diff --git a/src/core/wee-utf8.c b/src/core/wee-utf8.c index f02238a1e..c6f6f5a4d 100644 --- a/src/core/wee-utf8.c +++ b/src/core/wee-utf8.c @@ -300,7 +300,7 @@ utf8_strlen_screen (char *string) return utf8_strlen (string); num_char = mbstowcs (NULL, string, 0) + 1; - wstring = (wchar_t *)malloc ((num_char + 1) * sizeof (wchar_t)); + wstring = malloc ((num_char + 1) * sizeof (wstring[0])); if (!wstring) return utf8_strlen (string); diff --git a/src/core/wee-util.c b/src/core/wee-util.c index cd81a94e2..c96718ff8 100644 --- a/src/core/wee-util.c +++ b/src/core/wee-util.c @@ -222,7 +222,7 @@ util_search_full_lib_name (char *filename, char *sys_directory) if (CONFIG_STRING(config_plugins_extension) && CONFIG_STRING(config_plugins_extension)[0]) length += strlen (CONFIG_STRING(config_plugins_extension)); - name_with_ext = (char *)malloc (length * sizeof (char)); + name_with_ext = malloc (length); if (!name_with_ext) return strdup (filename); strcpy (name_with_ext, filename); @@ -234,7 +234,7 @@ util_search_full_lib_name (char *filename, char *sys_directory) /* try WeeChat user's dir */ length = strlen (weechat_home) + strlen (name_with_ext) + strlen (sys_directory) + 16; - final_name = (char *)malloc (length * sizeof (char)); + final_name = malloc (length); if (!final_name) { free (name_with_ext); @@ -252,7 +252,7 @@ util_search_full_lib_name (char *filename, char *sys_directory) /* try WeeChat global lib dir */ length = strlen (WEECHAT_LIBDIR) + strlen (name_with_ext) + strlen (sys_directory) + 16; - final_name = (char *)malloc (length * sizeof (char)); + final_name = malloc (length); if (!final_name) { free (name_with_ext); diff --git a/src/core/weechat.c b/src/core/weechat.c index 3f192968d..92cd724b8 100644 --- a/src/core/weechat.c +++ b/src/core/weechat.c @@ -357,8 +357,7 @@ weechat_create_home_dirs () weechat_shutdown (EXIT_FAILURE, 0); } dir_length = strlen (ptr_home) + 10; - weechat_home = - (char *)malloc (dir_length * sizeof (char)); + weechat_home = malloc (dir_length); if (!weechat_home) { string_iconv_fprintf (stderr, |