From 722918abd647f55fa7ceb2018103ca5ee11cce58 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Thu, 16 Mar 2017 16:30:28 +0100 Subject: [PATCH] Folder::showSyncResultPopup: Fix undefined behavior when there is no errors When there is no errors _syncResult.firstItemError() is NULL, and accessing it's _file member is an undefined behavior. (Thankfully, createGuiLog did not use the string when the count was 0, but we are not supposed to create null references. Found with the UB sanitizer: src/gui/folder.cpp:348:49: runtime error: member access within null pointer of type 'OCC::SyncFileItem' src/gui/folder.cpp:348:19: runtime error: reference binding to null pointer of type 'const QString' --- src/gui/folder.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp index 18d2f2b12..d20215a0e 100644 --- a/src/gui/folder.cpp +++ b/src/gui/folder.cpp @@ -345,7 +345,9 @@ void Folder::showSyncResultPopup() if( _syncResult.firstConflictItem() ) { createGuiLog( _syncResult.firstConflictItem()->_file, LogStatusConflict, _syncResult.numConflictItems() ); } - createGuiLog( _syncResult.firstItemError()->_file, LogStatusError, _syncResult.numErrorItems() ); + if (int errorCount = _syncResult.numErrorItems()) { + createGuiLog( _syncResult.firstItemError()->_file, LogStatusError, errorCount ); + } qDebug() << "OO folder slotSyncFinished: result: " << int(_syncResult.status()); } -- 2.30.2