summaryrefslogtreecommitdiff
path: root/core
authorerik <erik>2007-02-08 01:45:16 (UTC)
committer erik <erik>2007-02-08 01:45:16 (UTC)
commit2e497f7cae45184184e2416114887095735958f5 (patch) (unidiff)
treea6b399d9bce5854dc7ad6c985b48965cf20680b0 /core
parent853b61f97e718359bef95147ab3c7beb0705acda (diff)
downloadopie-2e497f7cae45184184e2416114887095735958f5.zip
opie-2e497f7cae45184184e2416114887095735958f5.tar.gz
opie-2e497f7cae45184184e2416114887095735958f5.tar.bz2
Each file in this commit has a problem where it is possible to dereference
a pointer without that pointer being valid. This commit fixes each instance of that.
Diffstat (limited to 'core') (more/less context) (show whitespace changes)
-rw-r--r--core/multimedia/opieplayer/modplug/sndfile.cpp5
-rw-r--r--core/multimedia/opieplayer/vorbis/tremor/block.c2
-rw-r--r--core/multimedia/opieplayer/vorbis/tremor/info.c2
3 files changed, 7 insertions, 2 deletions
diff --git a/core/multimedia/opieplayer/modplug/sndfile.cpp b/core/multimedia/opieplayer/modplug/sndfile.cpp
index 1d0d610..799555c 100644
--- a/core/multimedia/opieplayer/modplug/sndfile.cpp
+++ b/core/multimedia/opieplayer/modplug/sndfile.cpp
@@ -1694,97 +1694,100 @@ void CSoundFile::FrequencyToTranspose(MODINSTRUMENT *psmp)
1694 int ftune = f2t & 0x7F; 1694 int ftune = f2t & 0x7F;
1695 if (ftune > 80) 1695 if (ftune > 80)
1696 { 1696 {
1697 transp++; 1697 transp++;
1698 ftune -= 128; 1698 ftune -= 128;
1699 } 1699 }
1700 if (transp > 127) transp = 127; 1700 if (transp > 127) transp = 127;
1701 if (transp < -127) transp = -127; 1701 if (transp < -127) transp = -127;
1702 psmp->RelativeTone = transp; 1702 psmp->RelativeTone = transp;
1703 psmp->nFineTune = ftune; 1703 psmp->nFineTune = ftune;
1704} 1704}
1705 1705
1706 1706
1707void CSoundFile::CheckCPUUsage(UINT nCPU) 1707void CSoundFile::CheckCPUUsage(UINT nCPU)
1708//--------------------------------------- 1708//---------------------------------------
1709{ 1709{
1710 if (nCPU > 100) nCPU = 100; 1710 if (nCPU > 100) nCPU = 100;
1711 gnCPUUsage = nCPU; 1711 gnCPUUsage = nCPU;
1712 if (nCPU < 90) 1712 if (nCPU < 90)
1713 { 1713 {
1714 m_dwSongFlags &= ~SONG_CPUVERYHIGH; 1714 m_dwSongFlags &= ~SONG_CPUVERYHIGH;
1715 } else 1715 } else
1716 if ((m_dwSongFlags & SONG_CPUVERYHIGH) && (nCPU >= 94)) 1716 if ((m_dwSongFlags & SONG_CPUVERYHIGH) && (nCPU >= 94))
1717 { 1717 {
1718 UINT i=MAX_CHANNELS; 1718 UINT i=MAX_CHANNELS;
1719 while (i >= 8) 1719 while (i >= 8)
1720 { 1720 {
1721 i--; 1721 i--;
1722 if (Chn[i].nLength) 1722 if (Chn[i].nLength)
1723 { 1723 {
1724 Chn[i].nLength = Chn[i].nPos = 0; 1724 Chn[i].nLength = Chn[i].nPos = 0;
1725 nCPU -= 2; 1725 nCPU -= 2;
1726 if (nCPU < 94) break; 1726 if (nCPU < 94) break;
1727 } 1727 }
1728 } 1728 }
1729 } else 1729 } else
1730 if (nCPU > 90) 1730 if (nCPU > 90)
1731 { 1731 {
1732 m_dwSongFlags |= SONG_CPUVERYHIGH; 1732 m_dwSongFlags |= SONG_CPUVERYHIGH;
1733 } 1733 }
1734} 1734}
1735 1735
1736 1736
1737BOOL CSoundFile::SetPatternName(UINT nPat, LPCSTR lpszName) 1737BOOL CSoundFile::SetPatternName(UINT nPat, LPCSTR lpszName)
1738//--------------------------------------------------------- 1738//---------------------------------------------------------
1739{ 1739{
1740 char szName[MAX_PATTERNNAME] = ""; // changed from CHAR 1740 char szName[MAX_PATTERNNAME] = ""; // changed from CHAR
1741 if (nPat >= MAX_PATTERNS) return FALSE; 1741 if (nPat >= MAX_PATTERNS) return FALSE;
1742 if (lpszName) lstrcpyn(szName, lpszName, MAX_PATTERNNAME); 1742 if (lpszName)
1743 lstrcpyn(szName, lpszName, MAX_PATTERNNAME);
1744 else
1745 return FALSE;
1743 szName[MAX_PATTERNNAME-1] = 0; 1746 szName[MAX_PATTERNNAME-1] = 0;
1744 if (!m_lpszPatternNames) m_nPatternNames = 0; 1747 if (!m_lpszPatternNames) m_nPatternNames = 0;
1745 if (nPat >= m_nPatternNames) 1748 if (nPat >= m_nPatternNames)
1746 { 1749 {
1747 if (!lpszName[0]) return TRUE; 1750 if (!lpszName[0]) return TRUE;
1748 UINT len = (nPat+1)*MAX_PATTERNNAME; 1751 UINT len = (nPat+1)*MAX_PATTERNNAME;
1749 char *p = new char[len]; // changed from CHAR 1752 char *p = new char[len]; // changed from CHAR
1750 if (!p) return FALSE; 1753 if (!p) return FALSE;
1751 memset(p, 0, len); 1754 memset(p, 0, len);
1752 if (m_lpszPatternNames) 1755 if (m_lpszPatternNames)
1753 { 1756 {
1754 memcpy(p, m_lpszPatternNames, m_nPatternNames * MAX_PATTERNNAME); 1757 memcpy(p, m_lpszPatternNames, m_nPatternNames * MAX_PATTERNNAME);
1755 delete m_lpszPatternNames; 1758 delete m_lpszPatternNames;
1756 m_lpszPatternNames = NULL; 1759 m_lpszPatternNames = NULL;
1757 } 1760 }
1758 m_lpszPatternNames = p; 1761 m_lpszPatternNames = p;
1759 m_nPatternNames = nPat + 1; 1762 m_nPatternNames = nPat + 1;
1760 } 1763 }
1761 memcpy(m_lpszPatternNames + nPat * MAX_PATTERNNAME, szName, MAX_PATTERNNAME); 1764 memcpy(m_lpszPatternNames + nPat * MAX_PATTERNNAME, szName, MAX_PATTERNNAME);
1762 return TRUE; 1765 return TRUE;
1763} 1766}
1764 1767
1765 1768
1766BOOL CSoundFile::GetPatternName(UINT nPat, LPSTR lpszName, UINT cbSize) const 1769BOOL CSoundFile::GetPatternName(UINT nPat, LPSTR lpszName, UINT cbSize) const
1767//--------------------------------------------------------------------------- 1770//---------------------------------------------------------------------------
1768{ 1771{
1769 if ((!lpszName) || (!cbSize)) return FALSE; 1772 if ((!lpszName) || (!cbSize)) return FALSE;
1770 lpszName[0] = 0; 1773 lpszName[0] = 0;
1771 if (cbSize > MAX_PATTERNNAME) cbSize = MAX_PATTERNNAME; 1774 if (cbSize > MAX_PATTERNNAME) cbSize = MAX_PATTERNNAME;
1772 if ((m_lpszPatternNames) && (nPat < m_nPatternNames)) 1775 if ((m_lpszPatternNames) && (nPat < m_nPatternNames))
1773 { 1776 {
1774 memcpy(lpszName, m_lpszPatternNames + nPat * MAX_PATTERNNAME, cbSize); 1777 memcpy(lpszName, m_lpszPatternNames + nPat * MAX_PATTERNNAME, cbSize);
1775 lpszName[cbSize-1] = 0; 1778 lpszName[cbSize-1] = 0;
1776 return TRUE; 1779 return TRUE;
1777 } 1780 }
1778 return FALSE; 1781 return FALSE;
1779} 1782}
1780 1783
1781 1784
1782#ifndef FASTSOUNDLIB 1785#ifndef FASTSOUNDLIB
1783 1786
1784UINT CSoundFile::DetectUnusedSamples(BOOL *pbIns) 1787UINT CSoundFile::DetectUnusedSamples(BOOL *pbIns)
1785//----------------------------------------------- 1788//-----------------------------------------------
1786{ 1789{
1787 UINT nExt = 0; 1790 UINT nExt = 0;
1788 1791
1789 if (!pbIns) return 0; 1792 if (!pbIns) return 0;
1790 if (m_nInstruments) 1793 if (m_nInstruments)
diff --git a/core/multimedia/opieplayer/vorbis/tremor/block.c b/core/multimedia/opieplayer/vorbis/tremor/block.c
index 8949253..7b5531b 100644
--- a/core/multimedia/opieplayer/vorbis/tremor/block.c
+++ b/core/multimedia/opieplayer/vorbis/tremor/block.c
@@ -181,98 +181,100 @@ static int _vds_init(vorbis_dsp_state *v,vorbis_info *vi){
181 v->W=0; /* current window size */ 181 v->W=0; /* current window size */
182 182
183 /* initialize all the mapping/backend lookups */ 183 /* initialize all the mapping/backend lookups */
184 b->mode=(vorbis_look_mapping **)_ogg_calloc(ci->modes,sizeof(*b->mode)); 184 b->mode=(vorbis_look_mapping **)_ogg_calloc(ci->modes,sizeof(*b->mode));
185 for(i=0;i<ci->modes;i++){ 185 for(i=0;i<ci->modes;i++){
186 int mapnum=ci->mode_param[i]->mapping; 186 int mapnum=ci->mode_param[i]->mapping;
187 int maptype=ci->map_type[mapnum]; 187 int maptype=ci->map_type[mapnum];
188 b->mode[i]=_mapping_P[maptype]->look(v,ci->mode_param[i], 188 b->mode[i]=_mapping_P[maptype]->look(v,ci->mode_param[i],
189 ci->map_param[mapnum]); 189 ci->map_param[mapnum]);
190 } 190 }
191 return(0); 191 return(0);
192} 192}
193 193
194int vorbis_synthesis_restart(vorbis_dsp_state *v){ 194int vorbis_synthesis_restart(vorbis_dsp_state *v){
195 vorbis_info *vi=v->vi; 195 vorbis_info *vi=v->vi;
196 codec_setup_info *ci; 196 codec_setup_info *ci;
197 197
198 if(!v->backend_state)return -1; 198 if(!v->backend_state)return -1;
199 if(!vi)return -1; 199 if(!vi)return -1;
200 ci=vi->codec_setup; 200 ci=vi->codec_setup;
201 if(!ci)return -1; 201 if(!ci)return -1;
202 202
203 v->centerW=ci->blocksizes[1]/2; 203 v->centerW=ci->blocksizes[1]/2;
204 v->pcm_current=v->centerW; 204 v->pcm_current=v->centerW;
205 205
206 v->pcm_returned=-1; 206 v->pcm_returned=-1;
207 v->granulepos=-1; 207 v->granulepos=-1;
208 v->sequence=-1; 208 v->sequence=-1;
209 ((private_state *)(v->backend_state))->sample_count=-1; 209 ((private_state *)(v->backend_state))->sample_count=-1;
210 210
211 return(0); 211 return(0);
212} 212}
213 213
214int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi){ 214int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi){
215 _vds_init(v,vi); 215 _vds_init(v,vi);
216 vorbis_synthesis_restart(v); 216 vorbis_synthesis_restart(v);
217 217
218 return(0); 218 return(0);
219} 219}
220 220
221void vorbis_dsp_clear(vorbis_dsp_state *v){ 221void vorbis_dsp_clear(vorbis_dsp_state *v){
222 int i; 222 int i;
223 if(v){ 223 if(v){
224 vorbis_info *vi=v->vi; 224 vorbis_info *vi=v->vi;
225 codec_setup_info *ci=(codec_setup_info *)(vi?vi->codec_setup:NULL); 225 codec_setup_info *ci=(codec_setup_info *)(vi?vi->codec_setup:NULL);
226 private_state *b=(private_state *)v->backend_state; 226 private_state *b=(private_state *)v->backend_state;
227 227
228 if(v->pcm){ 228 if(v->pcm){
229 if (vi) {
229 for(i=0;i<vi->channels;i++) 230 for(i=0;i<vi->channels;i++)
230 if(v->pcm[i])_ogg_free(v->pcm[i]); 231 if(v->pcm[i])_ogg_free(v->pcm[i]);
232 }
231 _ogg_free(v->pcm); 233 _ogg_free(v->pcm);
232 if(v->pcmret)_ogg_free(v->pcmret); 234 if(v->pcmret)_ogg_free(v->pcmret);
233 } 235 }
234 236
235 /* free mode lookups; these are actually vorbis_look_mapping structs */ 237 /* free mode lookups; these are actually vorbis_look_mapping structs */
236 if(ci){ 238 if(ci){
237 for(i=0;i<ci->modes;i++){ 239 for(i=0;i<ci->modes;i++){
238 int mapnum=ci->mode_param[i]->mapping; 240 int mapnum=ci->mode_param[i]->mapping;
239 int maptype=ci->map_type[mapnum]; 241 int maptype=ci->map_type[mapnum];
240 if(b && b->mode)_mapping_P[maptype]->free_look(b->mode[i]); 242 if(b && b->mode)_mapping_P[maptype]->free_look(b->mode[i]);
241 } 243 }
242 } 244 }
243 245
244 if(b){ 246 if(b){
245 if(b->mode)_ogg_free(b->mode); 247 if(b->mode)_ogg_free(b->mode);
246 _ogg_free(b); 248 _ogg_free(b);
247 } 249 }
248 250
249 memset(v,0,sizeof(*v)); 251 memset(v,0,sizeof(*v));
250 } 252 }
251} 253}
252 254
253/* Unlike in analysis, the window is only partially applied for each 255/* Unlike in analysis, the window is only partially applied for each
254 block. The time domain envelope is not yet handled at the point of 256 block. The time domain envelope is not yet handled at the point of
255 calling (as it relies on the previous block). */ 257 calling (as it relies on the previous block). */
256 258
257int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){ 259int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){
258 vorbis_info *vi=v->vi; 260 vorbis_info *vi=v->vi;
259 codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; 261 codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
260 private_state *b=v->backend_state; 262 private_state *b=v->backend_state;
261 int i,j; 263 int i,j;
262 264
263 if(v->pcm_current>v->pcm_returned && v->pcm_returned!=-1)return(OV_EINVAL); 265 if(v->pcm_current>v->pcm_returned && v->pcm_returned!=-1)return(OV_EINVAL);
264 266
265 v->lW=v->W; 267 v->lW=v->W;
266 v->W=vb->W; 268 v->W=vb->W;
267 v->nW=-1; 269 v->nW=-1;
268 270
269 if((v->sequence==-1)|| 271 if((v->sequence==-1)||
270 (v->sequence+1 != vb->sequence)){ 272 (v->sequence+1 != vb->sequence)){
271 v->granulepos=-1; /* out of sequence; lose count */ 273 v->granulepos=-1; /* out of sequence; lose count */
272 b->sample_count=-1; 274 b->sample_count=-1;
273 } 275 }
274 276
275 v->sequence=vb->sequence; 277 v->sequence=vb->sequence;
276 278
277 if(vb->pcm){ /* no pcm to process if vorbis_synthesis_trackonly 279 if(vb->pcm){ /* no pcm to process if vorbis_synthesis_trackonly
278 was called on block */ 280 was called on block */
diff --git a/core/multimedia/opieplayer/vorbis/tremor/info.c b/core/multimedia/opieplayer/vorbis/tremor/info.c
index 941695e..3499ae4 100644
--- a/core/multimedia/opieplayer/vorbis/tremor/info.c
+++ b/core/multimedia/opieplayer/vorbis/tremor/info.c
@@ -52,99 +52,99 @@ static int tagcompare(const char *s1, const char *s2, int n){
52 } 52 }
53 return 0; 53 return 0;
54} 54}
55 55
56char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count){ 56char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count){
57 long i; 57 long i;
58 int found = 0; 58 int found = 0;
59 int taglen = strlen(tag)+1; /* +1 for the = we append */ 59 int taglen = strlen(tag)+1; /* +1 for the = we append */
60 char *fulltag = (char *)alloca(taglen+ 1); 60 char *fulltag = (char *)alloca(taglen+ 1);
61 61
62 strcpy(fulltag, tag); 62 strcpy(fulltag, tag);
63 strcat(fulltag, "="); 63 strcat(fulltag, "=");
64 64
65 for(i=0;i<vc->comments;i++){ 65 for(i=0;i<vc->comments;i++){
66 if(!tagcompare(vc->user_comments[i], fulltag, taglen)){ 66 if(!tagcompare(vc->user_comments[i], fulltag, taglen)){
67 if(count == found) 67 if(count == found)
68 /* We return a pointer to the data, not a copy */ 68 /* We return a pointer to the data, not a copy */
69 return vc->user_comments[i] + taglen; 69 return vc->user_comments[i] + taglen;
70 else 70 else
71 found++; 71 found++;
72 } 72 }
73 } 73 }
74 return NULL; /* didn't find anything */ 74 return NULL; /* didn't find anything */
75} 75}
76 76
77int vorbis_comment_query_count(vorbis_comment *vc, char *tag){ 77int vorbis_comment_query_count(vorbis_comment *vc, char *tag){
78 int i,count=0; 78 int i,count=0;
79 int taglen = strlen(tag)+1; /* +1 for the = we append */ 79 int taglen = strlen(tag)+1; /* +1 for the = we append */
80 char *fulltag = (char *)alloca(taglen+1); 80 char *fulltag = (char *)alloca(taglen+1);
81 strcpy(fulltag,tag); 81 strcpy(fulltag,tag);
82 strcat(fulltag, "="); 82 strcat(fulltag, "=");
83 83
84 for(i=0;i<vc->comments;i++){ 84 for(i=0;i<vc->comments;i++){
85 if(!tagcompare(vc->user_comments[i], fulltag, taglen)) 85 if(!tagcompare(vc->user_comments[i], fulltag, taglen))
86 count++; 86 count++;
87 } 87 }
88 88
89 return count; 89 return count;
90} 90}
91 91
92void vorbis_comment_clear(vorbis_comment *vc){ 92void vorbis_comment_clear(vorbis_comment *vc){
93 if(vc){ 93 if(vc){
94 long i; 94 long i;
95 for(i=0;i<vc->comments;i++) 95 for(i=0;i<vc->comments;i++)
96 if(vc->user_comments[i])_ogg_free(vc->user_comments[i]); 96 if(vc->user_comments[i])_ogg_free(vc->user_comments[i]);
97 if(vc->user_comments)_ogg_free(vc->user_comments); 97 if(vc->user_comments)_ogg_free(vc->user_comments);
98 if(vc->comment_lengths)_ogg_free(vc->comment_lengths); 98 if(vc->comment_lengths)_ogg_free(vc->comment_lengths);
99 if(vc->vendor)_ogg_free(vc->vendor); 99 if(vc->vendor)_ogg_free(vc->vendor);
100 }
101 memset(vc,0,sizeof(*vc)); 100 memset(vc,0,sizeof(*vc));
102} 101}
102}
103 103
104/* blocksize 0 is guaranteed to be short, 1 is guarantted to be long. 104/* blocksize 0 is guaranteed to be short, 1 is guarantted to be long.
105 They may be equal, but short will never ge greater than long */ 105 They may be equal, but short will never ge greater than long */
106int vorbis_info_blocksize(vorbis_info *vi,int zo){ 106int vorbis_info_blocksize(vorbis_info *vi,int zo){
107 codec_setup_info *ci = (codec_setup_info *)vi->codec_setup; 107 codec_setup_info *ci = (codec_setup_info *)vi->codec_setup;
108 return ci ? ci->blocksizes[zo] : -1; 108 return ci ? ci->blocksizes[zo] : -1;
109} 109}
110 110
111/* used by synthesis, which has a full, alloced vi */ 111/* used by synthesis, which has a full, alloced vi */
112void vorbis_info_init(vorbis_info *vi){ 112void vorbis_info_init(vorbis_info *vi){
113 memset(vi,0,sizeof(*vi)); 113 memset(vi,0,sizeof(*vi));
114 vi->codec_setup=(codec_setup_info *)_ogg_calloc(1,sizeof(codec_setup_info)); 114 vi->codec_setup=(codec_setup_info *)_ogg_calloc(1,sizeof(codec_setup_info));
115} 115}
116 116
117void vorbis_info_clear(vorbis_info *vi){ 117void vorbis_info_clear(vorbis_info *vi){
118 codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; 118 codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
119 int i; 119 int i;
120 120
121 if(ci){ 121 if(ci){
122 122
123 for(i=0;i<ci->modes;i++) 123 for(i=0;i<ci->modes;i++)
124 if(ci->mode_param[i])_ogg_free(ci->mode_param[i]); 124 if(ci->mode_param[i])_ogg_free(ci->mode_param[i]);
125 125
126 for(i=0;i<ci->maps;i++) /* unpack does the range checking */ 126 for(i=0;i<ci->maps;i++) /* unpack does the range checking */
127 _mapping_P[ci->map_type[i]]->free_info(ci->map_param[i]); 127 _mapping_P[ci->map_type[i]]->free_info(ci->map_param[i]);
128 128
129 for(i=0;i<ci->floors;i++) /* unpack does the range checking */ 129 for(i=0;i<ci->floors;i++) /* unpack does the range checking */
130 _floor_P[ci->floor_type[i]]->free_info(ci->floor_param[i]); 130 _floor_P[ci->floor_type[i]]->free_info(ci->floor_param[i]);
131 131
132 for(i=0;i<ci->residues;i++) /* unpack does the range checking */ 132 for(i=0;i<ci->residues;i++) /* unpack does the range checking */
133 _residue_P[ci->residue_type[i]]->free_info(ci->residue_param[i]); 133 _residue_P[ci->residue_type[i]]->free_info(ci->residue_param[i]);
134 134
135 for(i=0;i<ci->books;i++){ 135 for(i=0;i<ci->books;i++){
136 if(ci->book_param[i]){ 136 if(ci->book_param[i]){
137 /* knows if the book was not alloced */ 137 /* knows if the book was not alloced */
138 vorbis_staticbook_destroy(ci->book_param[i]); 138 vorbis_staticbook_destroy(ci->book_param[i]);
139 } 139 }
140 if(ci->fullbooks) 140 if(ci->fullbooks)
141 vorbis_book_clear(ci->fullbooks+i); 141 vorbis_book_clear(ci->fullbooks+i);
142 } 142 }
143 if(ci->fullbooks) 143 if(ci->fullbooks)
144 _ogg_free(ci->fullbooks); 144 _ogg_free(ci->fullbooks);
145 145
146 _ogg_free(ci); 146 _ogg_free(ci);
147 } 147 }
148 148
149 memset(vi,0,sizeof(*vi)); 149 memset(vi,0,sizeof(*vi));
150} 150}