File tree Expand file tree Collapse file tree 4 files changed +38
-10
lines changed
Expand file tree Collapse file tree 4 files changed +38
-10
lines changed Original file line number Diff line number Diff line change @@ -641,23 +641,24 @@ void StdLogger::reportErr(const ErrorMessage &msg)
641641 if (msg.severity == Severity::internal)
642642 return ;
643643
644- // TODO: we generate a different message here then we log below
645- // TODO: there should be no need for verbose and default messages here
646- // Alert only about unique errors
647- if (!mSettings .emitDuplicates && !mShownErrors .insert (msg.toString (mSettings .verbose )).second )
648- return ;
649-
650644 ErrorMessage msgCopy = msg;
651645 msgCopy.guideline = getGuideline (msgCopy.id , mSettings .reportType ,
652646 mGuidelineMapping , msgCopy.severity );
653647 msgCopy.classification = getClassification (msgCopy.guideline , mSettings .reportType );
654648
649+ // TODO: there should be no need for verbose and default messages here
650+ const std::string msgStr = msgCopy.toString (mSettings .verbose , mSettings .templateFormat , mSettings .templateLocation );
651+
652+ // Alert only about unique errors
653+ if (!mSettings .emitDuplicates && !mShownErrors .insert (msgStr).second )
654+ return ;
655+
655656 if (mSettings .outputFormat == Settings::OutputFormat::sarif)
656657 mSarifReport .addFinding (msgCopy);
657658 else if (mSettings .outputFormat == Settings::OutputFormat::xml)
658659 reportErr (msgCopy.toXML ());
659660 else
660- reportErr (msgCopy. toString ( mSettings . verbose , mSettings . templateFormat , mSettings . templateLocation ) );
661+ reportErr (msgStr );
661662}
662663
663664/* *
Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ bool Executor::hasToLog(const ErrorMessage &msg)
4646 if (!mSuppressions .nomsg .isSuppressed (msg, {}))
4747 {
4848 // TODO: there should be no need for verbose and default messages here
49- std::string errmsg = msg.toString (mSettings .verbose );
49+ std::string errmsg = msg.toString (mSettings .verbose , mSettings . templateFormat , mSettings . templateLocation );
5050 if (errmsg.empty ())
5151 return false ;
5252
Original file line number Diff line number Diff line change @@ -203,7 +203,7 @@ class CppCheck::CppCheckLogger : public ErrorLogger
203203 }
204204
205205 // TODO: there should be no need for the verbose and default messages here
206- std::string errmsg = msg.toString (mSettings .verbose );
206+ std::string errmsg = msg.toString (mSettings .verbose , mSettings . templateFormat , mSettings . templateLocation );
207207 if (errmsg.empty ())
208208 return ;
209209
Original file line number Diff line number Diff line change @@ -3160,4 +3160,31 @@ def test_debug_valueflow_xml(tmp_path): # #13606
31603160 assert 'floatvalue' in value_elem [1 ].attrib
31613161 assert value_elem [1 ].attrib ['floatvalue' ] == '1e-07'
31623162 assert 'floatvalue' in value_elem [2 ].attrib
3163- assert value_elem [2 ].attrib ['floatvalue' ] == '1e-07'
3163+ assert value_elem [2 ].attrib ['floatvalue' ] == '1e-07'
3164+
3165+
3166+ def test_unique_error (tmp_path ): # #6366
3167+ test_file = tmp_path / 'test.c'
3168+ with open (test_file , 'wt' ) as f :
3169+ f .write (
3170+ """void f()
3171+ {
3172+ const long m[9] = {};
3173+ long a=m[9], b=m[9];
3174+ (void)a;
3175+ (void)b;
3176+ }
3177+ """ )
3178+
3179+ args = [
3180+ '-q' ,
3181+ '--template=simple' ,
3182+ str (test_file )
3183+ ]
3184+ exitcode , stdout , stderr = cppcheck (args )
3185+ assert exitcode == 0 , stdout
3186+ assert stdout .splitlines () == []
3187+ assert stderr .splitlines () == [
3188+ "{}:4:13: error: Array 'm[9]' accessed at index 9, which is out of bounds. [arrayIndexOutOfBounds]" .format (test_file ),
3189+ "{}:4:21: error: Array 'm[9]' accessed at index 9, which is out of bounds. [arrayIndexOutOfBounds]" .format (test_file )
3190+ ]
You can’t perform that action at this time.
0 commit comments