Mercurial > mplayer.hg
changeset 5802:35f19046f809
Portability fix with realloc
author | albeu |
---|---|
date | Tue, 23 Apr 2002 20:06:00 +0000 |
parents | 81fee5d61ddb |
children | 4febd266489c |
files | asxparser.c playtree.c playtreeparser.c |
diffstat | 3 files changed, 19 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/asxparser.c Tue Apr 23 16:29:13 2002 +0000 +++ b/asxparser.c Tue Apr 23 20:06:00 2002 +0000 @@ -264,7 +264,12 @@ if( i < parser->ret_stack_size) memmove(parser->ret_stack,parser->ret_stack+i, (parser->ret_stack_size - i)*sizeof(ASX_LineSave_t)); parser->ret_stack_size -= i; - parser->ret_stack = (ASX_LineSave_t*)realloc(parser->ret_stack,parser->ret_stack_size*sizeof(ASX_LineSave_t)); + if(parser->ret_stack_size > 0) + parser->ret_stack = (ASX_LineSave_t*)realloc(parser->ret_stack,parser->ret_stack_size*sizeof(ASX_LineSave_t)); + else { + free(parser->ret_stack); + parser->ret_stack = NULL; + } } }
--- a/playtree.c Tue Apr 23 16:29:13 2002 +0000 +++ b/playtree.c Tue Apr 23 20:06:00 2002 +0000 @@ -605,7 +605,12 @@ iter->stack_size--; iter->loop = iter->status_stack[iter->stack_size]; - iter->status_stack = (int*)realloc(iter->status_stack,iter->stack_size*sizeof(int)); + if(iter->stack_size > 0) + iter->status_stack = (int*)realloc(iter->status_stack,iter->stack_size*sizeof(int)); + else { + free(iter->status_stack); + iter->status_stack = NULL; + } if(iter->stack_size > 0 && iter->status_stack == NULL) { mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",iter->stack_size*sizeof(char*)); return PLAY_TREE_ITER_ERROR;
--- a/playtreeparser.c Tue Apr 23 16:29:13 2002 +0000 +++ b/playtreeparser.c Tue Apr 23 20:06:00 2002 +0000 @@ -49,7 +49,7 @@ p->iter = p->buffer; } - if(p->stream->eof && p->buffer_end == 0) + if(p->stream->eof && (p->buffer_end == 0 || p->iter[0] == '\0')) return NULL; while(1) { @@ -83,12 +83,14 @@ } line_end = ((*(end-1)) == '\r') ? end-1 : end; - p->line = (char*)realloc(p->line,line_end - p->iter+1); - if(!p->line) + if(line_end - p->iter >= 0) + p->line = (char*)realloc(p->line,line_end - p->iter+1); + else return NULL; - strncpy(p->line,p->iter,line_end - p->iter); + if(line_end - p->iter > 0) + strncpy(p->line,p->iter,line_end - p->iter); p->line[line_end - p->iter] = '\0'; - if(end != '\0') + if(end[0] != '\0') end++; if(!p->keep) {