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 Nov 18, 2024
1 parent b699420 commit 189cf89
Show file tree
Hide file tree
Showing 75 changed files with 371 additions and 367 deletions.
36 changes: 18 additions & 18 deletions audio/src/backend/openal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,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: %d", alc_err);
}

Expand Down Expand Up @@ -248,7 +248,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 @@ -319,7 +319,7 @@ void OpenAL::destroySource(AlSource& source)
*/
bool OpenAL::autoInitInput()
{
return alInDev ? true : initInput(settings.getInDev());
return alInDev != nullptr ? true : initInput(settings.getInDev());
}

/**
Expand All @@ -329,7 +329,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 @@ -360,7 +360,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) {
qWarning() << "Failed to initialize audio input device:" << deviceName;
return false;
}
Expand Down Expand Up @@ -394,7 +394,7 @@ bool OpenAL::initOutput(const QString& deviceName)
const ALchar* tmpDevName = qDevName.isEmpty() ? nullptr : qDevName.constData();
alOutDev = alcOpenDevice(tmpDevName);

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

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

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

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

qDebug() << "Closing audio input";
Expand All @@ -547,16 +547,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;

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

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

QStringList OpenAL::outDeviceNames()
Expand All @@ -674,8 +674,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 @@ -690,8 +690,8 @@ QStringList OpenAL::inDeviceNames()
QStringList list;
const ALchar* pDeviceList = alcGetString(nullptr, ALC_CAPTURE_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 Down
16 changes: 8 additions & 8 deletions src/appmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,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
foreach (QByteArray bufferedMsg, *logBuffer)
fwrite(bufferedMsg.constData(), 1, bufferedMsg.size(), logFilePtr);
Expand All @@ -135,7 +135,7 @@ bool toxURIEventHandler(const QByteArray& eventData, void* userData)
return false;
}

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

Expand Down Expand Up @@ -233,7 +233,7 @@ int AppManager::run()
qDebug() << "Log file over 1MB, rotating...";

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

QDir dir(logFileDir);
Expand All @@ -251,7 +251,7 @@ int AppManager::run()
mainLogFilePtr = fopen(logfile.toLocal8Bit().constData(), "a");
}

if (!mainLogFilePtr)
if (mainLogFilePtr == nullptr)
qCritical() << "Couldn't open logfile" << logfile;

logFileFile.storeRelaxed(mainLogFilePtr); // atomically set the logFile
Expand Down Expand Up @@ -336,11 +336,11 @@ int AppManager::run()
&& !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
14 changes: 7 additions & 7 deletions src/chatlog/chatline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ChatLine::ChatLine() {}
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 All @@ -147,7 +147,7 @@ void ChatLine::replaceContent(int col, ChatLineContent* lineContent)

void ChatLine::layout(qreal w, QPointF scenePos)
{
if (!content.size())
if (content.size() == 0)
return;

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

return QString();
Expand All @@ -271,14 +271,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 189cf89

Please sign in to comment.