From a6b3156a2e95786932eff861fa1552eff8ec085e Mon Sep 17 00:00:00 2001
From: Vit Rosin <vit_r@list.ru>
Date: Fri, 4 Dec 2009 03:00:05 +0000
Subject: [PATCH] fixing some g_malloc callsNreturn
---
edit/bookmark.c | 6 ++++++
edit/choosesyntax.c | 3 +++
edit/editcmd.c | 35 ++++++++++++++++++++++++-----------
edit/etags.c | 5 ++++-
edit/wordproc.c | 6 +++---
5 files changed, 40 insertions(+), 15 deletions(-)
diff --git a/edit/bookmark.c b/edit/bookmark.c
index 00dfe8e..3b23c6a 100644
a
|
b
|
struct _book_mark *book_mark_find (WEdit * edit, int line) |
66 | 66 | if (!edit->book_mark) { |
67 | 67 | /* must have an imaginary top bookmark at line -1 to make things less complicated */ |
68 | 68 | edit->book_mark = g_malloc0 (sizeof (struct _book_mark)); |
| 69 | if (!edit->book_mark) |
| 70 | return NULL; |
| 71 | |
69 | 72 | edit->book_mark->line = -1; |
70 | 73 | return edit->book_mark; |
71 | 74 | } |
… |
… |
book_mark_insert (WEdit *edit, int line, int c) |
137 | 140 | edit->force |= REDRAW_LINE; |
138 | 141 | /* create list entry */ |
139 | 142 | q = g_malloc0 (sizeof (struct _book_mark)); |
| 143 | if (!q) |
| 144 | return; |
| 145 | |
140 | 146 | q->line = line; |
141 | 147 | q->c = c; |
142 | 148 | q->next = p->next; |
diff --git a/edit/choosesyntax.c b/edit/choosesyntax.c
index 20df935..11d6f07 100644
a
|
b
|
edit_syntax_dialog (void) { |
70 | 70 | int count = 0; |
71 | 71 | |
72 | 72 | names = (char**) g_malloc (sizeof (char*)); |
| 73 | if (!names) |
| 74 | return; |
| 75 | |
73 | 76 | names[0] = NULL; |
74 | 77 | /* We fill the list of syntax files every time the editor is invoked. |
75 | 78 | Instead we could save the list to a file and update it once the syntax |
diff --git a/edit/editcmd.c b/edit/editcmd.c
index 7328ac8..51f1a1f 100644
a
|
b
|
edit_insert_column_of_text_from_file (WEdit * edit, int file) |
1127 | 1127 | unsigned char *data; |
1128 | 1128 | cursor = edit->curs1; |
1129 | 1129 | col = edit_get_col (edit); |
1130 | | data = g_malloc (TEMP_BUF_LEN); |
| 1130 | data = g_malloc (TEMP_BUF_LEN * sizeof (*data)); |
| 1131 | if (!data) |
| 1132 | return 0; |
| 1133 | |
1131 | 1134 | while ((blocklen = mc_read (file, (char *) data, TEMP_BUF_LEN)) > 0) { |
1132 | 1135 | for (width = 0; width < blocklen; width++) { |
1133 | 1136 | if (data[width] == '\n') |
… |
… |
edit_block_move_cmd (WEdit *edit) |
1279 | 1282 | edit_push_action (edit, COLUMN_ON); |
1280 | 1283 | column_highlighting = 0; |
1281 | 1284 | } else { |
1282 | | copy_buf = g_malloc (end_mark - start_mark); |
| 1285 | copy_buf = g_malloc ((end_mark - start_mark) * sizeof (*copy_buf)); |
| 1286 | if (!copy_buf) |
| 1287 | return; |
| 1288 | |
1283 | 1289 | edit_cursor_move (edit, start_mark - edit->curs1); |
1284 | 1290 | edit_scroll_screen_over_cursor (edit); |
1285 | 1291 | count = start_mark; |
… |
… |
static unsigned char * |
1822 | 1828 | edit_get_block (WEdit *edit, long start, long finish, int *l) |
1823 | 1829 | { |
1824 | 1830 | unsigned char *s, *r; |
1825 | | r = s = g_malloc (finish - start + 1); |
| 1831 | r = s = g_malloc ((finish - start + 1) * sizeof (*r)); |
| 1832 | if (!r) |
| 1833 | return; |
| 1834 | |
1826 | 1835 | if (column_highlighting) { |
1827 | 1836 | *l = 0; |
1828 | 1837 | /* copy from buffer, excluding chars that are out of the column 'margins' */ |
… |
… |
edit_save_block (WEdit * edit, const char *filename, long start, |
1878 | 1887 | unsigned char *buf; |
1879 | 1888 | int i = start, end; |
1880 | 1889 | len = finish - start; |
1881 | | buf = g_malloc (TEMP_BUF_LEN); |
1882 | | while (start != finish) { |
1883 | | end = min (finish, start + TEMP_BUF_LEN); |
1884 | | for (; i < end; i++) |
1885 | | buf[i - start] = edit_get_byte (edit, i); |
1886 | | len -= mc_write (file, (char *) buf, end - start); |
1887 | | start = end; |
| 1890 | buf = g_malloc (TEMP_BUF_LEN * sizeof (*buf)); |
| 1891 | if (buf) { |
| 1892 | while (start != finish) { |
| 1893 | end = min (finish, start + TEMP_BUF_LEN); |
| 1894 | for (; i < end; i++) |
| 1895 | buf[i - start] = edit_get_byte (edit, i); |
| 1896 | len -= mc_write (file, (char *) buf, end - start); |
| 1897 | start = end; |
| 1898 | } |
| 1899 | g_free (buf); |
| 1900 | } else { |
| 1901 | len = 0; |
1888 | 1902 | } |
1889 | | g_free (buf); |
1890 | 1903 | } |
1891 | 1904 | mc_close (file); |
1892 | 1905 | if (len) |
diff --git a/edit/etags.c b/edit/etags.c
index 474203f..2b7cade 100644
a
|
b
|
int etags_set_definition_hash(const char *tagfile, const char *start_path, |
162 | 162 | case in_filename: |
163 | 163 | pos = strcspn(buf, ","); |
164 | 164 | g_free(filename); |
165 | | filename = g_malloc (pos + 2); |
| 165 | filename = g_malloc ((pos + 2) * sizeof (*filename)); |
| 166 | if (!filename) |
| 167 | return 0; |
| 168 | |
166 | 169 | g_strlcpy(filename, (char *)buf, pos + 1); |
167 | 170 | state = in_define; |
168 | 171 | break; |
diff --git a/edit/wordproc.c b/edit/wordproc.c
index e3c3055..cbdbef9 100644
a
|
b
|
get_paragraph (WEdit *edit, long p, long q, int indent, int *size) |
141 | 141 | { |
142 | 142 | unsigned char *s, *t; |
143 | 143 | #if 0 |
144 | | t = g_malloc ((q - p) + 2 * (q - p) / option_word_wrap_line_length + |
145 | | 10); |
| 144 | t = g_malloc (((q - p) + 2 * (q - p) / option_word_wrap_line_length + |
| 145 | 10) * sizeof (*t)); |
146 | 146 | #else |
147 | | t = g_malloc (2 * (q - p) + 100); |
| 147 | t = g_malloc ((2 * (q - p) + 100) * sizeof (*t)); |
148 | 148 | #endif |
149 | 149 | if (!t) |
150 | 150 | return 0; |