# HG changeset patch # User mikael # Date 1114922527 0 # Node ID ae0844311710a5b62f676e24023379d940a1127d # Parent 05f606cfb9e4e92fb9d49fc8d97ff131528f300a [/trunk] Changeset 165 by mikael * Do check on memory allocation for important data. * Decrease scr_LogPrint buffer size to 1kb. diff -r 05f606cfb9e4 -r ae0844311710 mcabber/src/hbuf.c --- 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; } diff -r 05f606cfb9e4 -r ae0844311710 mcabber/src/screen.c --- 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);