From be8a030fa71333e1c9d47bf55af46d69df714144 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Sun, 16 Jan 2022 19:38:30 +0100 Subject: [PATCH] [mem_realloc] cast return value --- src/bfu/listmenu.c | 2 +- src/document/html/frames.c | 2 +- src/document/html/iframes.c | 4 ++-- src/document/html/parser.c | 2 +- src/document/html/parser/table.c | 4 ++-- src/dom/node.c | 2 +- src/dom/string.h | 2 +- src/encoding/brotli.c | 2 +- src/encoding/bzip2.c | 2 +- src/encoding/gzip.c | 2 +- src/encoding/lzma.c | 2 +- src/encoding/zstd.c | 4 ++-- src/intl/charsets.c | 4 ++-- src/main/event.c | 4 ++-- src/main/select.c | 2 +- src/network/socket.c | 2 +- src/protocol/fsp/fsp.c | 2 +- src/protocol/ftp/ftp.c | 2 +- src/protocol/http/post.c | 2 +- src/protocol/smb/smb2.c | 2 +- src/scripting/lua/core.c | 2 +- src/terminal/event.c | 2 +- src/terminal/kbd.c | 2 +- src/terminal/screen.c | 2 +- src/util/fastfind.c | 2 +- src/util/file.c | 4 ++-- src/util/memlist.c | 4 ++-- src/util/string.c | 6 +++--- src/viewer/text/form.c | 2 +- 29 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/bfu/listmenu.c b/src/bfu/listmenu.c index a6db75a7..1c02d800 100644 --- a/src/bfu/listmenu.c +++ b/src/bfu/listmenu.c @@ -82,7 +82,7 @@ new_menu_item(struct list_menu *menu, char *name, int data, int fullname) if (data == -1) { int size = (menu->stack_size + 1) * sizeof(*menu->stack); - struct menu_item **stack = mem_realloc(menu->stack, size); + struct menu_item **stack = (struct menu_item **)mem_realloc(menu->stack, size); if (stack) { menu->stack = stack; diff --git a/src/document/html/frames.c b/src/document/html/frames.c index 22443aba..ed909ab5 100644 --- a/src/document/html/frames.c +++ b/src/document/html/frames.c @@ -428,7 +428,7 @@ extract_rows_or_cols_values(char *str, int max_value, int pixels_per_char, } /* Save value. */ - tmp_values = mem_realloc(values, (values_count + 1) * sizeof(*tmp_values)); + tmp_values = (int *)mem_realloc(values, (values_count + 1) * sizeof(*tmp_values)); if (!tmp_values) return 0; values = tmp_values; diff --git a/src/document/html/iframes.c b/src/document/html/iframes.c index abcbfb19..3635c39a 100644 --- a/src/document/html/iframes.c +++ b/src/document/html/iframes.c @@ -37,9 +37,9 @@ void add_iframeset_entry(struct iframeset_desc **parent, if_assert_failed return; if (!*parent) { - *parent = mem_calloc(1, sizeof(struct iframeset_desc)); + *parent = (struct iframeset_desc *)mem_calloc(1, sizeof(struct iframeset_desc)); } else { - *parent = mem_realloc(*parent, sizeof(struct iframeset_desc) + ((*parent)->n + 1) * sizeof(struct iframe_desc)); + *parent = (struct iframeset_desc *)mem_realloc(*parent, sizeof(struct iframeset_desc) + ((*parent)->n + 1) * sizeof(struct iframe_desc)); } if (!*parent) return; diff --git a/src/document/html/parser.c b/src/document/html/parser.c index 4dab7373..326b9df4 100644 --- a/src/document/html/parser.c +++ b/src/document/html/parser.c @@ -633,7 +633,7 @@ look_for_link(char **pos, char *eof, struct menu_item **menu, } } - nm = mem_realloc(*menu, (nmenu + 2) * sizeof(*nm)); + nm = (struct menu_item *)mem_realloc(*menu, (nmenu + 2) * sizeof(*nm)); if (nm) { *menu = nm; memset(&nm[nmenu], 0, 2 * sizeof(*nm)); diff --git a/src/document/html/parser/table.c b/src/document/html/parser/table.c index 1de5b992..fa283301 100644 --- a/src/document/html/parser/table.c +++ b/src/document/html/parser/table.c @@ -446,7 +446,7 @@ new_columns(struct table *table, int span, int width, int align, sizeof(*new_columns), SMART_RAISE_LIMIT); if (!n) return; - new_columns = mem_realloc(table->columns, n * sizeof(*new_columns)); + new_columns = (struct table_column *)mem_realloc(table->columns, n * sizeof(*new_columns)); if (!new_columns) return; table->real_columns_count = n; @@ -476,7 +476,7 @@ set_td_width(struct table *table, int col, int width, int force) if (!n && table->cols_x_count) return; if (!n) n = col + 1; - new_cols_x = mem_realloc(table->cols_x, n * sizeof(*new_cols_x)); + new_cols_x = (int *)mem_realloc(table->cols_x, n * sizeof(*new_cols_x)); if (!new_cols_x) return; for (i = table->cols_x_count; i < n; i++) diff --git a/src/dom/node.c b/src/dom/node.c index cfb15e73..b5848f14 100644 --- a/src/dom/node.c +++ b/src/dom/node.c @@ -38,7 +38,7 @@ realloc_dom_node_list(struct dom_node_list **oldlist) if (newsize <= oldsize) return list; - list = mem_realloc(list, DOM_NODE_LIST_SIZE(newsize)); + list = (struct dom_node_list *)mem_realloc(list, DOM_NODE_LIST_SIZE(newsize)); if (!list) return NULL; /* If this is the first reallocation clear the size */ diff --git a/src/dom/string.h b/src/dom/string.h index d348f4bd..5ec0b19d 100644 --- a/src/dom/string.h +++ b/src/dom/string.h @@ -57,7 +57,7 @@ add_to_dom_string(struct dom_string *string, char *str, size_t len) { char *newstring; - newstring = mem_realloc(string->string, string->length + len + 1); + newstring = (char *)mem_realloc(string->string, string->length + len + 1); if (!newstring) return NULL; diff --git a/src/encoding/brotli.c b/src/encoding/brotli.c index 25f56e15..6d88f7bd 100644 --- a/src/encoding/brotli.c +++ b/src/encoding/brotli.c @@ -131,7 +131,7 @@ brotli_decode_buffer(struct stream_encoded *st, char *datac, int len, int *new_l do { char *new_buffer; size_t size = enc_data->total_out + ELINKS_BROTLI_BUFFER_LENGTH; - new_buffer = mem_realloc(enc_data->buffer, size); + new_buffer = (char *)mem_realloc(enc_data->buffer, size); if (!new_buffer) { error = BROTLI_DECODER_RESULT_ERROR; diff --git a/src/encoding/bzip2.c b/src/encoding/bzip2.c index 69df7a42..8591d634 100644 --- a/src/encoding/bzip2.c +++ b/src/encoding/bzip2.c @@ -159,7 +159,7 @@ bzip2_decode_buffer(struct stream_encoded *st, char *data, int len, int *new_len * --jonas */ assertm(!stream->total_out_hi32, "64 bzip2 decoding not supported"); - new_buffer = mem_realloc(buffer, size); + new_buffer = (char *)mem_realloc(buffer, size); if (!new_buffer) { error = BZ_MEM_ERROR; break; diff --git a/src/encoding/gzip.c b/src/encoding/gzip.c index dfb64f5c..bb966c87 100644 --- a/src/encoding/gzip.c +++ b/src/encoding/gzip.c @@ -185,7 +185,7 @@ deflate_decode_buffer(struct stream_encoded *st, int window_size, char *datac, i unsigned char *new_buffer; size_t size = stream->total_out + MAX_STR_LEN; - new_buffer = mem_realloc(buffer, size); + new_buffer = (unsigned char *)mem_realloc(buffer, size); if (!new_buffer) { error = Z_MEM_ERROR; break; diff --git a/src/encoding/lzma.c b/src/encoding/lzma.c index b870e6cb..bf58416b 100644 --- a/src/encoding/lzma.c +++ b/src/encoding/lzma.c @@ -127,7 +127,7 @@ lzma_decode_buffer(struct stream_encoded *st, unsigned char *data, int len, int char *new_buffer; size_t size = stream->total_out + MAX_STR_LEN; - new_buffer = mem_realloc(buffer, size); + new_buffer = (char *)mem_realloc(buffer, size); if (!new_buffer) { error = LZMA_MEM_ERROR; break; diff --git a/src/encoding/zstd.c b/src/encoding/zstd.c index f5b6d59e..1ac6f954 100644 --- a/src/encoding/zstd.c +++ b/src/encoding/zstd.c @@ -76,7 +76,7 @@ zstd_decode_buffer(struct stream_encoded *st, char *data, int len, int *new_len) char *new_buffer; size_t size = enc_data->output.size + ELINKS_ZSTD_BUFFER_LENGTH; - new_buffer = mem_realloc(enc_data->output.dst, size); + new_buffer = (char *)mem_realloc(enc_data->output.dst, size); if (!new_buffer) { error = 1; break; @@ -109,7 +109,7 @@ zstd_read(struct stream_encoded *stream, char *buf, int len) if (!data->decoded) { size_t read_pos = 0; - char *tmp_buf = malloc(len); + char *tmp_buf = (char *)mem_alloc(len); int new_len; if (!tmp_buf) { diff --git a/src/intl/charsets.c b/src/intl/charsets.c index be1e9905..53e0dfdc 100644 --- a/src/intl/charsets.c +++ b/src/intl/charsets.c @@ -823,7 +823,7 @@ get_combined(unicode_val_T *data, int length) last_combined++; indeks = last_combined - UCS_BEGIN_COMBINED; - combined = mem_realloc(combined, sizeof(*combined) * (indeks + 1)); + combined = (unicode_val_T **)mem_realloc(combined, sizeof(*combined) * (indeks + 1)); if (!combined) { mem_free(key); last_combined--; @@ -1459,7 +1459,7 @@ flush: callback(callback_data, buffer, bufferpos); bufferpos = 0; } else { - new_ = mem_realloc(buffer, bufferpos + ALLOC_GR); + new_ = (char *)mem_realloc(buffer, bufferpos + ALLOC_GR); if (!new_) { mem_free(buffer); return NULL; diff --git a/src/main/event.c b/src/main/event.c index dc65029f..487d1bab 100644 --- a/src/main/event.c +++ b/src/main/event.c @@ -219,7 +219,7 @@ register_event_hook(int id, event_hook_T callback, int priority, void *data) if (i == event->count) { struct event_handler *eh; - eh = mem_realloc(event->handlers, + eh = (struct event_handler *)mem_realloc(event->handlers, (event->count + 1) * sizeof(*event->handlers)); if (!eh) return EVENT_NONE; @@ -268,7 +268,7 @@ unregister_event_hook(int id, event_hook_T callback) } else { struct event_handler *eh; - eh = mem_realloc(event->handlers, + eh = (struct event_handler *)mem_realloc(event->handlers, event->count * sizeof(*event->handlers)); if (eh) event->handlers = eh; } diff --git a/src/main/select.c b/src/main/select.c index 792b2607..d893a758 100644 --- a/src/main/select.c +++ b/src/main/select.c @@ -418,7 +418,7 @@ set_handlers(int fd, select_handler_T read_func, select_handler_T write_func, return; } if (fd >= n_threads) { - struct thread *tmp_threads = mem_realloc(threads, (fd + 1) * sizeof(struct thread)); + struct thread *tmp_threads = (struct thread *)mem_realloc(threads, (fd + 1) * sizeof(struct thread)); if (!tmp_threads) { elinks_internal("out of memory"); diff --git a/src/network/socket.c b/src/network/socket.c index f053f843..5e982e6e 100644 --- a/src/network/socket.c +++ b/src/network/socket.c @@ -960,7 +960,7 @@ read_select(struct socket *socket) if (!rb->freespace) { int size = RD_SIZE(rb, rb->length); - rb = mem_realloc(rb, size); + rb = (struct read_buffer *)mem_realloc(rb, size); if (!rb) { socket->ops->done(socket, connection_state(S_OUT_OF_MEM)); return; diff --git a/src/protocol/fsp/fsp.c b/src/protocol/fsp/fsp.c index 439ddf79..f77e4582 100644 --- a/src/protocol/fsp/fsp.c +++ b/src/protocol/fsp/fsp.c @@ -191,7 +191,7 @@ sort_and_display_entries(FSP_DIR *dir, const char dircolor[]) if (!fresult) break; if (!strcmp(fentry.name, ".")) continue; - new_table = mem_realloc(table, (size + 1) * sizeof(*table)); + new_table = (FSP_RDENTRY *)mem_realloc(table, (size + 1) * sizeof(*table)); if (!new_table) continue; table = new_table; diff --git a/src/protocol/ftp/ftp.c b/src/protocol/ftp/ftp.c index 58127441..4184ae55 100644 --- a/src/protocol/ftp/ftp.c +++ b/src/protocol/ftp/ftp.c @@ -808,7 +808,7 @@ add_file_cmd_to_str(struct connection *conn) ftp->opc = ftp->pending_commands; /* 1 byte is already reserved for cmd_buffer in struct ftp_connection_info. */ - ftp = mem_realloc(ftp, sizeof(*ftp) + command.length); + ftp = (struct ftp_connection_info *)mem_realloc(ftp, sizeof(*ftp) + command.length); if (!ftp) { abort_connection(conn, connection_state(S_OUT_OF_MEM)); goto ret; diff --git a/src/protocol/http/post.c b/src/protocol/http/post.c index 39c8176d..347d5778 100644 --- a/src/protocol/http/post.c +++ b/src/protocol/http/post.c @@ -125,7 +125,7 @@ open_http_post(struct http_post *http_post, const char *post_data, /* This use of mem_realloc() in a loop consumes O(n^2) * time but how many files are you really going to * upload in one request? */ - new_files = mem_realloc(http_post->files, + new_files = (struct http_post_file *)mem_realloc(http_post->files, (http_post->file_count + 1) * sizeof(*new_files)); if (new_files == NULL) { diff --git a/src/protocol/smb/smb2.c b/src/protocol/smb/smb2.c index 3ec53d05..b643c315 100644 --- a/src/protocol/smb/smb2.c +++ b/src/protocol/smb/smb2.c @@ -93,7 +93,7 @@ get_smb_directory_entries(int dir, struct string *prefix) if (!strcmp(entry->name, ".")) continue; - new_entries = mem_realloc(entries, (size + 2) * sizeof(*new_entries)); + new_entries = (struct directory_entry *)mem_realloc(entries, (size + 2) * sizeof(*new_entries)); if (!new_entries) continue; entries = new_entries; diff --git a/src/scripting/lua/core.c b/src/scripting/lua/core.c index 92c3ffd8..4f6dcdaf 100644 --- a/src/scripting/lua/core.c +++ b/src/scripting/lua/core.c @@ -225,7 +225,7 @@ l_pipe_read(LS) size_t l = fread(buf, 1, sizeof(buf), fp); if (l > 0) { - char *news = mem_realloc(s, len + l); + char *news = (char *)mem_realloc(s, len + l); if (!news) goto lua_error; s = news; diff --git a/src/terminal/event.c b/src/terminal/event.c index 1646b5af..45850d69 100644 --- a/src/terminal/event.c +++ b/src/terminal/event.c @@ -469,7 +469,7 @@ in_term(struct terminal *term) int queuesize = ((qlen + ALLOC_GR) & ~(ALLOC_GR - 1)); int newsize = sizeof(*interlink) + queuesize; - interlink = mem_realloc(interlink, newsize); + interlink = (struct terminal_interlink *)mem_realloc(interlink, newsize); if (!interlink) { destroy_terminal(term); return; diff --git a/src/terminal/kbd.c b/src/terminal/kbd.c index 55333dc7..d274c06b 100644 --- a/src/terminal/kbd.c +++ b/src/terminal/kbd.c @@ -124,7 +124,7 @@ itrm_queue_event(struct itrm *itrm, char *data, int len) if (w < len) { int left = len - w; - unsigned char *c = mem_realloc(itrm->out.queue.data, + unsigned char *c = (unsigned char *)mem_realloc(itrm->out.queue.data, itrm->out.queue.len + left); if (!c) { diff --git a/src/terminal/screen.c b/src/terminal/screen.c index c9837ef8..7ec57dda 100644 --- a/src/terminal/screen.c +++ b/src/terminal/screen.c @@ -1493,7 +1493,7 @@ resize_screen(struct terminal *term, int width, int height) bsize = size * sizeof(*image); - image = mem_realloc(screen->image, bsize * 2); + image = (struct screen_char *)mem_realloc(screen->image, bsize * 2); if (!image) return; screen->image = image; diff --git a/src/util/fastfind.c b/src/util/fastfind.c index 64741a9c..4f1d16a3 100644 --- a/src/util/fastfind.c +++ b/src/util/fastfind.c @@ -346,7 +346,7 @@ alloc_leafset(struct fastfind_info *info) /* info->leafsets[0] is never used since l=0 marks no leaf * in struct ff_node. That's the reason of that + 2. */ - leafsets = mem_realloc(info->leafsets, + leafsets = (struct ff_node **)mem_realloc(info->leafsets, sizeof(*leafsets) * (info->leafsets_count + 2)); if (!leafsets) return 0; info->leafsets = leafsets; diff --git a/src/util/file.c b/src/util/file.c index 8fad8c11..398e0a8f 100644 --- a/src/util/file.c +++ b/src/util/file.c @@ -214,7 +214,7 @@ file_read_line(char *line, size_t *size, FILE *file, int *lineno) offset = *size - 1; *size += MAX_STR_LEN; - newline = mem_realloc(line, *size); + newline = (char *)mem_realloc(line, *size); if (!newline) break; line = newline; @@ -332,7 +332,7 @@ get_directory_entries(char *dirname, int get_hidden) if (!file_visible(entry->d_name, get_hidden, is_root_directory)) continue; - new_entries = mem_realloc(entries, (size + 2) * sizeof(*new_entries)); + new_entries = (struct directory_entry *)mem_realloc(entries, (size + 2) * sizeof(*new_entries)); if (!new_entries) continue; entries = new_entries; diff --git a/src/util/memlist.c b/src/util/memlist.c index c8f8e42c..7c21851d 100644 --- a/src/util/memlist.c +++ b/src/util/memlist.c @@ -114,7 +114,7 @@ add_to_ml(struct memory_list **ml, ...) /* Enlarge existing ml. */ struct memory_list *nml; - nml = mem_realloc(*ml, ML_SIZE(n + (*ml)->n)); + nml = (struct memory_list *)mem_realloc(*ml, ML_SIZE(n + (*ml)->n)); if (!nml) return; *ml = nml; @@ -155,7 +155,7 @@ add_one_to_ml(struct memory_list **ml, void *p) /* Enlarge existing ml. */ struct memory_list *nml; - nml = mem_realloc(*ml, ML_SIZE(1 + (*ml)->n)); + nml = (struct memory_list *)mem_realloc(*ml, ML_SIZE(1 + (*ml)->n)); if (!nml) return; *ml = nml; diff --git a/src/util/string.c b/src/util/string.c index 23633320..e3b7d164 100644 --- a/src/util/string.c +++ b/src/util/string.c @@ -110,7 +110,7 @@ add_to_strn(char **dst, const char *src) dstlen = strlen(*dst); srclen = strlen(src) + 1; /* Include the NUL char! */ - newdst = mem_realloc(*dst, dstlen + srclen); + newdst = (char *)mem_realloc(*dst, dstlen + srclen); if (!newdst) return; memcpy(newdst + dstlen, src, srclen); @@ -122,7 +122,7 @@ insert_in_string(char **dst, int pos, const char *seq, int seqlen) { int dstlen = strlen(*dst); - char *string = mem_realloc(*dst, dstlen + seqlen + 1); + char *string = (char *)mem_realloc(*dst, dstlen + seqlen + 1); if (!string) return NULL; @@ -157,7 +157,7 @@ straconcat(const char *str, ...) if (!l) continue; - ns = mem_realloc(s, len + 1 + l); + ns = (char *)mem_realloc(s, len + 1 + l); if (!ns) { mem_free(s); va_end(ap); diff --git a/src/viewer/text/form.c b/src/viewer/text/form.c index dfcd9826..82da7c3f 100644 --- a/src/viewer/text/form.c +++ b/src/viewer/text/form.c @@ -1645,7 +1645,7 @@ field_op(struct session *ses, struct document_view *doc_view, length = strlen(text); if (length <= fc->maxlength) { - char *v = mem_realloc(fs->value, length + 1); + char *v = (char *)mem_realloc(fs->value, length + 1); if (v) { fs->value = v;