]> git.saurik.com Git - wxWidgets.git/blobdiff - src/unix/sound.cpp
fixed a double free bug in SetBufferIO(size_t) (coverity checker CID 62)
[wxWidgets.git] / src / unix / sound.cpp
index 3ac2ea84629a81cf530e22f8e543c92e52d7c5af..6afa44f146d97c5336f01c5b38dbc04c130659fa 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        sound.cpp
+// Name:        src/unix/sound.cpp
 // Purpose:     wxSound
 // Author:      Marcel Rasche, Vaclav Slavik
 // Modified by:
@@ -9,16 +9,9 @@
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
-#pragma implementation "sound.h"
-#pragma implementation "soundbase.h"
-#endif
-
 // for compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
-#include "wx/setup.h"
-
 #if defined(__BORLANDC__)
 #pragma hdrstop
 #endif
@@ -413,7 +406,7 @@ bool wxSoundSyncOnlyAdaptor::IsPlaying() const
 #if wxUSE_THREADS
     return m_status.m_playing;
 #else
-    return FALSE;
+    return false;
 #endif
 }
 
@@ -452,7 +445,8 @@ wxSound::~wxSound()
     Free();
 }
 
-bool wxSound::Create(const wxString& fileName, bool isResource)
+bool wxSound::Create(const wxString& fileName,
+                     bool WXUNUSED_UNLESS_DEBUG(isResource))
 {
     wxASSERT_MSG( !isResource,
              _T("Loading sound from resources is only supported on Windows") );
@@ -465,9 +459,13 @@ bool wxSound::Create(const wxString& fileName, bool isResource)
         return false;
     }
 
-    wxFileOffset len = fileWave.Length();
+    wxFileOffset lenOrig = fileWave.Length();
+    if ( lenOrig == wxInvalidOffset )
+        return false;
+
+    size_t len = wx_truncate_cast(size_t, lenOrig);
     wxUint8 *data = new wxUint8[len];
-    if (fileWave.Read(data, len) != len)
+    if ( fileWave.Read(data, len) != lenOrig )
     {
         wxLogError(_("Couldn't load sound data from '%s'."), fileName.c_str());
         return false;
@@ -620,7 +618,6 @@ typedef struct
     wxUint16      uiBitsPerSample;
 } WAVEFORMAT;
 
-#define MONO             1  // and stereo is 2 by wav format
 #define WAVE_FORMAT_PCM  1
 #define WAVE_INDEX       8
 #define FMT_INDEX       12