Commit ee5a2fcc authored by Monty's avatar Monty
Browse files

fixes to prevent segfaults

svn path=/trunk/vorbis/; revision=271
parent 6533d0e2
......@@ -12,7 +12,7 @@
********************************************************************
function: PCM data vector blocking, windowing and dis/reassembly
last mod: $Id: block.c,v 1.26 2000/02/23 09:24:23 xiphmont Exp $
last mod: $Id: block.c,v 1.27 2000/02/23 11:22:43 xiphmont Exp $
Handle windowing, overlap-add, etc of the PCM vectors. This is made
more amusing by Vorbis' current two allowed block sizes.
......@@ -268,12 +268,14 @@ void vorbis_dsp_clear(vorbis_dsp_state *v){
if(v){
vorbis_info *vi=v->vi;
for(i=0;i<VI_WINDOWB;i++){
if(v->window[0][0][0][i])free(v->window[0][0][0][i]);
for(j=0;j<2;j++)
for(k=0;k<2;k++)
if(v->window[1][j][k][i])free(v->window[1][j][k][i]);
}
if(v->window[0][0][0])
for(i=0;i<VI_WINDOWB;i++){
if(v->window[0][0][0][i])free(v->window[0][0][0][i]);
for(j=0;j<2;j++)
for(k=0;k<2;k++)
if(v->window[1][j][k][i])free(v->window[1][j][k][i]);
}
if(v->pcm){
for(i=0;i<vi->channels;i++)
if(v->pcm[i])free(v->pcm[i]);
......@@ -283,25 +285,30 @@ void vorbis_dsp_clear(vorbis_dsp_state *v){
if(v->multipliers)free(v->multipliers);
_ve_envelope_clear(&v->ve);
mdct_clear(v->transform[0][0]);
mdct_clear(v->transform[1][0]);
free(v->transform[0][0]);
free(v->transform[1][0]);
free(v->transform[0]);
free(v->transform[1]);
if(v->transform[0]){
mdct_clear(v->transform[0][0]);
free(v->transform[0][0]);
free(v->transform[0]);
}
if(v->transform[1]){
mdct_clear(v->transform[1][0]);
free(v->transform[1][0]);
free(v->transform[1]);
}
/* free mode lookups; these are actually vorbis_look_mapping structs */
for(i=0;i<vi->modes;i++){
int mapnum=vi->mode_param[i]->mapping;
int maptype=vi->map_type[mapnum];
_mapping_P[maptype]->free_look(v->mode[i]);
if(vi){
for(i=0;i<vi->modes;i++){
int mapnum=vi->mode_param[i]->mapping;
int maptype=vi->map_type[mapnum];
_mapping_P[maptype]->free_look(v->mode[i]);
}
/* free codebooks */
for(i=0;i<vi->books;i++)
vorbis_book_clear(v->fullbooks+i);
}
if(v->mode)free(v->mode);
/* free codebooks */
for(i=0;i<vi->books;i++)
vorbis_book_clear(v->fullbooks+i);
if(v->mode)free(v->mode);
if(v->fullbooks)free(v->fullbooks);
/* free header, header1, header2 */
......
......@@ -12,7 +12,7 @@
********************************************************************
function: floor backend 0 implementation
last mod: $Id: floor0.c,v 1.10 2000/02/23 09:24:27 xiphmont Exp $
last mod: $Id: floor0.c,v 1.11 2000/02/23 11:22:44 xiphmont Exp $
********************************************************************/
......@@ -191,11 +191,11 @@ static int forward(vorbis_block *vb,vorbis_look_floor *i,
/* take the coefficients back to a spectral envelope curve */
vorbis_lsp_to_lpc(out,out,look->m);
vorbis_lpc_to_curve(out,out,amp,&look->lpclook);
fprintf(stderr,"Encoded %d LSP coefficients in %d bits\n",look->m,bits);
fprintf(stderr,"Encoded %ld LSP coefficients in %ld bits\n",look->m,bits);
return(1);
}
fprintf(stderr,"Encoded %d LSP coefficients in %d bits\n",look->m,bits);
fprintf(stderr,"Encoded %ld LSP coefficients in %ld bits\n",look->m,bits);
memset(out,0,sizeof(double)*look->n);
return(0);
......
......@@ -12,7 +12,7 @@
********************************************************************
function: maintain the info structure, info <-> header packets
last mod: $Id: info.c,v 1.20 2000/02/06 13:39:41 xiphmont Exp $
last mod: $Id: info.c,v 1.21 2000/02/23 11:22:45 xiphmont Exp $
********************************************************************/
......@@ -270,14 +270,15 @@ int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,ogg_packet *op)
/* Also verify header-ness, vorbis */
{
char buffer[6];
int packtype=_oggpack_read(&opb,8);
memset(buffer,0,6);
_v_readstring(&opb,buffer,6);
if(memcmp(buffer,"vorbis",6)){
/* not a vorbis header */
return(-1);
}
switch(_oggpack_read(&opb,8)){
case 0x80:
switch(packtype){
case 0x01: /* least significant *bit* is read first */
if(!op->b_o_s){
/* Not the initial packet */
return(-1);
......@@ -289,7 +290,7 @@ int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,ogg_packet *op)
return(_vorbis_unpack_info(vi,&opb));
case 0x81:
case 0x03: /* least significant *bit* is read first */
if(vi->rate==0){
/* um... we didn't get the initial header */
return(-1);
......@@ -297,7 +298,7 @@ int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,ogg_packet *op)
return(_vorbis_unpack_comment(vc,&opb));
case 0x82:
case 0x05: /* least significant *bit* is read first */
if(vi->rate==0 || vc->vendor==NULL){
/* um... we didn;t get the initial header or comments yet */
return(-1);
......@@ -319,8 +320,8 @@ int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,ogg_packet *op)
static int _vorbis_pack_info(oggpack_buffer *opb,vorbis_info *vi){
/* preamble */
_oggpack_write(opb,0x01,8);
_v_writestring(opb,"vorbis");
_oggpack_write(opb,0x80,8);
/* basic information about the stream */
_oggpack_write(opb,0x00,32);
......@@ -342,8 +343,8 @@ static int _vorbis_pack_comment(oggpack_buffer *opb,vorbis_comment *vc){
char temp[]="Xiphophorus libVorbis I 20000121";
/* preamble */
_oggpack_write(opb,0x03,8);
_v_writestring(opb,"vorbis");
_oggpack_write(opb,0x81,8);
/* vendor */
_oggpack_write(opb,strlen(temp),32);
......@@ -370,8 +371,8 @@ static int _vorbis_pack_comment(oggpack_buffer *opb,vorbis_comment *vc){
static int _vorbis_pack_books(oggpack_buffer *opb,vorbis_info *vi){
int i;
_oggpack_write(opb,0x05,8);
_v_writestring(opb,"vorbis");
_oggpack_write(opb,0x82,8);
/* books */
_oggpack_write(opb,vi->books-1,8);
......
......@@ -12,7 +12,7 @@
********************************************************************
function: residue backend 0 implementation
last mod: $Id: res0.c,v 1.7 2000/02/23 09:24:31 xiphmont Exp $
last mod: $Id: res0.c,v 1.8 2000/02/23 11:22:46 xiphmont Exp $
********************************************************************/
......@@ -68,7 +68,6 @@ void free_look(vorbis_look_residue *i){
}
}
/* not yet */
void pack(vorbis_info_residue *vr,oggpack_buffer *opb){
vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
int j,acc=0;
......@@ -314,7 +313,7 @@ int forward(vorbis_block *vb,vorbis_look_residue *vl,
}
for(i=0;i<possible_partitions;i++)resbitsT+=resbits[i];
fprintf(stderr,"Encoded %ld res vectors in %d phrasing and %d res bits\n\t",
fprintf(stderr,"Encoded %ld res vectors in %ld phrasing and %ld res bits\n\t",
ch*(info->end-info->begin),phrasebits,resbitsT);
for(i=0;i<possible_partitions;i++)
fprintf(stderr,"%ld(%ld):%ld ",i,resvals[i],resbits[i]);
......@@ -345,7 +344,7 @@ int inverse(vorbis_block *vb,vorbis_look_residue *vl,double **in,int ch){
partword[j]=look->decodemap[vorbis_book_decode(look->phrasebook,
&vb->opb)];
/* now we encode interleaved residual values for the partitions */
/* now we decode interleaved residual values for the partitions */
for(k=0;k<partitions_per_word;k++,l++,i+=samples_per_partition)
for(j=0;j<ch;j++){
int part=partword[j][k];
......
......@@ -12,7 +12,7 @@
********************************************************************
function: stdio-based convenience library for opening/seeking/decoding
last mod: $Id: vorbisfile.c,v 1.14 2000/01/28 09:05:18 xiphmont Exp $
last mod: $Id: vorbisfile.c,v 1.15 2000/02/23 11:22:47 xiphmont Exp $
********************************************************************/
......@@ -261,6 +261,7 @@ static void _prefetch_all_headers(OggVorbis_File *vf,vorbis_info *first_i,
int i,ret;
vf->vi=calloc(vf->links,sizeof(vorbis_info));
vf->vc=calloc(vf->links,sizeof(vorbis_info));
vf->dataoffsets=malloc(vf->links*sizeof(long));
vf->pcmlengths=malloc(vf->links*sizeof(int64_t));
vf->serialnos=malloc(vf->links*sizeof(long));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment