Skip to content

Commit

Permalink
avformat/argo_asf: cleanup and NULL-terminate name field in header
Browse files Browse the repository at this point in the history
Preparation for metadata changes in the following patches. Saves
having to create an extra buffer.

Signed-off-by: Zane van Iperen <[email protected]>
  • Loading branch information
vs49688 committed Oct 15, 2021
1 parent 2c734a8 commit 20fa838
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
8 changes: 4 additions & 4 deletions libavformat/argo_asf.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ void ff_argo_asf_parse_file_header(ArgoASFFileHeader *hdr, const uint8_t *buf)
hdr->version_minor = AV_RL16(buf + 6);
hdr->num_chunks = AV_RL32(buf + 8);
hdr->chunk_offset = AV_RL32(buf + 12);
for (int i = 0; i < FF_ARRAY_ELEMS(hdr->name); i++)
hdr->name[i] = AV_RL8(buf + 16 + i);
memcpy(hdr->name, buf + 16, ASF_NAME_SIZE);
hdr->name[ASF_NAME_SIZE] = '\0';
}

int ff_argo_asf_validate_file_header(AVFormatContext *s, const ArgoASFFileHeader *hdr)
Expand Down Expand Up @@ -331,7 +331,7 @@ static void argo_asf_write_file_header(const ArgoASFFileHeader *fhdr, AVIOContex
avio_wl16( pb, fhdr->version_minor);
avio_wl32( pb, fhdr->num_chunks);
avio_wl32( pb, fhdr->chunk_offset);
avio_write(pb, fhdr->name, sizeof(fhdr->name));
avio_write(pb, fhdr->name, ASF_NAME_SIZE);
}

static void argo_asf_write_chunk_header(const ArgoASFChunkHeader *ckhdr, AVIOContext *pb)
Expand Down Expand Up @@ -368,7 +368,7 @@ static int argo_asf_write_header(AVFormatContext *s)
} else {
len = end - name;
}
memcpy(fhdr.name, name, FFMIN(len, sizeof(fhdr.name)));
memcpy(fhdr.name, name, FFMIN(len, ASF_NAME_SIZE));

chdr.num_blocks = 0;
chdr.num_samples = ASF_SAMPLE_COUNT;
Expand Down
3 changes: 2 additions & 1 deletion libavformat/argo_asf.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@
#define ASF_CHUNK_HEADER_SIZE 20
#define ASF_SAMPLE_COUNT 32
#define ASF_MIN_BUFFER_SIZE FFMAX(ASF_FILE_HEADER_SIZE, ASF_CHUNK_HEADER_SIZE)
#define ASF_NAME_SIZE 8

typedef struct ArgoASFFileHeader {
uint32_t magic; /*< Magic Number, {'A', 'S', 'F', '\0'} */
uint16_t version_major; /*< File Major Version. */
uint16_t version_minor; /*< File Minor Version. */
uint32_t num_chunks; /*< No. chunks in the file. */
uint32_t chunk_offset; /*< Offset to the first chunk from the start of the file. */
int8_t name[8]; /*< Name. */
char name[ASF_NAME_SIZE + 1]; /*< Name, +1 for NULL-terminator. */
} ArgoASFFileHeader;

typedef struct ArgoASFChunkHeader {
Expand Down

0 comments on commit 20fa838

Please sign in to comment.