make riff int-size safe

This commit is contained in:
Bill Currie 2007-04-04 09:23:10 +00:00 committed by Jeff Teunissen
parent de265f236c
commit fcf464ef99
2 changed files with 31 additions and 27 deletions

View file

@ -32,44 +32,47 @@
#ifndef __QF_riff_h #ifndef __QF_riff_h
#define __QF_riff_h #define __QF_riff_h
#include <stdint.h>
#include <sys/types.h>
#include "QF/quakeio.h" #include "QF/quakeio.h"
typedef struct riff_d_chunk_s { typedef struct riff_d_chunk_s {
char name[4]; char name[4];
unsigned len; uint32_t len;
} riff_d_chunk_t; } riff_d_chunk_t;
typedef struct riff_d_cue_point_s { typedef struct riff_d_cue_point_s {
unsigned name; uint32_t name;
unsigned position; uint32_t position;
char chunk[4]; char chunk[4];
unsigned chunk_start; uint32_t chunk_start;
unsigned block_start; uint32_t block_start;
unsigned sample_offset; uint32_t sample_offset;
} riff_d_cue_point_t; } riff_d_cue_point_t;
typedef struct riff_d_cue_s { typedef struct riff_d_cue_s {
unsigned count; uint32_t count;
riff_d_cue_point_t cue_points[1]; riff_d_cue_point_t cue_points[1];
} riff_d_cue_t; } riff_d_cue_t;
typedef struct riff_d_format_s { typedef struct riff_d_format_s {
unsigned short format_tag; uint16_t format_tag;
unsigned short channels; uint16_t channels;
unsigned samples_per_sec; uint32_t samples_per_sec;
unsigned bytes_per_sec; uint32_t bytes_per_sec;
unsigned short align; uint16_t align;
unsigned short bits_per_sample; // only if format_tag == 1 uint16_t bits_per_sample; // only if format_tag == 1
} riff_d_format_t; } riff_d_format_t;
typedef struct riff_d_ltxt_s { typedef struct riff_d_ltxt_s {
unsigned name; uint32_t name;
unsigned len; uint32_t len;
char purpose[4]; char purpose[4];
unsigned country; uint32_t country;
unsigned language; uint32_t language;
unsigned dialect; uint32_t dialect;
unsigned codepage; uint32_t codepage;
unsigned char data[0]; unsigned char data[0];
} riff_d_ltxt_t; } riff_d_ltxt_t;
@ -91,7 +94,7 @@ typedef struct riff_ltxt_s {
typedef struct riff_label_s { typedef struct riff_label_s {
riff_d_chunk_t ck; riff_d_chunk_t ck;
unsigned ofs; off_t ofs;
char *label; char *label;
} riff_label_t; } riff_label_t;

View file

@ -131,7 +131,8 @@ read_ltxt (QFile *f, int len, riff_d_ltxt_t *ltxt)
static void static void
read_adtl (dstring_t *list_buf, QFile *f, int len) read_adtl (dstring_t *list_buf, QFile *f, int len)
{ {
riff_d_chunk_t ck, *chunk = 0; riff_d_chunk_t ck;
riff_d_chunk_t *chunk = 0;
riff_ltxt_t *ltxt; riff_ltxt_t *ltxt;
riff_label_t *label; riff_label_t *label;
riff_data_t *data; riff_data_t *data;
@ -257,7 +258,7 @@ static riff_d_cue_t *
read_cue (QFile *f, int len) read_cue (QFile *f, int len)
{ {
riff_d_cue_t *cue = malloc (len); riff_d_cue_t *cue = malloc (len);
unsigned int i; uint32_t i;
if (!Rread (f, cue, len)) { if (!Rread (f, cue, len)) {
free (cue); free (cue);