Mercurial > hg
comparison mcabber/src/hbuf.c @ 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 | 5647381a7dfb |
children | f7b03201877a |
comparison
equal
deleted
inserted
replaced
152:05f606cfb9e4 | 153:ae0844311710 |
---|---|
59 | 59 |
60 hbuf_block_elt = g_new0(hbuf_block, 1); | 60 hbuf_block_elt = g_new0(hbuf_block, 1); |
61 if (prefix) | 61 if (prefix) |
62 strncpy(hbuf_block_elt->persist.prefix, prefix, PREFIX_LENGTH-1); | 62 strncpy(hbuf_block_elt->persist.prefix, prefix, PREFIX_LENGTH-1); |
63 if (!hbuf) { | 63 if (!hbuf) { |
64 hbuf_block_elt->ptr = g_new(char, HBB_BLOCKSIZE); | 64 do { |
65 hbuf_block_elt->ptr = g_new(char, HBB_BLOCKSIZE); | |
66 } while (!hbuf_block_elt->ptr); | |
65 hbuf_block_elt->flags = HBB_FLAG_ALLOC | HBB_FLAG_PERSISTENT; | 67 hbuf_block_elt->flags = HBB_FLAG_ALLOC | HBB_FLAG_PERSISTENT; |
66 hbuf_block_elt->persist.ptr_end_alloc = hbuf_block_elt->ptr + HBB_BLOCKSIZE; | 68 hbuf_block_elt->persist.ptr_end_alloc = hbuf_block_elt->ptr + HBB_BLOCKSIZE; |
67 *p_hbuf = g_list_append(*p_hbuf, hbuf_block_elt); | 69 *p_hbuf = g_list_append(*p_hbuf, hbuf_block_elt); |
68 } else { | 70 } else { |
69 hbuf_block *hbuf_b_prev = g_list_last(hbuf)->data; | 71 hbuf_block *hbuf_b_prev = g_list_last(hbuf)->data; |
77 // Too long | 79 // Too long |
78 text = "[ERR:LINE_TOO_LONG]"; | 80 text = "[ERR:LINE_TOO_LONG]"; |
79 } | 81 } |
80 if (hbuf_block_elt->ptr + strlen(text) >= hbuf_block_elt->persist.ptr_end_alloc) { | 82 if (hbuf_block_elt->ptr + strlen(text) >= hbuf_block_elt->persist.ptr_end_alloc) { |
81 // Too long for the current allocated bloc, we need another one | 83 // Too long for the current allocated bloc, we need another one |
82 hbuf_block_elt->ptr = g_new0(char, HBB_BLOCKSIZE); | 84 do { |
85 hbuf_block_elt->ptr = g_new0(char, HBB_BLOCKSIZE); | |
86 } while (!hbuf_block_elt->ptr); | |
83 hbuf_block_elt->flags = HBB_FLAG_ALLOC | HBB_FLAG_PERSISTENT; | 87 hbuf_block_elt->flags = HBB_FLAG_ALLOC | HBB_FLAG_PERSISTENT; |
84 hbuf_block_elt->persist.ptr_end_alloc = hbuf_block_elt->ptr + HBB_BLOCKSIZE; | 88 hbuf_block_elt->persist.ptr_end_alloc = hbuf_block_elt->ptr + HBB_BLOCKSIZE; |
85 } | 89 } |
86 | 90 |
87 line = hbuf_block_elt->ptr; | 91 line = hbuf_block_elt->ptr; |