Ticket #1857: 1857-fixing-some-g_malloc-callsNreturn.patch

File 1857-fixing-some-g_malloc-callsNreturn.patch, 5.0 KB (added by vit_r, 15 years ago)
  • edit/bookmark.c

    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) 
    6666    if (!edit->book_mark) { 
    6767/* must have an imaginary top bookmark at line -1 to make things less complicated  */ 
    6868        edit->book_mark = g_malloc0 (sizeof (struct _book_mark)); 
     69        if (!edit->book_mark) 
     70            return NULL; 
     71             
    6972        edit->book_mark->line = -1; 
    7073        return edit->book_mark; 
    7174    } 
    book_mark_insert (WEdit *edit, int line, int c) 
    137140    edit->force |= REDRAW_LINE; 
    138141    /* create list entry */ 
    139142    q = g_malloc0 (sizeof (struct _book_mark)); 
     143    if (!q) 
     144        return; 
     145 
    140146    q->line = line; 
    141147    q->c = c; 
    142148    q->next = p->next; 
  • edit/choosesyntax.c

    diff --git a/edit/choosesyntax.c b/edit/choosesyntax.c
    index 20df935..11d6f07 100644
    a b edit_syntax_dialog (void) { 
    7070    int count = 0; 
    7171 
    7272    names = (char**) g_malloc (sizeof (char*)); 
     73    if (!names) 
     74        return; 
     75 
    7376    names[0] = NULL; 
    7477    /* We fill the list of syntax files every time the editor is invoked. 
    7578       Instead we could save the list to a file and update it once the syntax 
  • edit/editcmd.c

    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) 
    11271127    unsigned char *data; 
    11281128    cursor = edit->curs1; 
    11291129    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 
    11311134    while ((blocklen = mc_read (file, (char *) data, TEMP_BUF_LEN)) > 0) { 
    11321135        for (width = 0; width < blocklen; width++) { 
    11331136            if (data[width] == '\n') 
    edit_block_move_cmd (WEdit *edit) 
    12791282        edit_push_action (edit, COLUMN_ON); 
    12801283        column_highlighting = 0; 
    12811284    } 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 
    12831289        edit_cursor_move (edit, start_mark - edit->curs1); 
    12841290        edit_scroll_screen_over_cursor (edit); 
    12851291        count = start_mark; 
    static unsigned char * 
    18221828edit_get_block (WEdit *edit, long start, long finish, int *l) 
    18231829{ 
    18241830    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 
    18261835    if (column_highlighting) { 
    18271836        *l = 0; 
    18281837        /* copy from buffer, excluding chars that are out of the column 'margins' */ 
    edit_save_block (WEdit * edit, const char *filename, long start, 
    18781887        unsigned char *buf; 
    18791888        int i = start, end; 
    18801889        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; 
    18881902        } 
    1889         g_free (buf); 
    18901903    } 
    18911904    mc_close (file); 
    18921905    if (len) 
  • edit/etags.c

    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, 
    162162        case in_filename: 
    163163            pos = strcspn(buf, ","); 
    164164            g_free(filename); 
    165             filename = g_malloc (pos + 2); 
     165            filename = g_malloc ((pos + 2) * sizeof (*filename)); 
     166            if (!filename) 
     167                return 0; 
     168 
    166169            g_strlcpy(filename, (char *)buf, pos + 1); 
    167170            state = in_define; 
    168171            break; 
  • edit/wordproc.c

    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) 
    141141{ 
    142142    unsigned char *s, *t; 
    143143#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)); 
    146146#else 
    147     t = g_malloc (2 * (q - p) + 100); 
     147    t = g_malloc ((2 * (q - p) + 100) * sizeof (*t)); 
    148148#endif 
    149149    if (!t) 
    150150        return 0;