Mercurial > libavcodec.hg
comparison parser.c @ 6534:23b2a64342f2 libavcodec
Return an error when realloc fails.
Patch by Andy Gocke (agocke gmail com)
| author | benoit |
|---|---|
| date | Tue, 25 Mar 2008 14:48:18 +0000 |
| parents | 493dc59d469a |
| children | d7051562c2b3 |
comparison
equal
deleted
inserted
replaced
| 6533:b4c000318ed4 | 6534:23b2a64342f2 |
|---|---|
| 222 | 222 |
| 223 /*****************************************************/ | 223 /*****************************************************/ |
| 224 | 224 |
| 225 /** | 225 /** |
| 226 * combines the (truncated) bitstream to a complete frame | 226 * combines the (truncated) bitstream to a complete frame |
| 227 * @returns -1 if no complete frame could be created | 227 * @returns -1 if no complete frame could be created, AVERROR(ENOMEM) if there was a memory allocation error |
| 228 */ | 228 */ |
| 229 int ff_combine_frame(ParseContext *pc, int next, const uint8_t **buf, int *buf_size) | 229 int ff_combine_frame(ParseContext *pc, int next, const uint8_t **buf, int *buf_size) |
| 230 { | 230 { |
| 231 #if 0 | 231 #if 0 |
| 232 if(pc->overread){ | 232 if(pc->overread){ |
| 247 | 247 |
| 248 pc->last_index= pc->index; | 248 pc->last_index= pc->index; |
| 249 | 249 |
| 250 /* copy into buffer end return */ | 250 /* copy into buffer end return */ |
| 251 if(next == END_NOT_FOUND){ | 251 if(next == END_NOT_FOUND){ |
| 252 pc->buffer= av_fast_realloc(pc->buffer, &pc->buffer_size, (*buf_size) + pc->index + FF_INPUT_BUFFER_PADDING_SIZE); | 252 void* new_buffer = av_fast_realloc(pc->buffer, &pc->buffer_size, (*buf_size) + pc->index + FF_INPUT_BUFFER_PADDING_SIZE); |
| 253 | 253 |
| 254 if(!new_buffer) | |
| 255 return AVERROR(ENOMEM); | |
| 256 pc->buffer = new_buffer; | |
| 254 memcpy(&pc->buffer[pc->index], *buf, *buf_size); | 257 memcpy(&pc->buffer[pc->index], *buf, *buf_size); |
| 255 pc->index += *buf_size; | 258 pc->index += *buf_size; |
| 256 return -1; | 259 return -1; |
| 257 } | 260 } |
| 258 | 261 |
| 259 *buf_size= | 262 *buf_size= |
| 260 pc->overread_index= pc->index + next; | 263 pc->overread_index= pc->index + next; |
| 261 | 264 |
| 262 /* append to buffer */ | 265 /* append to buffer */ |
| 263 if(pc->index){ | 266 if(pc->index){ |
| 264 pc->buffer= av_fast_realloc(pc->buffer, &pc->buffer_size, next + pc->index + FF_INPUT_BUFFER_PADDING_SIZE); | 267 void* new_buffer = av_fast_realloc(pc->buffer, &pc->buffer_size, next + pc->index + FF_INPUT_BUFFER_PADDING_SIZE); |
| 265 | 268 |
| 269 if(!new_buffer) | |
| 270 return AVERROR(ENOMEM); | |
| 271 pc->buffer = new_buffer; | |
| 266 memcpy(&pc->buffer[pc->index], *buf, next + FF_INPUT_BUFFER_PADDING_SIZE ); | 272 memcpy(&pc->buffer[pc->index], *buf, next + FF_INPUT_BUFFER_PADDING_SIZE ); |
| 267 pc->index = 0; | 273 pc->index = 0; |
| 268 *buf= pc->buffer; | 274 *buf= pc->buffer; |
| 269 } | 275 } |
| 270 | 276 |
