diff --git a/output.cc b/output.cc index 75b636c96..d045b74f6 100644 --- a/output.cc +++ b/output.cc @@ -785,7 +785,8 @@ void printportoutput(Target *currenths, PortList *plist) { #ifndef NOLUA if (o.script) { ScriptResults::const_iterator ssr_iter; - + //Sort the results before outputing them on the screen + current->scriptResults.sort(comparescriptids); for (ssr_iter = current->scriptResults.begin(); ssr_iter != current->scriptResults.end(); ssr_iter++) { xml_open_start_tag("script"); @@ -2165,7 +2166,9 @@ void printscriptresults(ScriptResults *scriptResults, stype scantype) { char *script_output; if (scriptResults->size() > 0) { - if (scantype == SCRIPT_PRE_SCAN) { + // No sense sorting if we don't need too + scriptResults->sort(comparescriptids); + if (scantype == SCRIPT_PRE_SCAN) { xml_start_tag("prescript"); log_write(LOG_PLAIN, "Pre-scan script results:\n"); } @@ -2194,6 +2197,8 @@ void printhostscriptresults(Target *currenths) { char *script_output; if (currenths->scriptResults.size() > 0) { + //no point sorting an empty list + currenths->scriptResults.sort(comparescriptids); xml_start_tag("hostscript"); log_write(LOG_PLAIN, "\nHost script results:\n"); for (iter = currenths->scriptResults.begin(); @@ -2603,3 +2608,18 @@ void printdatafilepaths() { } } } + +/*This is a helper function to determine the ordering of the script results + based on their id */ +bool comparescriptids(ScriptResult first, ScriptResult second){ + //Pull the two id fields out for comparison + std::string firstid(first.get_id()); + std::string secondid(second.get_id()); + + if (firstid < secondid) + return true; + else + return false; +} + + diff --git a/output.h b/output.h index 4747b8381..2f45a54f7 100644 --- a/output.h +++ b/output.h @@ -251,4 +251,8 @@ void printfinaloutput(); were found. */ void printdatafilepaths(); +/*This is a helper function to determine the ordering of the script results + based on their id */ +bool comparescriptids(ScriptResult first, ScriptResult second); + #endif /* OUTPUT_H */