aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar ctrlaltca2024-02-08 08:58:10 +0100
committerGravatar GitHub2024-02-08 08:58:10 +0100
commit5cbbeabcfd2321e42767063d617b71ae14b3b8c7 (patch)
tree02622afce182d44bc2463f3adb2e19609a7aa225 /src
parentFix #2597: moc may require the full KviMaskEntry declaration in the header fi... (diff)
downloadKVIrc-5cbbeabcfd2321e42767063d617b71ae14b3b8c7.tar.gz
KVIrc-5cbbeabcfd2321e42767063d617b71ae14b3b8c7.tar.bz2
KVIrc-5cbbeabcfd2321e42767063d617b71ae14b3b8c7.zip
Add support for sanitizers at compile time (and fix some issues) (#2599)
* Add an option to enable sanitizer at compile time * Fix singleton classes initialization * Revert r5378 - issue #1068 - to avoid having duplicate symbols exported by modules, that may cause a crash * Fix cast in KviTalIconAndRichTextItemDelegate (used by both QListWidget and QTreeWidget) * ScriptEditor: don't leak a timer for every script editor widget * Add support for memory and thread sanitizers * Fix sanitizer * KviSignalhandler: don't leak the whole object * Remove debug warning when a single message is longer than 512 bytes. As per https://ircv3.net/specs/extensions/message-tags.html#size-limit , message tags can prepend a whooping 8kbs of "tags" (header data) to each message. * Avoid initialization loop between KviLocale and KviMessageCatalogue. Assume all .po files are UTF8. This is already a requirement since about a decade. * KviInputEditor: don't leak the undo/redo stacks KviInputEditor: don't leak the undo/redo stacks - rework using smart pointers * Fix typo
Diffstat (limited to 'src')
-rw-r--r--src/kvilib/irc/KviIdentityProfileSet.cpp9
-rw-r--r--src/kvilib/irc/KviIdentityProfileSet.h7
-rw-r--r--src/kvilib/locale/KviLocale.cpp9
-rw-r--r--src/kvilib/locale/KviLocale.h7
-rw-r--r--src/kvilib/locale/KviMessageCatalogue.cpp32
-rw-r--r--src/kvilib/system/KviSignalHandler.cpp2
-rw-r--r--src/kvilib/tal/KviTalIconAndRichTextItemDelegate.cpp7
-rw-r--r--src/kvirc/kernel/KviDefaultScript.cpp9
-rw-r--r--src/kvirc/kernel/KviDefaultScript.h7
-rw-r--r--src/kvirc/kernel/KviIrcLink.cpp5
-rw-r--r--src/kvirc/module/KviModuleManager.cpp2
-rw-r--r--src/kvirc/ui/KviInputEditor.cpp15
-rw-r--r--src/kvirc/ui/KviInputEditor.h4
-rw-r--r--src/kvirc/ui/KviInputHistory.cpp19
-rw-r--r--src/kvirc/ui/KviInputHistory.h19
-rw-r--r--src/modules/editor/ScriptEditorImplementation.cpp5
16 files changed, 34 insertions, 124 deletions
diff --git a/src/kvilib/irc/KviIdentityProfileSet.cpp b/src/kvilib/irc/KviIdentityProfileSet.cpp
index 1c10e1c2c..686114066 100644
--- a/src/kvilib/irc/KviIdentityProfileSet.cpp
+++ b/src/kvilib/irc/KviIdentityProfileSet.cpp
@@ -26,7 +26,6 @@
#include "KviConfigurationFile.h"
KviIdentityProfileSet * KviIdentityProfileSet::m_pSelf = nullptr;
-unsigned int KviIdentityProfileSet::m_uCount = 0;
KviIdentityProfileSet::KviIdentityProfileSet()
: KviHeapObject()
@@ -49,18 +48,18 @@ KviIdentityProfileSet::~KviIdentityProfileSet()
void KviIdentityProfileSet::init()
{
- if((!m_pSelf) && (m_pSelf->count() == 0))
+ if(!m_pSelf)
{
m_pSelf = new KviIdentityProfileSet();
- m_uCount++;
}
}
void KviIdentityProfileSet::done()
{
- m_uCount--;
- if(m_pSelf->count() == 0)
+ if(m_pSelf) {
delete m_pSelf;
+ m_pSelf = nullptr;
+ }
}
void KviIdentityProfileSet::clear()
diff --git a/src/kvilib/irc/KviIdentityProfileSet.h b/src/kvilib/irc/KviIdentityProfileSet.h
index c15076db8..bd608464c 100644
--- a/src/kvilib/irc/KviIdentityProfileSet.h
+++ b/src/kvilib/irc/KviIdentityProfileSet.h
@@ -66,7 +66,6 @@ public:
private:
static KviIdentityProfileSet * m_pSelf;
- static unsigned int m_uCount;
protected:
KviPointerList<KviIdentityProfile> * m_pProfiles;
@@ -92,12 +91,6 @@ public:
static inline KviIdentityProfileSet * instance() { return m_pSelf; };
/**
- * \brief Returns the number of instances of the class
- * \return unsigned int
- */
- unsigned int count() { return m_uCount; };
-
- /**
* \brief Returns the profiles set
* \return KviPointerList<KviIdentityProfile> *
*/
diff --git a/src/kvilib/locale/KviLocale.cpp b/src/kvilib/locale/KviLocale.cpp
index 2d8bd6920..e5cf011b9 100644
--- a/src/kvilib/locale/KviLocale.cpp
+++ b/src/kvilib/locale/KviLocale.cpp
@@ -466,7 +466,6 @@ static KviLocale::EncodingDescription supported_encodings[] = {
};
KviLocale * KviLocale::m_pSelf = nullptr;
-unsigned int KviLocale::m_uCount = 0;
QString KviLocale::g_szLang = "";
KviLocale::KviLocale(QApplication * pApp, const QString & szLocaleDir, const QString & szForceLocaleDir)
@@ -559,18 +558,18 @@ KviLocale::~KviLocale()
void KviLocale::init(QApplication * pApp, const QString & szLocaleDir, const QString & szForceLocaleDir)
{
- if((!m_pSelf) && (m_pSelf->count() == 0))
+ if(!m_pSelf)
{
m_pSelf = new KviLocale(pApp, szLocaleDir, szForceLocaleDir);
- m_uCount++;
}
}
void KviLocale::done()
{
- m_uCount--;
- if(m_pSelf->count() == 0)
+ if(m_pSelf) {
delete m_pSelf;
+ m_pSelf = nullptr;
+ }
}
QTextCodec * KviLocale::codecForName(const char * pcName)
diff --git a/src/kvilib/locale/KviLocale.h b/src/kvilib/locale/KviLocale.h
index ae37dd326..9d356a89e 100644
--- a/src/kvilib/locale/KviLocale.h
+++ b/src/kvilib/locale/KviLocale.h
@@ -97,7 +97,6 @@ protected:
private:
static KviLocale * m_pSelf;
- static unsigned int m_uCount;
public:
/**
@@ -123,12 +122,6 @@ public:
static inline KviLocale * instance() { return m_pSelf; }
/**
- * \brief Returns the number of instances of the class
- * \return unsigned int
- */
- unsigned int count() { return m_uCount; }
-
- /**
* \brief Returns the description of the encoding used
* \param iIdx The index of the description
* \warning You MUST start iterating from 0 and terminate when you get an entry with
diff --git a/src/kvilib/locale/KviMessageCatalogue.cpp b/src/kvilib/locale/KviMessageCatalogue.cpp
index abc9094e8..16865efa4 100644
--- a/src/kvilib/locale/KviMessageCatalogue.cpp
+++ b/src/kvilib/locale/KviMessageCatalogue.cpp
@@ -130,7 +130,7 @@ int kvi_getFirstBiggerPrime(int iNumber)
KviMessageCatalogue::KviMessageCatalogue()
{
//m_uEncoding = 0;
- m_pTextCodec = QTextCodec::codecForLocale();
+ m_pTextCodec = QTextCodec::codecForName("UTF-8");
//m_pMessages = new KviPointerHashTable<const char *,KviTranslationEntry>(1123,true,false); // dictSize, case sensitive, don't copy keys
m_pMessages = new KviPointerHashTable<const char *, KviTranslationEntry>(32, true, false); // dictSize, case sensitive, don't copy keys
@@ -280,36 +280,6 @@ bool KviMessageCatalogue::load(const QString & szName)
KviMemory::free(pcBuffer);
f.close();
-
- m_pTextCodec = nullptr;
-
- // find out the text encoding, if possible
- if(szHeader.hasData())
- {
- // find "charset=*\n"
- int iIdx = szHeader.findFirstIdx("charset=");
- if(iIdx != -1)
- {
- szHeader.cutLeft(iIdx + 8);
- szHeader.cutFromFirst('\n');
- szHeader.trim();
- m_pTextCodec = KviLocale::instance()->codecForName(szHeader.ptr());
- if(!m_pTextCodec)
- {
- qDebug("Can't find the codec for charset=%s", szHeader.ptr());
- qDebug("Falling back to codecForLocale()");
- m_pTextCodec = QTextCodec::codecForLocale();
- }
- }
- }
-
- if(!m_pTextCodec)
- {
- qDebug("The message catalogue does not have a \"charset\" header");
- qDebug("Assuming UTF-8"); // FIXME: or codecForLocale() ?
- m_pTextCodec = QTextCodec::codecForName("UTF-8");
- }
-
return true;
}
diff --git a/src/kvilib/system/KviSignalHandler.cpp b/src/kvilib/system/KviSignalHandler.cpp
index 02f4b6aa1..20ec09824 100644
--- a/src/kvilib/system/KviSignalHandler.cpp
+++ b/src/kvilib/system/KviSignalHandler.cpp
@@ -64,7 +64,7 @@ KviSignalHandler::KviSignalHandler(QObject *parent)
bool kvi_signalHandlerSetup()
{
- new KviSignalHandler();
+ new KviSignalHandler(qApp);
struct sigaction sa;
::memset(&sa,0,sizeof(sa));
diff --git a/src/kvilib/tal/KviTalIconAndRichTextItemDelegate.cpp b/src/kvilib/tal/KviTalIconAndRichTextItemDelegate.cpp
index e7f3ba758..2375ec5ea 100644
--- a/src/kvilib/tal/KviTalIconAndRichTextItemDelegate.cpp
+++ b/src/kvilib/tal/KviTalIconAndRichTextItemDelegate.cpp
@@ -27,7 +27,6 @@
#include <QAbstractItemView>
#include <QAbstractTextDocumentLayout>
#include <QApplication>
-#include <QListWidget>
#include <QPainter>
#define LVI_AFTER_ICON (LVI_BORDER + LVI_ICON_SIZE + LVI_SPACING)
@@ -102,15 +101,15 @@ QSize KviTalIconAndRichTextItemDelegate::sizeHint(const QStyleOptionViewItem & o
QTextDocument doc;
doc.setHtml(szText);
doc.setDefaultFont(option.font);
- doc.setTextWidth(((QListWidget *)parent())->viewport()->width() - LVI_AFTER_ICON - LVI_BORDER);
+ doc.setTextWidth(((QAbstractItemView *)parent())->viewport()->width() - LVI_AFTER_ICON - LVI_BORDER);
int iHeight = doc.documentLayout()->documentSize().toSize().height();
- //qDebug("Size hint (%d,%d)",((QListWidget *)parent())->minimumWidth(), iHeight + (2 * LVI_BORDER));
+ //qDebug("Size hint (%d,%d)",((QAbstractItemView *)parent())->minimumWidth(), iHeight + (2 * LVI_BORDER));
int iIconWidth = m_oIconSize.width() + (2 * LVI_BORDER);
int iIconHeight = m_oIconSize.height() + (2 * LVI_BORDER);
- int w = ((QListWidget *)parent())->minimumWidth();
+ int w = ((QAbstractItemView *)parent())->minimumWidth();
if(w < iIconWidth)
w = iIconWidth;
if(w < m_oMinimumSize.width())
diff --git a/src/kvirc/kernel/KviDefaultScript.cpp b/src/kvirc/kernel/KviDefaultScript.cpp
index f8ffe8186..b65c75f6b 100644
--- a/src/kvirc/kernel/KviDefaultScript.cpp
+++ b/src/kvirc/kernel/KviDefaultScript.cpp
@@ -41,7 +41,6 @@
#include <QMessageBox>
KviDefaultScriptManager * KviDefaultScriptManager::m_pSelf = nullptr;
-unsigned int KviDefaultScriptManager::m_uCount = 0;
KviDefaultScriptManager::KviDefaultScriptManager()
: QObject()
@@ -72,18 +71,18 @@ KviDefaultScriptManager::~KviDefaultScriptManager()
void KviDefaultScriptManager::init()
{
- if((!m_pSelf) && (m_pSelf->count() == 0))
+ if(!m_pSelf)
{
m_pSelf = new KviDefaultScriptManager();
- m_uCount++;
}
}
void KviDefaultScriptManager::done()
{
- m_uCount--;
- if(m_pSelf->count() == 0)
+ if(m_pSelf) {
delete m_pSelf;
+ m_pSelf = nullptr;
+ }
}
bool KviDefaultScriptManager::isDefscriptUpToDate()
diff --git a/src/kvirc/kernel/KviDefaultScript.h b/src/kvirc/kernel/KviDefaultScript.h
index 3fc658e9f..667d6154c 100644
--- a/src/kvirc/kernel/KviDefaultScript.h
+++ b/src/kvirc/kernel/KviDefaultScript.h
@@ -61,7 +61,6 @@ public:
private:
static KviDefaultScriptManager * m_pSelf;
- static unsigned int m_uCount;
bool m_bNoNeedToRestore = false;
bool m_bConfigFileMissing = false;
KviDefaultScriptDialog * m_pDialog = nullptr;
@@ -96,12 +95,6 @@ public:
static inline KviDefaultScriptManager * instance() { return m_pSelf; }
/**
- * \brief Returns the number of instances of the class
- * \return unsigned int
- */
- unsigned int count() const { return m_uCount; }
-
- /**
* \brief Checks if the local defscript is up to date
* \return bool
*/
diff --git a/src/kvirc/kernel/KviIrcLink.cpp b/src/kvirc/kernel/KviIrcLink.cpp
index 30b83b0e0..281ca474b 100644
--- a/src/kvirc/kernel/KviIrcLink.cpp
+++ b/src/kvirc/kernel/KviIrcLink.cpp
@@ -296,11 +296,6 @@ void KviIrcLink::processData(char * buffer, int iLen)
m_pReadBuffer = (char *)KviMemory::allocate(m_uReadBufferLen);
KviMemory::move(m_pReadBuffer, cBeginOfCurData, m_uReadBufferLen);
}
- //The m_pReadBuffer contains at max 1 IRC message...
- //that can not be longer than 510 bytes (the message is not CRLF terminated)
- // FIXME: Is this limit *really* valid on all servers ?
- if(m_uReadBufferLen > 510)
- qDebug("WARNING: receiving an invalid IRC message from server.");
}
KviMemory::free(cMessageBuffer);
}
diff --git a/src/kvirc/module/KviModuleManager.cpp b/src/kvirc/module/KviModuleManager.cpp
index 37cee0b83..933d9e266 100644
--- a/src/kvirc/module/KviModuleManager.cpp
+++ b/src/kvirc/module/KviModuleManager.cpp
@@ -175,8 +175,6 @@ bool KviModuleManager::loadModule(const QString & modName)
}
QLibrary * pLibrary = new QLibrary(tmp);
- pLibrary->setLoadHints(QLibrary::ExportExternalSymbolsHint);
-
if(!pLibrary->load())
{
m_szLastError = pLibrary->errorString();
diff --git a/src/kvirc/ui/KviInputEditor.cpp b/src/kvirc/ui/KviInputEditor.cpp
index f3cab5fe7..a73f2aaf6 100644
--- a/src/kvirc/ui/KviInputEditor.cpp
+++ b/src/kvirc/ui/KviInputEditor.cpp
@@ -216,6 +216,7 @@ KviInputEditor::~KviInputEditor()
if(m_iCursorTimer)
killTimer(m_iCursorTimer);
killDragTimer();
+ clearUndoStack();
qDeleteAll(m_p->lTextBlocks);
delete m_p;
@@ -2602,7 +2603,7 @@ void KviInputEditor::undo()
if(m_UndoStack.empty())
return; // this should be ensured by isUndoAvailable() but well...
- EditCommand * pCommand = m_UndoStack.back();
+ std::unique_ptr<EditCommand> pCommand = std::move(m_RedoStack.back());
m_UndoStack.pop_back();
Q_ASSERT(pCommand); // should be true: we delete the empty undo stack
@@ -2624,12 +2625,10 @@ void KviInputEditor::undo()
break;
default:
Q_ASSERT_X(false, "KviInputEditor::undo", "Unexpected EditCommand type");
- delete pCommand; // argh
return;
- break;
}
- m_RedoStack.push_back(pCommand);
+ m_RedoStack.push_back(std::move(pCommand));
if(m_RedoStack.size() > KVI_INPUT_MAX_UNDO_SIZE)
m_RedoStack.erase(m_RedoStack.begin()); // will delete it
}
@@ -2642,7 +2641,7 @@ void KviInputEditor::redo()
if(m_RedoStack.empty())
return; // this should be ensured by isUndoAvailable() but well...
- EditCommand * pCommand = m_RedoStack.back();
+ std::unique_ptr<EditCommand> pCommand = std::move(m_RedoStack.back());
m_RedoStack.pop_back();
Q_ASSERT(pCommand); // should be true: we delete the empty redo stack
@@ -2664,19 +2663,17 @@ void KviInputEditor::redo()
break;
default:
Q_ASSERT_X(false, "KviInputEditor::redo", "Unexpected EditCommand type");
- delete pCommand; // argh
return;
- break;
}
- m_UndoStack.push_back(pCommand);
+ m_UndoStack.push_back(std::move(pCommand));
if(m_UndoStack.size() > KVI_INPUT_MAX_UNDO_SIZE)
m_UndoStack.erase(m_UndoStack.begin()); // will delete it
}
void KviInputEditor::addUndo(EditCommand * pCommand)
{
- m_UndoStack.push_back(pCommand);
+ m_UndoStack.push_back(std::unique_ptr<EditCommand>(pCommand));
if(m_UndoStack.size() > KVI_INPUT_MAX_UNDO_SIZE)
m_UndoStack.erase(m_UndoStack.begin()); // will delete it
diff --git a/src/kvirc/ui/KviInputEditor.h b/src/kvirc/ui/KviInputEditor.h
index 88ad6a0db..2cf12c504 100644
--- a/src/kvirc/ui/KviInputEditor.h
+++ b/src/kvirc/ui/KviInputEditor.h
@@ -253,7 +253,7 @@ protected:
* Contains owned pointers and has autodelete set to true. The most recent command
* is at the end. Null when no undo is available.
*/
- std::vector<EditCommand *> m_UndoStack;
+ std::vector<std::unique_ptr<EditCommand>> m_UndoStack;
/**
* \var m_RedoStack
@@ -262,7 +262,7 @@ protected:
* Contains owned pointers and has autodelete set to true. The most recently undone
* command is at the end. Null when no redo is available.
*/
- std::vector<EditCommand *> m_RedoStack;
+ std::vector<std::unique_ptr<EditCommand>> m_RedoStack;
KviInputEditorPrivate * m_p;
diff --git a/src/kvirc/ui/KviInputHistory.cpp b/src/kvirc/ui/KviInputHistory.cpp
index 5f46ad0d9..58784e892 100644
--- a/src/kvirc/ui/KviInputHistory.cpp
+++ b/src/kvirc/ui/KviInputHistory.cpp
@@ -33,32 +33,21 @@
#include <QString>
KviInputHistory * KviInputHistory::m_pSelf = nullptr;
-unsigned int KviInputHistory::m_uCount = 0;
void KviInputHistory::init()
{
- if((!m_pSelf) && (m_pSelf->count() == 0))
+ if(!m_pSelf)
{
m_pSelf = new KviInputHistory();
- addRef();
}
}
void KviInputHistory::done()
{
- delRef();
- if(m_pSelf->count() == 0)
+ if(m_pSelf) {
delete m_pSelf;
-}
-
-void KviInputHistory::addRef()
-{
- m_uCount++;
-}
-
-void KviInputHistory::delRef()
-{
- m_uCount--;
+ m_pSelf = nullptr;
+ }
}
void KviInputHistory::add(const QString & szString)
diff --git a/src/kvirc/ui/KviInputHistory.h b/src/kvirc/ui/KviInputHistory.h
index 068401a86..c7fb59581 100644
--- a/src/kvirc/ui/KviInputHistory.h
+++ b/src/kvirc/ui/KviInputHistory.h
@@ -54,7 +54,6 @@ class KVIRC_API KviInputHistory
{
private:
static KviInputHistory * m_pSelf;
- static unsigned int m_uCount;
protected:
std::vector<QString> m_StringList;
@@ -79,24 +78,6 @@ public:
static inline KviInputHistory * instance() { return m_pSelf; };
/**
- * \brief Returns the number of instances of the class
- * \return unsigned int
- */
- unsigned int count() { return m_uCount; };
-
- /**
- * \brief Adds a reference to the class
- * \return void
- */
- static void addRef();
-
- /**
- * \brief Removes a reference to the class
- * \return void
- */
- static void delRef();
-
- /**
* \brief Adds a string to the history
* \param szString The string to add
* \return void
diff --git a/src/modules/editor/ScriptEditorImplementation.cpp b/src/modules/editor/ScriptEditorImplementation.cpp
index 81081fae8..c567d01e3 100644
--- a/src/modules/editor/ScriptEditorImplementation.cpp
+++ b/src/modules/editor/ScriptEditorImplementation.cpp
@@ -137,6 +137,11 @@ ScriptEditorWidget::~ScriptEditorWidget()
if(m_pCompleter)
delete m_pCompleter;
disableSyntaxHighlighter();
+ if(m_pStartTimer) {
+ m_pStartTimer->stop();
+ m_pStartTimer->deleteLater();
+ m_pStartTimer = nullptr;
+ }
}
void ScriptEditorWidget::checkReadyCompleter()