Mercurial > hg > index.fcgi > rcg > rcg-1
changeset 7:0b9cf47655fe
bugfixes
author | paulo@hit-nxdomain.opendns.com |
---|---|
date | Thu, 06 May 2010 23:15:40 -0700 |
parents | 910e059abd6d |
children | 5ab8d6c1a37c |
files | rcg.c |
diffstat | 1 files changed, 9 insertions(+), 5 deletions(-) [+] |
line diff
1.1 --- a/rcg.c Tue Apr 06 22:51:22 2010 -0700 1.2 +++ b/rcg.c Thu May 06 23:15:40 2010 -0700 1.3 @@ -83,13 +83,14 @@ 1.4 size_t CLR_END_len = strlen(CLR_END); 1.5 size_t CLR_CLEAR_len = strlen(CLR_CLEAR); 1.6 1.7 + char *out = NULL; 1.8 + 1.9 while (fgets(buf, BUFSIZE, stdin)) 1.10 { 1.11 int so = -1; 1.12 int eo = -1; 1.13 1.14 size_t out_len = strlen(buf) + 1; 1.15 - char *out = calloc(out_len, sizeof(char)); 1.16 unsigned int out_pos = 0; 1.17 unsigned int buf_pos = 0; 1.18 1.19 @@ -102,14 +103,18 @@ 1.20 if (out_len >= (BUFSIZE - buf_pos)) 1.21 out_len = (BUFSIZE - buf_pos) - 1; 1.22 1.23 + out = (char *)realloc(out, out_len*sizeof(char)); 1.24 + if (!out) 1.25 + exit(realloc_error()); 1.26 + 1.27 so = rem[0].rm_so; 1.28 eo = rem[0].rm_eo; 1.29 + int match_len = eo - so; 1.30 1.31 //fprintf(stderr, "%d %d \n", so, eo); //d// 20100327 PBA 1.32 1.33 - if (re_err != REG_NOMATCH && so >= 0 && eo >= 0) 1.34 + if (re_err != REG_NOMATCH && so >= 0 && eo >= 0 && match_len > 0) 1.35 { 1.36 - int match_len = eo - so; 1.37 out_len += CLR_START_len + CLR_END_len + CLR_CLEAR_len; 1.38 out = (char *)realloc(out, out_len*sizeof(char)); 1.39 if (!out) 1.40 @@ -131,12 +136,11 @@ 1.41 else 1.42 { 1.43 strncpy(&out[out_pos], &buf[buf_pos], out_len - out_pos); 1.44 - out[out_len] = '\0'; 1.45 + out[out_len - 1] = '\0'; 1.46 } 1.47 } 1.48 1.49 fputs(out, stdout); 1.50 - free(out); 1.51 } 1.52 1.53 return EXIT_OK;