author | erik <erik> | 2007-02-08 01:45:16 (UTC) |
---|---|---|
committer | erik <erik> | 2007-02-08 01:45:16 (UTC) |
commit | 2e497f7cae45184184e2416114887095735958f5 (patch) (unidiff) | |
tree | a6b399d9bce5854dc7ad6c985b48965cf20680b0 /core/multimedia/opieplayer/modplug | |
parent | 853b61f97e718359bef95147ab3c7beb0705acda (diff) | |
download | opie-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/multimedia/opieplayer/modplug') (more/less context) (show whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/modplug/sndfile.cpp | 5 |
1 files changed, 4 insertions, 1 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 | |||
@@ -1646,193 +1646,196 @@ DWORD CSoundFile::TransposeToFrequency(int transp, int ftune) | |||
1646 | fscale | 1646 | fscale |
1647 | fstp st(1) | 1647 | fstp st(1) |
1648 | fmul st(1), st(0) | 1648 | fmul st(1), st(0) |
1649 | faddp st(1), st(0) | 1649 | faddp st(1), st(0) |
1650 | fistp freq | 1650 | fistp freq |
1651 | } | 1651 | } |
1652 | UINT derr = freq % 11025; | 1652 | UINT derr = freq % 11025; |
1653 | if (derr <= 8) freq -= derr; | 1653 | if (derr <= 8) freq -= derr; |
1654 | if (derr >= 11015) freq += 11025-derr; | 1654 | if (derr >= 11015) freq += 11025-derr; |
1655 | derr = freq % 1000; | 1655 | derr = freq % 1000; |
1656 | if (derr <= 5) freq -= derr; | 1656 | if (derr <= 5) freq -= derr; |
1657 | if (derr >= 995) freq += 1000-derr; | 1657 | if (derr >= 995) freq += 1000-derr; |
1658 | return freq; | 1658 | return freq; |
1659 | #endif | 1659 | #endif |
1660 | } | 1660 | } |
1661 | 1661 | ||
1662 | 1662 | ||
1663 | // returns 12*128*log2(freq/8363) | 1663 | // returns 12*128*log2(freq/8363) |
1664 | int CSoundFile::FrequencyToTranspose(DWORD freq) | 1664 | int CSoundFile::FrequencyToTranspose(DWORD freq) |
1665 | //---------------------------------------------- | 1665 | //---------------------------------------------- |
1666 | { | 1666 | { |
1667 | //---GCCFIX: Removed assembly. | 1667 | //---GCCFIX: Removed assembly. |
1668 | return int(1536*(log(freq/8363)/log(2))); | 1668 | return int(1536*(log(freq/8363)/log(2))); |
1669 | 1669 | ||
1670 | #ifdef WIN32 | 1670 | #ifdef WIN32 |
1671 | const float _f1_8363 = 1.0f / 8363.0f; | 1671 | const float _f1_8363 = 1.0f / 8363.0f; |
1672 | const float _factor = 128 * 12; | 1672 | const float _factor = 128 * 12; |
1673 | LONG result; | 1673 | LONG result; |
1674 | 1674 | ||
1675 | if (!freq) return 0; | 1675 | if (!freq) return 0; |
1676 | _asm { | 1676 | _asm { |
1677 | fld _factor | 1677 | fld _factor |
1678 | fild freq | 1678 | fild freq |
1679 | fld _f1_8363 | 1679 | fld _f1_8363 |
1680 | fmulp st(1), st(0) | 1680 | fmulp st(1), st(0) |
1681 | fyl2x | 1681 | fyl2x |
1682 | fistp result | 1682 | fistp result |
1683 | } | 1683 | } |
1684 | return result; | 1684 | return result; |
1685 | #endif | 1685 | #endif |
1686 | } | 1686 | } |
1687 | 1687 | ||
1688 | 1688 | ||
1689 | void CSoundFile::FrequencyToTranspose(MODINSTRUMENT *psmp) | 1689 | void CSoundFile::FrequencyToTranspose(MODINSTRUMENT *psmp) |
1690 | //-------------------------------------------------------- | 1690 | //-------------------------------------------------------- |
1691 | { | 1691 | { |
1692 | int f2t = FrequencyToTranspose(psmp->nC4Speed); | 1692 | int f2t = FrequencyToTranspose(psmp->nC4Speed); |
1693 | int transp = f2t >> 7; | 1693 | int transp = f2t >> 7; |
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 | ||
1707 | void CSoundFile::CheckCPUUsage(UINT nCPU) | 1707 | void 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 | ||
1737 | BOOL CSoundFile::SetPatternName(UINT nPat, LPCSTR lpszName) | 1737 | BOOL 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 | ||
1766 | BOOL CSoundFile::GetPatternName(UINT nPat, LPSTR lpszName, UINT cbSize) const | 1769 | BOOL 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 | ||
1784 | UINT CSoundFile::DetectUnusedSamples(BOOL *pbIns) | 1787 | UINT 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) |
1791 | { | 1794 | { |
1792 | memset(pbIns, 0, MAX_SAMPLES * sizeof(BOOL)); | 1795 | memset(pbIns, 0, MAX_SAMPLES * sizeof(BOOL)); |
1793 | for (UINT ipat=0; ipat<MAX_PATTERNS; ipat++) | 1796 | for (UINT ipat=0; ipat<MAX_PATTERNS; ipat++) |
1794 | { | 1797 | { |
1795 | MODCOMMAND *p = Patterns[ipat]; | 1798 | MODCOMMAND *p = Patterns[ipat]; |
1796 | if (p) | 1799 | if (p) |
1797 | { | 1800 | { |
1798 | UINT jmax = PatternSize[ipat] * m_nChannels; | 1801 | UINT jmax = PatternSize[ipat] * m_nChannels; |
1799 | for (UINT j=0; j<jmax; j++, p++) | 1802 | for (UINT j=0; j<jmax; j++, p++) |
1800 | { | 1803 | { |
1801 | if ((p->note) && (p->note <= 120)) | 1804 | if ((p->note) && (p->note <= 120)) |
1802 | { | 1805 | { |
1803 | if ((p->instr) && (p->instr < MAX_INSTRUMENTS)) | 1806 | if ((p->instr) && (p->instr < MAX_INSTRUMENTS)) |
1804 | { | 1807 | { |
1805 | INSTRUMENTHEADER *penv = Headers[p->instr]; | 1808 | INSTRUMENTHEADER *penv = Headers[p->instr]; |
1806 | if (penv) | 1809 | if (penv) |
1807 | { | 1810 | { |
1808 | UINT n = penv->Keyboard[p->note-1]; | 1811 | UINT n = penv->Keyboard[p->note-1]; |
1809 | if (n < MAX_SAMPLES) pbIns[n] = TRUE; | 1812 | if (n < MAX_SAMPLES) pbIns[n] = TRUE; |
1810 | } | 1813 | } |
1811 | } else | 1814 | } else |
1812 | { | 1815 | { |
1813 | for (UINT k=1; k<=m_nInstruments; k++) | 1816 | for (UINT k=1; k<=m_nInstruments; k++) |
1814 | { | 1817 | { |
1815 | INSTRUMENTHEADER *penv = Headers[k]; | 1818 | INSTRUMENTHEADER *penv = Headers[k]; |
1816 | if (penv) | 1819 | if (penv) |
1817 | { | 1820 | { |
1818 | UINT n = penv->Keyboard[p->note-1]; | 1821 | UINT n = penv->Keyboard[p->note-1]; |
1819 | if (n < MAX_SAMPLES) pbIns[n] = TRUE; | 1822 | if (n < MAX_SAMPLES) pbIns[n] = TRUE; |
1820 | } | 1823 | } |
1821 | } | 1824 | } |
1822 | } | 1825 | } |
1823 | } | 1826 | } |
1824 | } | 1827 | } |
1825 | } | 1828 | } |
1826 | } | 1829 | } |
1827 | for (UINT ichk=1; ichk<=m_nSamples; ichk++) | 1830 | for (UINT ichk=1; ichk<=m_nSamples; ichk++) |
1828 | { | 1831 | { |
1829 | if ((!pbIns[ichk]) && (Ins[ichk].pSample)) nExt++; | 1832 | if ((!pbIns[ichk]) && (Ins[ichk].pSample)) nExt++; |
1830 | } | 1833 | } |
1831 | } | 1834 | } |
1832 | return nExt; | 1835 | return nExt; |
1833 | } | 1836 | } |
1834 | 1837 | ||
1835 | 1838 | ||
1836 | BOOL CSoundFile::RemoveSelectedSamples(BOOL *pbIns) | 1839 | BOOL CSoundFile::RemoveSelectedSamples(BOOL *pbIns) |
1837 | //------------------------------------------------- | 1840 | //------------------------------------------------- |
1838 | { | 1841 | { |