# HG changeset patch # User michael # Date 1171054152 0 # Node ID 3562fd629c3756a1b16c0251b38bd307d54a3c86 # Parent 814fbf5732eb03c82769b0a091b3f121dc1b171b fix broken memset(padding, 0) code add a few asserts diff -r 814fbf5732eb -r 3562fd629c37 asf-enc.c --- a/asf-enc.c Fri Feb 09 20:34:24 2007 +0000 +++ b/asf-enc.c Fri Feb 09 20:49:12 2007 +0000 @@ -537,6 +537,11 @@ int iLengthTypeFlags = ASF_PPI_LENGTH_TYPE_FLAGS; + padsize -= PACKET_HEADER_MIN_SIZE; + if(asf->multi_payloads_present) + padsize--; + assert(padsize>=0); + put_byte(pb, ASF_PACKET_ERROR_CORRECTION_FLAGS); for (i = 0; i < ASF_PACKET_ERROR_CORRECTION_DATA_SIZE; i++){ put_byte(pb, 0x0); @@ -587,7 +592,8 @@ asf->packet_size_left ); - packet_filled_size = PACKET_SIZE - packet_hdr_size - asf->packet_size_left; + packet_filled_size = PACKET_SIZE - asf->packet_size_left; + assert(packet_hdr_size <= asf->packet_size_left); memset(asf->packet_buf + packet_filled_size, 0, asf->packet_size_left); put_buffer(&s->pb, asf->packet_buf, asf->packet_size - packet_hdr_size); @@ -656,20 +662,18 @@ if (asf->packet_timestamp_start == -1) { asf->multi_payloads_present = (payload_len < MULTI_PAYLOAD_CONSTANT); + asf->packet_size_left = PACKET_SIZE; if (asf->multi_payloads_present){ - asf->packet_size_left = PACKET_SIZE; //For debug - asf->packet_size_left = PACKET_SIZE - PACKET_HEADER_MIN_SIZE - 1; frag_len1 = MULTI_PAYLOAD_CONSTANT - 1; } else { - asf->packet_size_left = PACKET_SIZE - PACKET_HEADER_MIN_SIZE; frag_len1 = SINGLE_PAYLOAD_DATA_LENGTH; } asf->packet_timestamp_start = timestamp; } else { // multi payloads - frag_len1 = asf->packet_size_left - PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS; + frag_len1 = asf->packet_size_left - PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS - PACKET_HEADER_MIN_SIZE - 1; asf->packet_timestamp_start = timestamp; } @@ -697,7 +701,7 @@ if (!asf->multi_payloads_present) flush_packet(s); - else if (asf->packet_size_left <= (PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS + 1)) + else if (asf->packet_size_left <= (PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS + PACKET_HEADER_MIN_SIZE + 1)) flush_packet(s); } stream->seq++;