Skip to content

Commit

Permalink
cleanup: Avoid implicit bool conversions.
Browse files Browse the repository at this point in the history
```sh
run-clang-tidy -p _build -fix \
  $(find . -name "*.h" -or -name "*.cpp" -or -name "*.c" | grep -v "/_build/") \
  -checks="-*,readability-implicit-bool-conversion"`
```
  • Loading branch information
iphydf committed Jan 20, 2025
1 parent a8ca17e commit 294c468
Show file tree
Hide file tree
Showing 76 changed files with 367 additions and 362 deletions.
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Checks: "-*
, performance-move-const-arg
, readability-container-*
, readability-else-after-return
, readability-implicit-bool-conversion
, readability-isolate-declaration
, readability-make-member-function-const
, readability-named-parameter
Expand Down
36 changes: 18 additions & 18 deletions audio/src/backend/openal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ void OpenAL::checkAlError() noexcept
void OpenAL::checkAlcError(ALCdevice* device) noexcept
{
const ALCenum alc_err = alcGetError(device);
if (alc_err) {
if (alc_err != 0) {
qWarning("OpenAL error: %s", alcGetString(device, alc_err));
}
}
Expand Down Expand Up @@ -295,7 +295,7 @@ void OpenAL::destroySink(AlSink& sink)

const uint sid = sink.getSourceId();

if (alIsSource(sid)) {
if (alIsSource(sid) != 0) {
// stop playing, marks all buffers as processed
alSourceStop(sid);
cleanupBuffers(sid);
Expand Down Expand Up @@ -364,7 +364,7 @@ void OpenAL::destroySource(AlSource& source)
*/
bool OpenAL::autoInitInput()
{
return alInDev ? true : initInput(settings.getInDev());
return (alInDev != nullptr) ? true : initInput(settings.getInDev());
}

/**
Expand All @@ -374,7 +374,7 @@ bool OpenAL::autoInitInput()
*/
bool OpenAL::autoInitOutput()
{
return alOutDev ? true : initOutput(settings.getOutDev());
return (alOutDev != nullptr) ? true : initOutput(settings.getOutDev());
}

bool OpenAL::initInput(const QString& deviceName)
Expand Down Expand Up @@ -405,7 +405,7 @@ bool OpenAL::initInput(const QString& deviceName, uint32_t channels)
alInDev = alcCaptureOpenDevice(tmpDevName, AUDIO_SAMPLE_RATE, stereoFlag, ringBufSize);

// Restart the capture if necessary
if (!alInDev) {
if (alInDev == nullptr) {
qCWarning(logcat::audio) << "Failed to initialize audio input device:" << deviceName;
return false;
}
Expand Down Expand Up @@ -439,7 +439,7 @@ bool OpenAL::initOutput(const QString& deviceName)
const ALchar* tmpDevName = qDevName.isEmpty() ? nullptr : qDevName.constData();
alOutDev = alcOpenDevice(tmpDevName);

if (!alOutDev) {
if (alOutDev == nullptr) {
qCWarning(logcat::audio) << "Cannot open audio output device" << deviceName;
return false;
}
Expand All @@ -448,7 +448,7 @@ bool OpenAL::initOutput(const QString& deviceName)
alOutContext = alcCreateContext(alOutDev, nullptr);
checkAlcError(alOutDev);

if (!alcMakeContextCurrent(alOutContext)) {
if (alcMakeContextCurrent(alOutContext) == 0) {
qCWarning(logcat::audio) << "Cannot create audio output context";
return false;
}
Expand Down Expand Up @@ -532,7 +532,7 @@ void OpenAL::playAudioBuffer(uint sourceId, const int16_t* data, int samples, un
assert(channels == 1 || channels == 2);
const QMutexLocker<QRecursiveMutex> locker(&audioLock);

if (!(alOutDev && outputInitialized))
if (!((alOutDev != nullptr) && outputInitialized))
return;

ALuint bufids[BUFFER_COUNT];
Expand Down Expand Up @@ -572,7 +572,7 @@ void OpenAL::playAudioBuffer(uint sourceId, const int16_t* data, int samples, un
*/
void OpenAL::cleanupInput()
{
if (!alInDev)
if (alInDev == nullptr)
return;

qCDebug(logcat::audio) << "Closing audio input";
Expand All @@ -593,16 +593,16 @@ void OpenAL::cleanupOutput()
{
outputInitialized = false;

if (alOutDev) {
if (!alcMakeContextCurrent(nullptr)) {
if (alOutDev != nullptr) {
if (alcMakeContextCurrent(nullptr) == 0) {
qWarning("Failed to clear audio context");
}

alcDestroyContext(alOutContext);
alOutContext = nullptr;

qCDebug(logcat::audio) << "Closing audio output";
if (alcCloseDevice(alOutDev)) {
if (alcCloseDevice(alOutDev) != 0) {
alOutDev = nullptr;
} else {
qWarning("Failed to close output");
Expand Down Expand Up @@ -694,7 +694,7 @@ void OpenAL::doAudio()
// Output section does nothing

// Input section
if (alInDev && !sources.empty()) {
if ((alInDev != nullptr) && !sources.empty()) {
doInput();
}
}
Expand All @@ -710,7 +710,7 @@ void OpenAL::captureSamples(ALCdevice* device, int16_t* buffer, ALCsizei samples
bool OpenAL::isOutputReady() const
{
const QMutexLocker<QRecursiveMutex> locker(&audioLock);
return alOutDev && outputInitialized;
return (alOutDev != nullptr) && outputInitialized;
}

QStringList OpenAL::outDeviceNames()
Expand All @@ -720,8 +720,8 @@ QStringList OpenAL::outDeviceNames()
? alcGetString(nullptr, ALC_ALL_DEVICES_SPECIFIER)
: alcGetString(nullptr, ALC_DEVICE_SPECIFIER);

if (pDeviceList) {
while (*pDeviceList) {
if (pDeviceList != nullptr) {
while (*pDeviceList != 0) {
auto len = strlen(pDeviceList);
list << QString::fromUtf8(pDeviceList, len);
pDeviceList += len + 1;
Expand All @@ -736,9 +736,9 @@ QStringList OpenAL::inDeviceNames()
QStringList list;
const ALchar* pDeviceList = alcGetString(nullptr, ALC_CAPTURE_DEVICE_SPECIFIER);

if (pDeviceList) {
if (pDeviceList != nullptr) {
qCDebug(logcat::audio) << "Available input devices:" << pDeviceList;
while (*pDeviceList) {
while (*pDeviceList != 0) {
auto len = strlen(pDeviceList);
list << QString::fromUtf8(pDeviceList, len);
pDeviceList += len + 1;
Expand Down
18 changes: 9 additions & 9 deletions src/appmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void logMessageHandler(QtMsgType type, const QMessageLogContext& ctxt, const QSt

const QString file = canonicalLogFilePath(ctxt.file);
const QString category =
ctxt.category ? QString::fromUtf8(ctxt.category) : QStringLiteral("default");
(ctxt.category != nullptr) ? QString::fromUtf8(ctxt.category) : QStringLiteral("default");
if ((type == QtDebugMsg && category == QStringLiteral("tox.core")
&& (file == QStringLiteral("rtp.c") || file == QStringLiteral("video.c")))
|| (file == QStringLiteral("bwcontroller.c") && msg.contains("update"))) {
Expand Down Expand Up @@ -146,15 +146,15 @@ void logMessageHandler(QtMsgType type, const QMessageLogContext& ctxt, const QSt

#ifdef LOG_TO_FILE
FILE* logFilePtr = logFileFile.loadRelaxed(); // atomically load the file pointer
if (!logFilePtr) {
if (logFilePtr == nullptr) {
logBufferMutex->lock();
if (logBuffer)
if (logBuffer != nullptr)
logBuffer->append(LogMsgBytes);

logBufferMutex->unlock();
} else {
logBufferMutex->lock();
if (logBuffer) {
if (logBuffer != nullptr) {
// empty logBuffer to file
for (const QByteArray& bufferedMsg : *logBuffer) {
fwrite(bufferedMsg.constData(), 1, bufferedMsg.size(), logFilePtr);
Expand All @@ -178,7 +178,7 @@ bool toxURIEventHandler(const QByteArray& eventData, void* userData)
return false;
}

if (!uriDialog) {
if (uriDialog == nullptr) {
return false;
}

Expand Down Expand Up @@ -221,7 +221,7 @@ int AppManager::startGui(QCommandLineParser& parser)
qDebug() << "Log file over 1MB, rotating...";

// close old logfile (need for windows)
if (mainLogFilePtr)
if (mainLogFilePtr != nullptr)
fclose(mainLogFilePtr);

QDir dir(logFileDir);
Expand All @@ -239,7 +239,7 @@ int AppManager::startGui(QCommandLineParser& parser)
mainLogFilePtr = fopen(logfile.toLocal8Bit().constData(), "a");
}

if (!mainLogFilePtr) {
if (mainLogFilePtr == nullptr) {
qCritical() << "Couldn't open logfile" << logfile;
} else {
qDebug() << "Logging to" << logfile;
Expand Down Expand Up @@ -329,11 +329,11 @@ int AppManager::startGui(QCommandLineParser& parser)
&& !Profile::isEncrypted(profileName, settings->getPaths())) {
profile = Profile::loadProfile(profileName, QString(), *settings, &parser, *cameraSource,
*messageBoxManager);
if (!profile) {
if (profile == nullptr) {
QMessageBox::information(nullptr, tr("Error"), tr("Failed to load profile automatically."));
}
}
if (profile) {
if (profile != nullptr) {
nexus->bootstrapWithProfile(profile);
} else {
nexus->setParser(&parser);
Expand Down
12 changes: 6 additions & 6 deletions src/chatlog/chatline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ChatLine::ChatLine() = default;
ChatLine::~ChatLine()
{
for (ChatLineContent* c : content) {
if (c->scene())
if (c->scene() != nullptr)
c->scene()->removeItem(c);

delete c;
Expand Down Expand Up @@ -52,14 +52,14 @@ ChatLineContent* ChatLine::getContent(QPointF scenePos) const
void ChatLine::removeFromScene()
{
for (ChatLineContent* c : content) {
if (c->scene())
if (c->scene() != nullptr)
c->scene()->removeItem(c);
}
}

void ChatLine::addToScene(QGraphicsScene* scene)
{
if (!scene)
if (scene == nullptr)
return;

for (ChatLineContent* c : content)
Expand Down Expand Up @@ -119,7 +119,7 @@ QRectF ChatLine::sceneBoundingRect() const

void ChatLine::addColumn(ChatLineContent* item, ColumnFormat fmt)
{
if (!item)
if (item == nullptr)
return;

format.push_back(fmt);
Expand All @@ -129,14 +129,14 @@ void ChatLine::addColumn(ChatLineContent* item, ColumnFormat fmt)

void ChatLine::replaceContent(int col, ChatLineContent* lineContent)
{
if (col >= 0 && col < content.size() && lineContent) {
if (col >= 0 && col < content.size() && (lineContent != nullptr)) {
QGraphicsScene* scene = content[col]->scene();
delete content[col];

content[col] = lineContent;
lineContent->setIndex(row, col);

if (scene)
if (scene != nullptr)
scene->addItem(content[col]);

layout(width, bbox.topLeft());
Expand Down
6 changes: 3 additions & 3 deletions src/chatlog/chatmessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ void ChatMessage::markAsBroken()
QString ChatMessage::toString() const
{
ChatLineContent* c = getContent(1);
if (c)
if (c != nullptr)
return c->getText();

return {};
Expand All @@ -272,14 +272,14 @@ void ChatMessage::setAsAction()
void ChatMessage::hideSender()
{
ChatLineContent* c = getContent(0);
if (c)
if (c != nullptr)
c->hide();
}

void ChatMessage::hideDate()
{
ChatLineContent* c = getContent(2);
if (c)
if (c != nullptr)
c->hide();
}

Expand Down
Loading

0 comments on commit 294c468

Please sign in to comment.