edbee / edbee-lib

QWidget based Text Editor Component for Qt. Multi-caret, Textmate grammar and highlighting support.
Other
73 stars 25 forks source link

Coverity scan issues #35

Closed vadi2 closed 7 years ago

vadi2 commented 7 years ago

We make use of https://scan.coverity.com (you could set it up for edbee as well), and after running Mudlet through it with edbee integrated, Coverity complained a whole lot. We'll flag them as 3rdparty, but I figure it's useful to report all the issues:

** CID 1446907:  Uninitialized members  (UNINIT_CTOR)
/home/vadi/Programs/Mudlet/mudlet/3rdparty/edbee-lib/edbee-lib/edbee/util/regexp.cpp: 101 in edbee::OnigRegExpEngine::OnigRegExpEngine(const QString &, bool, edbee::RegExp::Syntax)()

________________________________________________________________________________________________________
*** CID 1446907:  Uninitialized members  (UNINIT_CTOR)
/home/vadi/Programs/Mudlet/mudlet/3rdparty/edbee-lib/edbee-lib/edbee/util/regexp.cpp: 101 in edbee::OnigRegExpEngine::OnigRegExpEngine(const QString &, bool, edbee::RegExp::Syntax)()
95             OnigOptionType onigOptions = ONIG_OPTION_NONE|ONIG_OPTION_CAPTURE_GROUP;
96             if( !caseSensitive ) { onigOptions = onigOptions | ONIG_OPTION_IGNORECASE;}
97
98             int result = onig_new(&reg_, (OnigUChar*)patternChars, (OnigUChar*)(patternChars + pattern.length()), onigOptions, ONIG_ENCODING_UTF16_LE, ONIG_SYNTAX_DEFAULT, &einfo_);
99             valid_ = result == ONIG_NORMAL;
100             fillError( result );
>>>     CID 1446907:  Uninitialized members  (UNINIT_CTOR)
>>>     Non-static class member "lineRef_" is not initialized in this constructor nor in any functions that it calls.
101         }
102
103
104         /// destructs the regular expression engine
105         virtual ~OnigRegExpEngine()
106         {

** CID 1446906:  Control flow issues  (MISSING_BREAK)
/home/vadi/Programs/Mudlet/mudlet/3rdparty/edbee-lib/edbee-lib/edbee/util/regexp.cpp: 395 in edbee::RegExp::RegExp(const QString &, bool, edbee::RegExp::Syntax, edbee::RegExp::Engine)()

________________________________________________________________________________________________________
*** CID 1446906:  Control flow issues  (MISSING_BREAK)
/home/vadi/Programs/Mudlet/mudlet/3rdparty/edbee-lib/edbee-lib/edbee/util/regexp.cpp: 395 in edbee::RegExp::RegExp(const QString &, bool, edbee::RegExp::Syntax, edbee::RegExp::Engine)()
389             case EngineQRegExp:
390                 d_ = new QtRegExpEngine(pattern, caseSensitive, syntax);
391                 break;
392             default:
393                 Q_ASSERT(false);
394                 qlog_warn() << "Invalid engine supplied to RegExp. Falling back to EngineOniguruma";
>>>     CID 1446906:  Control flow issues  (MISSING_BREAK)
>>>     The above case falls through to this one.
395             case EngineOniguruma:
396                 d_ = new OnigRegExpEngine(pattern, caseSensitive, syntax);
397         }
398     }
399
400

** CID 1446905:  Null pointer dereferences  (FORWARD_NULL)
/home/vadi/Programs/Mudlet/mudlet/3rdparty/edbee-lib/edbee-lib/edbee/models/changes/mergablechangegroup.cpp: 401 in edbee::MergableChangeGroup::toSingleTextChangeTestString()()

________________________________________________________________________________________________________
*** CID 1446905:  Null pointer dereferences  (FORWARD_NULL)
/home/vadi/Programs/Mudlet/mudlet/3rdparty/edbee-lib/edbee-lib/edbee/models/changes/mergablechangegroup.cpp: 401 in edbee::MergableChangeGroup::toSingleTextChangeTestString()()
395     QString MergableChangeGroup::toSingleTextChangeTestString()
396     {
397         QString result;
398         foreach( AbstractRangedChange* abstractChange, textChangeList_ ) {
399             TextChange* change = dynamic_cast<TextChange*>(abstractChange);
400             if( !result.isEmpty() ) result.append(",");
>>>     CID 1446905:  Null pointer dereferences  (FORWARD_NULL)
>>>     Passing null pointer "change" to "offset", which dereferences it. (The dereference happens because this is a virtual function call.)
401             result.append( QString("%1:%2:%3").arg(change->offset()).arg(change->docLength()).arg(change->storedText()) );
402         }
403         return result;
404     }
405
406

** CID 1446904:  Incorrect expression  (DIVIDE_BY_ZERO)
/home/vadi/Programs/Mudlet/mudlet/3rdparty/edbee-lib/edbee-lib/edbee/util/simpleprofiler.cpp: 106 in edbee::SimpleProfiler::dumpResults()()

________________________________________________________________________________________________________
*** CID 1446904:  Incorrect expression  (DIVIDE_BY_ZERO)
/home/vadi/Programs/Mudlet/mudlet/3rdparty/edbee-lib/edbee-lib/edbee/util/simpleprofiler.cpp: 106 in edbee::SimpleProfiler::dumpResults()()
100                 totalCallCount += item->callCount();
101                 totalDurationWitoutChilds += item->durationWithoutChilds();
102             }
103
104             foreach( ProfilerItem* item, items ) {
105                 double durationPercentage = 100.0 * item->duration() / totalDuration;
>>>     CID 1446904:  Incorrect expression  (DIVIDE_BY_ZERO)
>>>     In expression "100. * item->callCount() / totalCallCount", division by expression "totalCallCount" which may be zero has undefined behavior.
106                 double callCountPercentage = 100.0 * item->callCount() / totalCallCount;
107                 double durationWithoutChildsPercenage = 100.0 * item->durationWithoutChilds() / totalDurationWitoutChilds;
108
109                 QString line = QString("%1x(%2%) %3ms(%4%) %5ms(%6%) |  %7:%8 %9")
110                    .arg(item->callCount(),8).arg( callCountPercentage, 6, 'f', 2 )
111                    .arg(item->duration(),6).arg( durationPercentage, 6, 'f', 2 )

** CID 1446902:  Incorrect expression  (DIVIDE_BY_ZERO)
/home/vadi/Programs/Mudlet/mudlet/3rdparty/edbee-lib/edbee-lib/edbee/util/simpleprofiler.cpp: 107 in edbee::SimpleProfiler::dumpResults()()

________________________________________________________________________________________________________
*** CID 1446902:  Incorrect expression  (DIVIDE_BY_ZERO)
/home/vadi/Programs/Mudlet/mudlet/3rdparty/edbee-lib/edbee-lib/edbee/util/simpleprofiler.cpp: 107 in edbee::SimpleProfiler::dumpResults()()
101                 totalDurationWitoutChilds += item->durationWithoutChilds();
102             }
103
104             foreach( ProfilerItem* item, items ) {
105                 double durationPercentage = 100.0 * item->duration() / totalDuration;
106                 double callCountPercentage = 100.0 * item->callCount() / totalCallCount;
>>>     CID 1446902:  Incorrect expression  (DIVIDE_BY_ZERO)
>>>     In expression "100. * item->durationWithoutChilds() / totalDurationWitoutChilds", division by expression "totalDurationWitoutChilds" which may be zero has undefined behavior.
107                 double durationWithoutChildsPercenage = 100.0 * item->durationWithoutChilds() / totalDurationWitoutChilds;
108
109                 QString line = QString("%1x(%2%) %3ms(%4%) %5ms(%6%) |  %7:%8 %9")
110                    .arg(item->callCount(),8).arg( callCountPercentage, 6, 'f', 2 )
111                    .arg(item->duration(),6).arg( durationPercentage, 6, 'f', 2 )
112                    .arg(item->durationWithoutChilds(), 6 ).arg( durationWithoutChildsPercenage, 6, 'f', 2 )

** CID 1446901:  Memory - corruptions  (USE_AFTER_FREE)
/home/vadi/Programs/Mudlet/mudlet/3rdparty/edbee-lib/edbee-lib/edbee/util/mem/debug_new.cpp: 105 in operator delete[] (void *, const char *, int)()

** CID 1446899:  Memory - corruptions  (USE_AFTER_FREE)
/home/vadi/Programs/Mudlet/mudlet/3rdparty/edbee-lib/edbee-lib/edbee/util/mem/debug_new.cpp: 82 in operator delete (void *, const char *, int)()

________________________________________________________________________________________________________
*** CID 1446899:  Memory - corruptions  (USE_AFTER_FREE)
/home/vadi/Programs/Mudlet/mudlet/3rdparty/edbee-lib/edbee-lib/edbee/util/mem/debug_new.cpp: 82 in operator delete (void *, const char *, int)()
76     }
77
78
79     /// th delete operator
80     void operator delete (void* p, const char* file, const int line)
81     {
>>>     CID 1446899:  Memory - corruptions  (USE_AFTER_FREE)
>>>     "operator delete" frees "p". [Note: The source code implementation of the function has been overridden by a builtin model.]
82         operator delete(p);
83         debug_free(p, file, line);
84     }
85
86
87     /// the delete operator

** CID 1446898:  Incorrect expression  (NO_EFFECT)
/home/vadi/Programs/Mudlet/mudlet/3rdparty/edbee-lib/edbee-lib/edbee/views/texttheme.cpp: 311 in edbee::TextThemeStyler::themePointerChanged(const QString &, edbee::TextTheme *, edbee::TextTheme *)()

________________________________________________________________________________________________________
*** CID 1446898:  Incorrect expression  (NO_EFFECT)
/home/vadi/Programs/Mudlet/mudlet/3rdparty/edbee-lib/edbee-lib/edbee/views/texttheme.cpp: 311 in edbee::TextThemeStyler::themePointerChanged(const QString &, edbee::TextTheme *, edbee::TextTheme *)()
305     void TextThemeStyler::themePointerChanged(const QString& name, TextTheme* oldTheme, TextTheme *newTheme)
306     {
307         if( name == themeName_ ) {
308             themeRef_ = newTheme;
309         } else {
310             if( oldTheme == themeRef_ ) {
>>>     CID 1446898:  Incorrect expression  (NO_EFFECT)
>>>     Comparing an array to null is not useful: ""The old theme is deleted but it's not the same theme name. This shouldn't happen"", since the test will always evaluate as true.
311                 Q_ASSERT(false && "The old theme is deleted but it's not the same theme name. This shouldn't happen");
312                 // If it happens a solution is to set the fallback theme
313             }
314         }
315     }
316

** CID 1446897:  Incorrect expression  (NO_EFFECT)
/home/vadi/Programs/Mudlet/mudlet/3rdparty/edbee-lib/edbee-lib/edbee/commands/newlinecommand.cpp: 178 in edbee::NewlineCommand::execute(edbee::TextEditorController *)()

________________________________________________________________________________________________________
*** CID 1446897:  Incorrect expression  (NO_EFFECT)
/home/vadi/Programs/Mudlet/mudlet/3rdparty/edbee-lib/edbee-lib/edbee/commands/newlinecommand.cpp: 178 in edbee::NewlineCommand::execute(edbee::TextEditorController *)()
172
173             case AddLineAfter:
174                 executeSpecialNewline(controller, true);
175                 break;
176
177             default:
>>>     CID 1446897:  Incorrect expression  (NO_EFFECT)
>>>     Comparing an array to null is not useful: ""Invalid newLineType!"", since the test will always evaluate as true.
178                 Q_ASSERT( false && "Invalid newLineType!");
179         }
180     }
181
182
183     /// Returns the command name

** CID 1446896:  Incorrect expression  (NO_EFFECT)
/home/vadi/Programs/Mudlet/mudlet/3rdparty/edbee-lib/edbee-lib/edbee/models/textundostack.cpp: 584 in edbee::TextUndoStack::clearRedo(edbee::TextEditorController *)()

________________________________________________________________________________________________________
*** CID 1446896:  Incorrect expression  (NO_EFFECT)
/home/vadi/Programs/Mudlet/mudlet/3rdparty/edbee-lib/edbee-lib/edbee/models/textundostack.cpp: 584 in edbee::TextUndoStack::clearRedo(edbee::TextEditorController *)()
578         // view specific undo
579         if( controller ) {
580             int idx = changeIndex_;
581             if( controllerIndexMap_.contains(controller) ) {
582                 idx = this->controllerIndexMap_.value(controller);
583             } else {
>>>     CID 1446896:  Incorrect expression  (NO_EFFECT)
>>>     Comparing an array to null is not useful: ""The current controller isn't registered with the undostack!"", since the test will always evaluate as true.
584                 Q_ASSERT(false && "The current controller isn't registered with the undostack!");    // warning view isn't registered!
585             }
586
587             // remove all items from the stack AFTER the given index
588             for( int i=changeList_.size()-1; i >= idx; --i ) {
589                 if( changeList_.at(i)->controllerContext() == controller ) {

** CID 1446895:  Incorrect expression  (DIVIDE_BY_ZERO)
/home/vadi/Programs/Mudlet/mudlet/3rdparty/edbee-lib/edbee-lib/edbee/util/simpleprofiler.cpp: 105 in edbee::SimpleProfiler::dumpResults()()

________________________________________________________________________________________________________
*** CID 1446895:  Incorrect expression  (DIVIDE_BY_ZERO)
/home/vadi/Programs/Mudlet/mudlet/3rdparty/edbee-lib/edbee-lib/edbee/util/simpleprofiler.cpp: 105 in edbee::SimpleProfiler::dumpResults()()
99                 totalDuration  += item->duration();
100                 totalCallCount += item->callCount();
101                 totalDurationWitoutChilds += item->durationWithoutChilds();
102             }
103
104             foreach( ProfilerItem* item, items ) {
>>>     CID 1446895:  Incorrect expression  (DIVIDE_BY_ZERO)
>>>     In expression "100. * item->duration() / totalDuration", division by expression "totalDuration" which may be zero has undefined behavior.
105                 double durationPercentage = 100.0 * item->duration() / totalDuration;
106                 double callCountPercentage = 100.0 * item->callCount() / totalCallCount;
107                 double durationWithoutChildsPercenage = 100.0 * item->durationWithoutChilds() / totalDurationWitoutChilds;
108
109                 QString line = QString("%1x(%2%) %3ms(%4%) %5ms(%6%) |  %7:%8 %9")
110                    .arg(item->callCount(),8).arg( callCountPercentage, 6, 'f', 2 )

** CID 1446894:  Possible Control flow issues  (DEADCODE)
/home/vadi/Programs/Mudlet/mudlet/3rdparty/edbee-lib/edbee-lib/edbee/io/jsonparser.cpp: 70 in edbee::JsonParser::parse(QIODevice *)()

________________________________________________________________________________________________________
*** CID 1446894:  Possible Control flow issues  (DEADCODE)
/home/vadi/Programs/Mudlet/mudlet/3rdparty/edbee-lib/edbee-lib/edbee/io/jsonparser.cpp: 70 in edbee::JsonParser::parse(QIODevice *)()
64                 return false;
65             }
66         }
67
68         QByteArray bytesIn = device->readAll();
69         bool result = parse( bytesIn );
>>>     CID 1446894:  Possible Control flow issues  (DEADCODE)
>>>     Execution cannot reach this statement: "device->close();".
70         if( opened ) device->close();
71         return result;
72     }
73
74
75     /// opens the given bytes as a json document

** CID 1446891:    (FORWARD_NULL)
/home/vadi/Programs/Mudlet/mudlet/3rdparty/edbee-lib/edbee-lib/edbee/models/changes/linedatalistchange.cpp: 97 in edbee::LineDataListChange::mergeStoredData(edbee::AbstractRangedChange *)()
/home/vadi/Programs/Mudlet/mudlet/3rdparty/edbee-lib/edbee-lib/edbee/models/changes/linedatalistchange.cpp: 106 in edbee::LineDataListChange::mergeStoredData(edbee::AbstractRangedChange *)()

________________________________________________________________________________________________________
*** CID 1446891:    (FORWARD_NULL)
/home/vadi/Programs/Mudlet/mudlet/3rdparty/edbee-lib/edbee-lib/edbee/models/changes/linedatalistchange.cpp: 97 in edbee::LineDataListChange::mergeStoredData(edbee::AbstractRangedChange *)()
91         LineDataListChange* lineTextChange = dynamic_cast<LineDataListChange*>(change);
92
93         // calculate the new size
94         int newOldListSize = getMergedStoredLength( change);// qlog_info() << "CALCULATED: " << newOldListSize ;
95
96         // no old data, we don't need to store anthing
>>>     CID 1446891:    (FORWARD_NULL)
>>>     Dereferencing null pointer "lineTextChange".
97         if( this->oldListList_ == 0 && lineTextChange->oldListList_ == 0 ) {
98             contentLength_ = newOldListSize;    // also store the content list
99             return;
100         }
101
102         // create the new list
/home/vadi/Programs/Mudlet/mudlet/3rdparty/edbee-lib/edbee-lib/edbee/models/changes/linedatalistchange.cpp: 106 in edbee::LineDataListChange::mergeStoredData(edbee::AbstractRangedChange *)()
100         }
101
102         // create the new list
103         TextLineDataList**  newOldListList_ = new TextLineDataList*[newOldListSize];
104
105         // merge the stuff
>>>     CID 1446891:    (FORWARD_NULL)
>>>     Dereferencing null pointer "lineTextChange".
106         mergeStoredDataViaMemcopy( newOldListList_, oldListList_, lineTextChange->oldListList_, change, sizeof(TextLineDataList*) );
107
108         // we need to delete all items that aren't used anymore
109         if( oldListList_ ) {
110             for( int i=0; i<contentLength_; ++i ) {
111                 bool found=false;

** CID 1446890:  Uninitialized members  (UNINIT_CTOR)
/home/vadi/Programs/Mudlet/mudlet/3rdparty/edbee-lib/edbee-lib/edbee/views/components/texteditorrenderer.cpp: 34 in edbee::TextEditorRenderer::TextEditorRenderer(edbee::TextRenderer *)()

________________________________________________________________________________________________________
*** CID 1446890:  Uninitialized members  (UNINIT_CTOR)
/home/vadi/Programs/Mudlet/mudlet/3rdparty/edbee-lib/edbee-lib/edbee/views/components/texteditorrenderer.cpp: 34 in edbee::TextEditorRenderer::TextEditorRenderer(edbee::TextRenderer *)()
28         , shadowGradient_(0)
29     {
30         shadowGradient_ = new QLinearGradient( 0, 0, ShadowWidth, 0 );
31         shadowGradient_ ->setColorAt(0, QColor( 0x00, 0x00, 0x00, 0x99 ));
32         shadowGradient_ ->setColorAt(1, QColor( 0x00, 0x00, 0x00, 0x00 ));
33
>>>     CID 1446890:  Uninitialized members  (UNINIT_CTOR)
>>>     Non-static class member "themeRef_" is not initialized in this constructor nor in any functions that it calls.
34     }
35
36     TextEditorRenderer::~TextEditorRenderer()
37     {
38         delete shadowGradient_;
39     }

** CID 1446888:  Uninitialized members  (UNINIT_CTOR)
/home/vadi/Programs/Mudlet/mudlet/3rdparty/edbee-lib/edbee-lib/edbee/views/textrenderer.cpp: 44 in edbee::TextRenderer::TextRenderer(edbee::TextEditorController *)()

________________________________________________________________________________________________________
*** CID 1446888:  Uninitialized members  (UNINIT_CTOR)
/home/vadi/Programs/Mudlet/mudlet/3rdparty/edbee-lib/edbee-lib/edbee/views/textrenderer.cpp: 44 in edbee::TextRenderer::TextRenderer(edbee::TextEditorController *)()
38         , totalWidthCache_(0)
39         , textThemeStyler_(0)
40         , clipRectRef_(0)
41     {
42         connect( controller, SIGNAL(textDocumentChanged(edbee::TextDocument*,edbee::TextDocument*)), this, SLOT(textDocumentChanged(edbee::TextDocument*,edbee::TextDocument*)));
43         textThemeStyler_ = new TextThemeStyler( controller );
>>>     CID 1446888:  Uninitialized members  (UNINIT_CTOR)
>>>     Non-static class member "endLine_" is not initialized in this constructor nor in any functions that it calls.
44     }
45
46
47     /// the destructor
48     TextRenderer::~TextRenderer()
49     {
gamecreature commented 7 years ago

Thanks for the info! I will check it out

gamecreature commented 7 years ago

I just fixed some small an probably some big issues.. (Strange delete[] call, opened-flag that wasn't set) thanks to your report! Thanks!!

I'm trying to configure coverity for my app, but I need to disable SIP protection on my Mac for it. (Which is something I don't want to do).

When I've find some time, I will try to configure it for my Ubuntu VM.

vadi2 commented 7 years ago

As I've got it all setup, I'm happy to do the upload for you - just add me as a member to the project.

On Wed, 28 Jun 2017 7:55 am Rick Blommers, notifications@github.com wrote:

I just fixed some small an probably some big issues.. (String delete[] call, opened-flag that wasn't set) thanks to your report! Thanks!!

I'm trying to configure coverity for my app, but I need to disable SIP protection on my Mac for it. (Which is something I don't want to do).

When I've find some time, I will try to configure it for my Ubuntu VM.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/edbee/edbee-lib/issues/35#issuecomment-311563739, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGxjI1Wfwnyljja9KmIPDGyHk0-_nP4ks5sIerpgaJpZM4OE3hj .

vadi2 commented 7 years ago

Sorry, added in the Coverity project - my email is vperetokin on gmail

On Wed, 28 Jun 2017 8:08 am Vadim Peretokin, vperetokin@gmail.com wrote:

As I've got it all setup, I'm happy to do the upload for you - just add me as a member to the project.

On Wed, 28 Jun 2017 7:55 am Rick Blommers, notifications@github.com wrote:

I just fixed some small an probably some big issues.. (String delete[] call, opened-flag that wasn't set) thanks to your report! Thanks!!

I'm trying to configure coverity for my app, but I need to disable SIP protection on my Mac for it. (Which is something I don't want to do).

When I've find some time, I will try to configure it for my Ubuntu VM.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/edbee/edbee-lib/issues/35#issuecomment-311563739, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGxjI1Wfwnyljja9KmIPDGyHk0-_nP4ks5sIerpgaJpZM4OE3hj .

vadi2 commented 7 years ago

Got it - waiting on Coverity to approve edbee-lib as an OSS project and then I'll be able to upload:

workspace 1_157

vadi2 commented 7 years ago

Is there an issue with getting approval? I'm still not able to access the project.

gamecreature commented 7 years ago

I don't know. I guess I must upload a project scan first... But I haven't made a scan yet..

vadi2 commented 7 years ago

OK, I'll generate one for you.

vadi2 commented 7 years ago

Here you go, upload this: https://transfer.sh/3l0bF/edbee-lig.xz

gamecreature commented 7 years ago

Thanks you very much! I just submitted the build!

vadi2 commented 7 years ago

Nice! Looks like the scan worked, I see the defect numbers are filled in - now they just need to approve it as an OSS project.

gamecreature commented 7 years ago

Yes! I will wait 2 workdays. If that doesn't work I'm going to send them an email..

vadi2 commented 7 years ago

@gamecreature looks like the results are available now!

gamecreature commented 7 years ago

Yeah, I found them. I just solved/resolved some coverity issues.

vadi2 commented 7 years ago

:+1: awesome. I'll leave you to it.

Would you like me to re-upload for a new scan?