Mercurial > pt1
diff recpt1/recpt1.c @ 139:61ff9cabf962
fix for split buffer shortage
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Thu, 25 Apr 2013 15:08:35 +0900 |
parents | 2b057f249811 |
children | c9b1d21c5035 |
line wrap: on
line diff
--- a/recpt1/recpt1.c Thu Apr 25 15:08:34 2013 +0900 +++ b/recpt1/recpt1.c Thu Apr 25 15:08:35 2013 +0900 @@ -375,7 +375,8 @@ buf.size = 0; buf.data = NULL; - splitbuf.size = 0; + splitbuf.buffer_size = 0; + splitbuf.buffer = NULL; if(wfd == -1) fileless = TRUE; @@ -411,7 +412,17 @@ if(use_splitter) { - splitbuf.size = 0; + splitbuf.buffer_filled = 0; + + /* allocate split buffer */ + if(splitbuf.buffer_size < buf.size && buf.size > 0) { + splitbuf.buffer = realloc(splitbuf.buffer, buf.size); + if(splitbuf.buffer == NULL) { + fprintf(stderr, "split buffer allocation failed\n"); + use_splitter = FALSE; + goto fin; + } + } while(buf.size) { /* $BJ,N%BP>](BPID$B$NCj=P(B */ @@ -436,6 +447,7 @@ break; } } + /* $BJ,N%BP>]0J30$r$U$k$$Mn$H$9(B */ code = split_ts(splitter, &buf, &splitbuf); if(code == TSS_NULL) { @@ -449,7 +461,7 @@ break; } /* while */ - buf.size = splitbuf.size; + buf.size = splitbuf.buffer_filled; buf.data = splitbuf.buffer; fin: ; @@ -523,7 +535,7 @@ } buf.data = splitbuf.buffer; - buf.size = splitbuf.size; + buf.size = splitbuf.buffer_size; } if(!fileless && !file_err) { @@ -544,6 +556,12 @@ } } + if(use_splitter) { + free(splitbuf.buffer); + splitbuf.buffer = NULL; + splitbuf.buffer_size = 0; + } + break; } }