Browse Source

Fix off-by-one in section gathering.

When 1 byte of the section was in the next TS packet, section
gathering misses it.
Georgi Chorbadzhiyski 12 years ago
parent
commit
7d13c10049
1 changed files with 3 additions and 2 deletions
  1. 3
    2
      secdata.c

+ 3
- 2
secdata.c View File

143
 		payload_offset += sec->pointer_field + 1; // Pointer field
143
 		payload_offset += sec->pointer_field + 1; // Pointer field
144
 	}
144
 	}
145
 
145
 
146
-	int to_copy = TS_PACKET_SIZE - payload_offset;
146
+	int to_copy = min(TS_PACKET_SIZE - payload_offset, sec->section_data_len - sec->section_pos);
147
 	if (to_copy <= 0)
147
 	if (to_copy <= 0)
148
 		return;
148
 		return;
149
 
149
 
155
 	memcpy(sec->packet_data + (sec->num_packets * TS_PACKET_SIZE), ts_packet, TS_PACKET_SIZE);
155
 	memcpy(sec->packet_data + (sec->num_packets * TS_PACKET_SIZE), ts_packet, TS_PACKET_SIZE);
156
 	sec->section_pos += to_copy;
156
 	sec->section_pos += to_copy;
157
 	sec->num_packets++;
157
 	sec->num_packets++;
158
-	sec->initialized = (sec->section_pos+1) >= sec->section_data_len;
158
+	sec->initialized = (sec->section_pos+1) > sec->section_data_len;
159
+
159
 	if (sec->initialized) {
160
 	if (sec->initialized) {
160
 		// CRC is after sec->data[sec->data_len]
161
 		// CRC is after sec->data[sec->data_len]
161
 		sec->CRC = (sec->CRC << 8) | sec->data[sec->data_len + 3];
162
 		sec->CRC = (sec->CRC << 8) | sec->data[sec->data_len + 3];

Loading…
Cancel
Save