Skip to content

Commit

Permalink
Merge pull request #10063 from neo1973/fixes
Browse files Browse the repository at this point in the history
Random fixes found with clang/gcc sanitizers
  • Loading branch information
MartijnKaijser committed Jul 17, 2016
2 parents 3736e89 + 85f239b commit 0dd39fc
Show file tree
Hide file tree
Showing 34 changed files with 54 additions and 42 deletions.
2 changes: 1 addition & 1 deletion xbmc/AutoSwitch.cpp
Expand Up @@ -238,5 +238,5 @@ float CAutoSwitch::MetadataPercentage(const CFileItemList &vecItems)
if(item->IsParentFolder())
total--;
}
return (float)count / total;
return (total != 0) ? ((float)count / total) : 0.0f;
}
8 changes: 2 additions & 6 deletions xbmc/cores/VideoPlayer/DVDMessage.cpp
Expand Up @@ -88,13 +88,9 @@ bool CDVDMsgGeneralSynchronize::Wait(unsigned int milliseconds, unsigned int sou
return true;
}

void CDVDMsgGeneralSynchronize::Wait(volatile bool *abort, unsigned int source)
void CDVDMsgGeneralSynchronize::Wait(std::atomic<bool>& abort, unsigned int source)
{
while(!Wait(100, source))
{
if(abort && *abort)
return;
}
while(!Wait(100, source) && !abort);
}

long CDVDMsgGeneralSynchronize::Release()
Expand Down
5 changes: 3 additions & 2 deletions xbmc/cores/VideoPlayer/DVDMessage.h
Expand Up @@ -30,6 +30,7 @@

// include as less is possible to prevent dependencies
#include "DVDResource.h"
#include <atomic>
#include <string>
#include <string.h>

Expand Down Expand Up @@ -148,8 +149,8 @@ class CDVDMsgGeneralSynchronize : public CDVDMsg

// waits until all threads waiting, released the object
// if abort is set somehow
bool Wait(unsigned int ms , unsigned int source);
void Wait(volatile bool *abort, unsigned int source);
bool Wait(unsigned int ms , unsigned int source);
void Wait(std::atomic<bool>& abort, unsigned int source);
private:
class CDVDMsgGeneralSynchronizePriv* m_p;
};
Expand Down
2 changes: 1 addition & 1 deletion xbmc/cores/VideoPlayer/DVDMessageQueue.cpp
Expand Up @@ -246,7 +246,7 @@ void CDVDMessageQueue::WaitUntilEmpty()
CLog::Log(LOGNOTICE, "CDVDMessageQueue(%s)::WaitUntilEmpty", m_owner.c_str());
CDVDMsgGeneralSynchronize* msg = new CDVDMsgGeneralSynchronize(40000, 0);
Put(msg->Acquire());
msg->Wait(&m_bAbortRequest, 0);
msg->Wait(m_bAbortRequest, 0);
msg->Release();
}

Expand Down
3 changes: 2 additions & 1 deletion xbmc/cores/VideoPlayer/DVDMessageQueue.h
Expand Up @@ -21,6 +21,7 @@
*/

#include "DVDMessage.h"
#include <atomic>
#include <string>
#include <list>
#include <algorithm>
Expand Down Expand Up @@ -111,7 +112,7 @@ class CDVDMessageQueue
CEvent m_hEvent;
mutable CCriticalSection m_section;

bool m_bAbortRequest;
std::atomic<bool> m_bAbortRequest;
bool m_bInitialized;

int m_iDataSize;
Expand Down
4 changes: 2 additions & 2 deletions xbmc/cores/VideoPlayer/VideoPlayer.cpp
Expand Up @@ -2368,7 +2368,7 @@ void CVideoPlayer::SynchronizeDemuxer(unsigned int timeout)

CDVDMsgGeneralSynchronize* message = new CDVDMsgGeneralSynchronize(timeout, 0);
m_messenger.Put(message->Acquire());
message->Wait(&m_bStop, 0);
message->Wait(m_bStop, 0);
message->Release();
}

Expand Down Expand Up @@ -3922,7 +3922,7 @@ void CVideoPlayer::FlushBuffers(bool queued, double pts, bool accurate, bool syn
CDVDMsgGeneralSynchronize* msg = new CDVDMsgGeneralSynchronize(1000, 0);
m_VideoPlayerAudio->SendMessage(msg->Acquire(), 1);
m_VideoPlayerVideo->SendMessage(msg->Acquire(), 1);
msg->Wait(&m_bStop, 0);
msg->Wait(m_bStop, 0);
msg->Release();

// purge any pending PLAYER_STARTED messages
Expand Down
2 changes: 1 addition & 1 deletion xbmc/dialogs/GUIDialogKeyboardGeneric.h
Expand Up @@ -87,7 +87,7 @@ class CGUIDialogKeyboardGeneric : public CGUIDialog, public CGUIKeyboard
std::string m_strHeading;
std::string m_text; ///< current text

IInputCodingTable *m_codingtable;
IInputCodingTablePtr m_codingtable;
std::vector<std::wstring> m_words;
std::string m_hzcode;
int m_pos;
Expand Down
4 changes: 4 additions & 0 deletions xbmc/guilib/GUIFontCache.cpp
Expand Up @@ -32,6 +32,10 @@ class CGUIFontCacheImpl
using HashIter = typename HashMap::iterator;
using AgeMap = std::multimap<size_t, HashIter>;

~EntryList()
{
Flush();
}
HashIter Insert(size_t hash, CGUIFontCacheEntry<Position, Value> *v)
{
auto r (hashMap.insert(typename HashMap::value_type(hash, v)));
Expand Down
3 changes: 3 additions & 0 deletions xbmc/input/InputCodingTable.h
Expand Up @@ -21,6 +21,7 @@
*/

#include <string>
#include <memory>
#include <vector>

class IInputCodingTable
Expand Down Expand Up @@ -58,3 +59,5 @@ class IInputCodingTable
protected:
std::string m_codechars;
};

typedef std::shared_ptr<IInputCodingTable> IInputCodingTablePtr;
2 changes: 1 addition & 1 deletion xbmc/input/KeyboardLayout.cpp
Expand Up @@ -69,7 +69,7 @@ bool CKeyboardLayout::Load(const TiXmlElement* element)

const TiXmlElement *keyboard = element->FirstChildElement("keyboard");
if (element->Attribute("codingtable"))
m_codingtable = CInputCodingTableFactory::CreateCodingTable(element->Attribute("codingtable"), element);
m_codingtable = IInputCodingTablePtr(CInputCodingTableFactory::CreateCodingTable(element->Attribute("codingtable"), element));
else
m_codingtable = NULL;
while (keyboard != NULL)
Expand Down
7 changes: 4 additions & 3 deletions xbmc/input/KeyboardLayout.h
Expand Up @@ -23,15 +23,16 @@
#include <string>
#include <vector>

#include "InputCodingTable.h"

class TiXmlElement;
class IInputCodingTable;

class CKeyboardLayout
{
public:
CKeyboardLayout();
virtual ~CKeyboardLayout();
IInputCodingTable* GetCodingTable() { return m_codingtable; }
IInputCodingTablePtr GetCodingTable() { return m_codingtable; }

bool Load(const TiXmlElement* element);

Expand All @@ -58,5 +59,5 @@ class CKeyboardLayout
std::string m_language;
std::string m_layout;
Keyboards m_keyboards;
IInputCodingTable* m_codingtable;
IInputCodingTablePtr m_codingtable;
};
3 changes: 2 additions & 1 deletion xbmc/network/EventServer.h
Expand Up @@ -26,6 +26,7 @@
#include "threads/CriticalSection.h"
#include "threads/SingleLock.h"

#include <atomic>
#include <map>
#include <queue>
#include <vector>
Expand Down Expand Up @@ -82,7 +83,7 @@ namespace EVENTSERVER
int m_iListenTimeout;
int m_iMaxClients;
unsigned char* m_pPacketBuffer;
bool m_bRunning;
std::atomic<bool> m_bRunning;
CCriticalSection m_critSection;
bool m_bRefreshSettings;
};
Expand Down
2 changes: 1 addition & 1 deletion xbmc/network/upnp/UPnP.cpp
Expand Up @@ -421,7 +421,7 @@ CUPnP::CUPnP() :
m_CtrlPointHolder(new CCtrlPointReferenceHolder())
{
NPT_LogManager::GetDefault().Configure("plist:.level=FINE;.handlers=CustomHandler;");
NPT_LogHandler::Create("CustomHandler", "xbmc", m_LogHandler);
NPT_LogHandler::Create("xbmc", "CustomHandler", m_LogHandler);
m_LogHandler->SetCustomHandlerFunction(&UPnPLogger);

// initialize upnp context
Expand Down
1 change: 1 addition & 0 deletions xbmc/threads/Event.cpp
Expand Up @@ -120,6 +120,7 @@ namespace XbmcThreads
signaled == NULL && iter != events.end(); ++iter)
{
CEvent* cur = *iter;
CSingleLock lock2(cur->mutex);
if (cur->signaled)
signaled = cur;
}
Expand Down
3 changes: 2 additions & 1 deletion xbmc/threads/Thread.h
Expand Up @@ -24,6 +24,7 @@

#pragma once

#include <atomic>
#include <string>
#include <stdint.h>
#include "Event.h"
Expand Down Expand Up @@ -91,7 +92,7 @@ class CThread
virtual void OnExit(){};
virtual void Process();

volatile bool m_bStop;
std::atomic<bool> m_bStop;

enum WaitResponse { WAIT_INTERRUPTED = -1, WAIT_SIGNALED = 0, WAIT_TIMEDOUT = 1 };

Expand Down
3 changes: 2 additions & 1 deletion xbmc/video/videosync/VideoSync.h
Expand Up @@ -18,6 +18,7 @@
* <http://www.gnu.org/licenses/>.
*
*/
#include <atomic>

class CVideoReferenceClock;
typedef void (*PUPDATECLOCK)(int NrVBlanks, uint64_t time, CVideoReferenceClock *clock);
Expand All @@ -28,7 +29,7 @@ class CVideoSync
CVideoSync(CVideoReferenceClock *clock) { m_refClock = clock; };
virtual ~CVideoSync() {};
virtual bool Setup(PUPDATECLOCK func) = 0;
virtual void Run(volatile bool& stop) = 0;
virtual void Run(std::atomic<bool>& stop) = 0;
virtual void Cleanup() = 0;
virtual float GetFps() = 0;
virtual void RefreshChanged() {};
Expand Down
2 changes: 1 addition & 1 deletion xbmc/video/videosync/VideoSyncAndroid.cpp
Expand Up @@ -47,7 +47,7 @@ bool CVideoSyncAndroid::Setup(PUPDATECLOCK func)
return true;
}

void CVideoSyncAndroid::Run(volatile bool& stop)
void CVideoSyncAndroid::Run(std::atomic<bool>& stop)
{
while(!stop && !m_abort)
{
Expand Down
2 changes: 1 addition & 1 deletion xbmc/video/videosync/VideoSyncAndroid.h
Expand Up @@ -30,7 +30,7 @@ class CVideoSyncAndroid : public CVideoSync, IDispResource

// CVideoSync interface
virtual bool Setup(PUPDATECLOCK func);
virtual void Run(volatile bool& stop);
virtual void Run(std::atomic<bool>& stop);
virtual void Cleanup();
virtual float GetFps();

Expand Down
2 changes: 1 addition & 1 deletion xbmc/video/videosync/VideoSyncD3D.cpp
Expand Up @@ -67,7 +67,7 @@ bool CVideoSyncD3D::Setup(PUPDATECLOCK func)
return true;
}

void CVideoSyncD3D::Run(volatile bool& stop)
void CVideoSyncD3D::Run(std::atomic<bool>& stop)
{
int64_t Now;
int64_t LastVBlankTime;
Expand Down
2 changes: 1 addition & 1 deletion xbmc/video/videosync/VideoSyncD3D.h
Expand Up @@ -30,7 +30,7 @@ class CVideoSyncD3D : public CVideoSync, IDispResource
public:
CVideoSyncD3D(CVideoReferenceClock *clock) : CVideoSync(clock) {};
bool Setup(PUPDATECLOCK func) override;
void Run(volatile bool& stop) override;
void Run(std::atomic<bool>& stop) override;
void Cleanup() override;
float GetFps() override;
void RefreshChanged() override;
Expand Down
2 changes: 1 addition & 1 deletion xbmc/video/videosync/VideoSyncDRM.cpp
Expand Up @@ -78,7 +78,7 @@ bool CVideoSyncDRM::Setup(PUPDATECLOCK func)
return true;
}

void CVideoSyncDRM::Run(volatile bool& stop)
void CVideoSyncDRM::Run(std::atomic<bool>& stop)
{
drmVBlank vbl;
VblInfo info;
Expand Down
2 changes: 1 addition & 1 deletion xbmc/video/videosync/VideoSyncDRM.h
Expand Up @@ -29,7 +29,7 @@ class CVideoSyncDRM : public CVideoSync, IDispResource
public:
CVideoSyncDRM(CVideoReferenceClock *clock) : CVideoSync(clock) {};
virtual bool Setup(PUPDATECLOCK func);
virtual void Run(volatile bool& stop);
virtual void Run(std::atomic<bool>& stop);
virtual void Cleanup();
virtual float GetFps();
virtual void OnResetDisplay();
Expand Down
2 changes: 1 addition & 1 deletion xbmc/video/videosync/VideoSyncGLX.cpp
Expand Up @@ -183,7 +183,7 @@ bool CVideoSyncGLX::Setup(PUPDATECLOCK func)
return true;
}

void CVideoSyncGLX::Run(volatile bool& stop)
void CVideoSyncGLX::Run(std::atomic<bool>& stop)
{
unsigned int PrevVblankCount;
unsigned int VblankCount;
Expand Down
2 changes: 1 addition & 1 deletion xbmc/video/videosync/VideoSyncGLX.h
Expand Up @@ -34,7 +34,7 @@ class CVideoSyncGLX : public CVideoSync, IDispResource
public:
CVideoSyncGLX(CVideoReferenceClock *clock) : CVideoSync(clock) {};
virtual bool Setup(PUPDATECLOCK func);
virtual void Run(volatile bool& stop);
virtual void Run(std::atomic<bool>& stop);
virtual void Cleanup();
virtual float GetFps();
virtual void OnLostDisplay();
Expand Down
2 changes: 1 addition & 1 deletion xbmc/video/videosync/VideoSyncIMX.cpp
Expand Up @@ -50,7 +50,7 @@ bool CVideoSyncIMX::Setup(PUPDATECLOCK func)
return true;
}

void CVideoSyncIMX::Run(volatile bool& stop)
void CVideoSyncIMX::Run(std::atomic<bool>& stop)
{
int counter;

Expand Down
2 changes: 1 addition & 1 deletion xbmc/video/videosync/VideoSyncIMX.h
Expand Up @@ -30,7 +30,7 @@ class CVideoSyncIMX : public CVideoSync, IDispResource
CVideoSyncIMX(CVideoReferenceClock *clock);
virtual ~CVideoSyncIMX();
virtual bool Setup(PUPDATECLOCK func);
virtual void Run(volatile bool& stop);
virtual void Run(std::atomic<bool>& stop);
virtual void Cleanup();
virtual float GetFps();
virtual void OnResetDisplay();
Expand Down
2 changes: 1 addition & 1 deletion xbmc/video/videosync/VideoSyncIos.cpp
Expand Up @@ -47,7 +47,7 @@ bool CVideoSyncIos::Setup(PUPDATECLOCK func)
return setupOk;
}

void CVideoSyncIos::Run(volatile bool& stop)
void CVideoSyncIos::Run(std::atomic<bool>& stop)
{
//because cocoa has a vblank callback, we just keep sleeping until we're asked to stop the thread
while(!stop && !m_abort)
Expand Down
2 changes: 1 addition & 1 deletion xbmc/video/videosync/VideoSyncIos.h
Expand Up @@ -30,7 +30,7 @@ class CVideoSyncIos : public CVideoSync, IDispResource

// CVideoSync interface
virtual bool Setup(PUPDATECLOCK func);
virtual void Run(volatile bool& stop);
virtual void Run(std::atomic<bool>& stop);
virtual void Cleanup();
virtual float GetFps();

Expand Down
2 changes: 1 addition & 1 deletion xbmc/video/videosync/VideoSyncOsx.cpp
Expand Up @@ -49,7 +49,7 @@ bool CVideoSyncOsx::Setup(PUPDATECLOCK func)
return true;
}

void CVideoSyncOsx::Run(volatile bool& stop)
void CVideoSyncOsx::Run(std::atomic<bool>& stop)
{
InitDisplayLink();

Expand Down
2 changes: 1 addition & 1 deletion xbmc/video/videosync/VideoSyncOsx.h
Expand Up @@ -36,7 +36,7 @@ class CVideoSyncOsx : public CVideoSync, IDispResource

// CVideoSync interface
virtual bool Setup(PUPDATECLOCK func);
virtual void Run(volatile bool& stop);
virtual void Run(std::atomic<bool>& stop);
virtual void Cleanup();
virtual float GetFps();
virtual void RefreshChanged();
Expand Down
2 changes: 1 addition & 1 deletion xbmc/video/videosync/VideoSyncPi.cpp
Expand Up @@ -39,7 +39,7 @@ bool CVideoSyncPi::Setup(PUPDATECLOCK func)
return true;
}

void CVideoSyncPi::Run(volatile bool& stop)
void CVideoSyncPi::Run(std::atomic<bool>& stop)
{
/* This shouldn't be very busy and timing is important so increase priority */
CThread::GetCurrentThread()->SetPriority(CThread::GetCurrentThread()->GetPriority()+1);
Expand Down
2 changes: 1 addition & 1 deletion xbmc/video/videosync/VideoSyncPi.h
Expand Up @@ -29,7 +29,7 @@ class CVideoSyncPi : public CVideoSync, IDispResource
public:
CVideoSyncPi(CVideoReferenceClock *clock) : CVideoSync(clock) {};
virtual bool Setup(PUPDATECLOCK func);
virtual void Run(volatile bool& stop);
virtual void Run(std::atomic<bool>& stop);
virtual void Cleanup();
virtual float GetFps();
virtual void OnResetDisplay();
Expand Down
6 changes: 3 additions & 3 deletions xbmc/windows/GUIWindowSplash.cpp
Expand Up @@ -33,7 +33,7 @@ CGUIWindowSplash::CGUIWindowSplash(void) : CGUIWindow(WINDOW_SPLASH, "")

CGUIWindowSplash::~CGUIWindowSplash(void)
{
delete m_image;

}

void CGUIWindowSplash::OnInitWindow()
Expand All @@ -44,7 +44,7 @@ void CGUIWindowSplash::OnInitWindow()

CLog::Log(LOGINFO, "load splash image: %s", CSpecialProtocol::TranslatePath(splashImage).c_str());

m_image = new CGUIImage(0, 0, 0, 0, g_graphicsContext.GetWidth(), g_graphicsContext.GetHeight(), CTextureInfo(splashImage));
m_image = std::unique_ptr<CGUIImage>(new CGUIImage(0, 0, 0, 0, g_graphicsContext.GetWidth(), g_graphicsContext.GetHeight(), CTextureInfo(splashImage)));
m_image->SetAspectRatio(CAspectRatio::AR_SCALE);
}

Expand All @@ -56,4 +56,4 @@ void CGUIWindowSplash::Render()
m_image->AllocResources();
m_image->Render();
m_image->FreeResources();
}
}

0 comments on commit 0dd39fc

Please sign in to comment.