Mercurial > hg
changeset 153:ae0844311710
[/trunk] Changeset 165 by mikael
* Do check on memory allocation for important data.
* Decrease scr_LogPrint buffer size to 1kb.
author | mikael |
---|---|
date | Sun, 01 May 2005 04:42:07 +0000 |
parents | 05f606cfb9e4 |
children | 8630b7cae87b |
files | mcabber/src/hbuf.c mcabber/src/screen.c |
diffstat | 2 files changed, 17 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/mcabber/src/hbuf.c Sun May 01 04:05:40 2005 +0000 +++ b/mcabber/src/hbuf.c Sun May 01 04:42:07 2005 +0000 @@ -61,7 +61,9 @@ if (prefix) strncpy(hbuf_block_elt->persist.prefix, prefix, PREFIX_LENGTH-1); if (!hbuf) { - hbuf_block_elt->ptr = g_new(char, HBB_BLOCKSIZE); + do { + hbuf_block_elt->ptr = g_new(char, HBB_BLOCKSIZE); + } while (!hbuf_block_elt->ptr); hbuf_block_elt->flags = HBB_FLAG_ALLOC | HBB_FLAG_PERSISTENT; hbuf_block_elt->persist.ptr_end_alloc = hbuf_block_elt->ptr + HBB_BLOCKSIZE; *p_hbuf = g_list_append(*p_hbuf, hbuf_block_elt); @@ -79,7 +81,9 @@ } if (hbuf_block_elt->ptr + strlen(text) >= hbuf_block_elt->persist.ptr_end_alloc) { // Too long for the current allocated bloc, we need another one - hbuf_block_elt->ptr = g_new0(char, HBB_BLOCKSIZE); + do { + hbuf_block_elt->ptr = g_new0(char, HBB_BLOCKSIZE); + } while (!hbuf_block_elt->ptr); hbuf_block_elt->flags = HBB_FLAG_ALLOC | HBB_FLAG_PERSISTENT; hbuf_block_elt->persist.ptr_end_alloc = hbuf_block_elt->ptr + HBB_BLOCKSIZE; }
--- a/mcabber/src/screen.c Sun May 01 04:05:40 2005 +0000 +++ b/mcabber/src/screen.c Sun May 01 04:42:07 2005 +0000 @@ -184,7 +184,11 @@ int y; int lines; int cols; - window_entry_t *tmp = calloc(1, sizeof(window_entry_t)); + window_entry_t *tmp; + + do { + tmp = calloc(1, sizeof(window_entry_t)); + } while (!tmp); // Dimensions x = ROSTER_WIDTH; @@ -194,8 +198,8 @@ tmp->win = newwin(lines, cols, y, x); tmp->panel = new_panel(tmp->win); - tmp->name = (char *) calloc(1, 1024); - strncpy(tmp->name, title, 1024); + tmp->name = (char *) calloc(1, 96); + strncpy(tmp->name, title, 96); scr_clear_box(tmp->win, 0, 0, lines, cols, COLOR_GENERAL); if (!dont_show) { @@ -928,14 +932,16 @@ char *buffer; va_list ap; - buffer = (char *) calloc(1, 4096); + do { + buffer = (char *) calloc(1, 1024); + } while (!buffer); timestamp = time(NULL); strftime(buffer, 64, "[%H:%M:%S] ", localtime(×tamp)); wprintw(logWnd, "\n%s", buffer); va_start(ap, fmt); - vsnprintf(buffer, 4096, fmt, ap); + vsnprintf(buffer, 1024, fmt, ap); va_end(ap); wprintw(logWnd, "%s", buffer);