Skip to content

Commit

Permalink
clang-tidy fixes, typo fixes, more readable code
Browse files Browse the repository at this point in the history
	... , no functional changes* (expect all output equal to output from last commit, which is `HEAD~1`).
	[*The fix for `produceAssistantCns` changes `assistantCns.neuronsPerLayer` from `26666` to `maxWidthOfMessages`, but `assistantCns` is for future use.]

?`build.sh`:
  `CXXFLAGS_ANALYSIS`: -`-Wno-unused`, +`-Wno-unused-function`, +`-Wppedantic`. Is for issue #27 (more close to `-Werror` support).
  Is followup to: 64ca540 (?build.sh:+CXX_FLAGS_ANALYSIS="-Wall ...)

?`cxx/main.hxx`:
	?`susuwuUnitTestsClassResultListBit`: `:%s/Sys/ResultList/`; comment fix.
	Is followup to: 2e01c08 (+`cxx/ClassResultList.cxx`: +`classResultListTests` ... +`susuwuUnitTestsClassResultListTestsBit`), which introduced the comment (plus `susuwuUnitTestsClassResultListBit`).

?`cxx/ClassResultList.hxx`:
	?`listProduceSignature()`: mismatched '{' (in comment) fix.
	Is followup to: commit 30521ed (... ?listProduceSignature() ...), which mismatched that.

?`cxx/ClassSys.hxx`:
	"warning: #includes are not sorted properly [llvm-include-order]" fix.
	Is followup to d50262f (+`classSysGetOwnPath()`, +`classSysFopenOwnPath()`), which triggered the diagnostic.

?`cxx/AssistantCns.hxx`:
	"warning: #includes are not sorted properly [llvm-include-order]" fix.
	Is followup to d3dd3e3 (?cxx/ClassSys.hxx:templateMatchAll Print funcName), which triggered the diagnostic.

?`cxx/AssistantCns.cxx`:
	Remove `execvex` from `#include ClassCns.hxx` comment. Is followup to 69e3329 (+cxx/ClassSys.{h,c}xx +`execves` +`execvex`), which moved `execvex` into `ClassSys.hxx`.
	?`assistantCnsProcessXhtml`: "string concatenation results in allocation of unnecessary temporary strings; consider using 'operator+=' or 'string::append()' instead [performance-inefficient-string-concatenation]" fix.
	?`produceAssistantCns`: "warning: 26666 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers]" fix. Is followup to f5a7a37 (...`cxx/VirusAnalysis.cxx`: ... `warning: 26666 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers]` fix), which should have fixed `produceAssistantCns` too.

?`cxx/VirusAnalysis.cxx`:
	?`produceAbortListSignatures`: more readable; don't use raw `std::get<0>(tuple)`.

?`posts/VirusAnalysis.md`: Include all this.
  • Loading branch information
SwuduSusuwu committed Nov 23, 2024
1 parent af5226c commit b8023f3
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 23 deletions.
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
SUSUWU_PRINT "${SUSUWU_SH_NOTICE}" "Dual licenses: choose \"Creative Commons\" or \"Apache 2\" (allows all uses)."

CXXFLAGS_SPECIAL="" #/* You can put special flags from `build.sh` into this to use. */
CXXFLAGS_ANALYSIS="-Wall -Wno-unused -Wno-unused-function -Wextra -Wno-unused-parameter -Wno-ignored-qualifiers" #/*TODO: -`-Wno-*`, +`-Wpedantic`, +`-Werror` */
CXXFLAGS_ANALYSIS="-Wall -Wno-unused-function -Wno-unused-function -Wextra -Wno-unused-parameter -Wno-ignored-qualifiers -Wpedantic" #/*TODO: -`-Wno-*`, +`-Werror` */
CXXFLAGS_RELEASE="-fomit-frame-pointer -DNDEBUG -O2" #/* without frame pointer (pointer used for stacktraces), without `assert(...)`/`SUSUWU_DEBUG(...)`/`SUSUWU_NOTICE(...)`, with optimization level 2 */
CXXFLAGS_DEBUG="-std=c++11 -g -Og" #/* in MSVC is `/Zi /Od`: symbols for `gdb`/`lldb` use, optimizations compatible with `-g`/`-fsan*` */
CXXFLAGS_DEBUG="-g -Og" #/* in MSVC is `/Zi /Od`: symbols for `gdb`/`lldb` use, optimizations compatible with `-g`/`-fsan*` */
Expand Down
16 changes: 10 additions & 6 deletions cxx/AssistantCns.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#ifndef INCLUDES_cxx_AssistantCns_cxx
#define INCLUDES_cxx_AssistantCns_cxx
#include "AssistantCns.hxx" /* assistantCnsProcessQuestion assistantCnsProcessResponses assistantCnsProcessUrls */
#include "ClassCns.hxx" /* Cns CnsMode execvex */
#include "ClassCns.hxx" /* Cns CnsMode */
#include "ClassPortableExecutable.hxx" /* FileBytecode FilePath */
#include "ClassResultList.hxx" /* explodeToList listMaxSize listHasValue ResultList ResultListBytecode resultListDumpTo resultListProduceHashes */
#include "ClassSha2.hxx" /* classSha2 */
Expand Down Expand Up @@ -55,12 +55,16 @@ const bool assistantCnsTests() {
}
void produceAssistantCns(const ResultList &questionsOrNull, const ResultList &responsesOrNull, Cns &cns) {
std::vector<std::tuple<ResultListBytecode, ResultListBytecode>> inputsToOutputs;
const size_t maxConvolutionsOfMessages = 6666; /* is not conversation's max message count, but max steps to compute output. TODO: compute this value */
const size_t maxResponseSize = listMaxSize(responsesOrNull.bytecodes);
const size_t maxQuestionSize = listMaxSize(questionsOrNull.bytecodes);
const size_t maxWidthOfMessages = (maxResponseSize > maxQuestionSize) ? maxResponseSize : maxQuestionSize;
cns.setInputMode(cnsModeString);
cns.setOutputMode(cnsModeString);
cns.setInputNeurons(listMaxSize(questionsOrNull.bytecodes));
cns.setOutputNeurons(listMaxSize(responsesOrNull.bytecodes));
cns.setLayersOfNeurons(6666);
cns.setNeuronsPerLayer(26666);
cns.setInputNeurons(maxQuestionSize);
cns.setOutputNeurons(maxResponseSize);
cns.setLayersOfNeurons(maxConvolutionsOfMessages);
cns.setNeuronsPerLayer(maxWidthOfMessages /* TODO: reduce this */);
assert(questionsOrNull.bytecodes.size() == questionsOrNull.bytecodes.size());
inputsToOutputs.reserve(questionsOrNull.bytecodes.size());
for(size_t x = 0; questionsOrNull.bytecodes.size() > x; ++x) {
Expand Down Expand Up @@ -106,7 +110,7 @@ void assistantCnsProcessXhtml(ResultList &questionsOrNull, ResultList &responses
auto urls = assistantCnsProcessUrls(localXhtml);
for(const auto &url : urls) {
if(!listHasValue(questionsOrNull.signatures, url) && !listHasValue(noRobots, url)) {
execvex("wget '" + url + "' -O" + localXhtml);
execvex("wget '" + url + "' -O" += localXhtml);
questionsOrNull.signatures.push_back(url);
assistantCnsProcessXhtml(questionsOrNull, responsesOrNull, localXhtml);
}
Expand Down
2 changes: 1 addition & 1 deletion cxx/AssistantCns.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#ifndef INCLUDES_cxx_AssistantCns_hxx
#define INCLUDES_cxx_AssistantCns_hxx
#include "ClassCns.hxx" /* Cns CnsMode */
#include "ClassSys.hxx" /* templateCatchAll */
#include "ClassPortableExecutable.hxx" /* FilePath FileBytecode */
#include "ClassResultList.hxx" /* ResultList */
#include "ClassSys.hxx" /* templateCatchAll */
#include "Macros.hxx" /* SUSUWU_NOEXCEPT */
#include <iostream> /* std::cout */
#include <ostream> /* std::ostream */
Expand Down
2 changes: 1 addition & 1 deletion cxx/ClassResultList.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ const bool listHasSubstr(const List &list, typename List::value_type::const_iter
}
template<class List>
/* Returns shortest substr from `value`, which is not found in `list`
* Usage: `resultList.signatures.push_back({listProduceSignature(resultList.bytecodes, bytecode));` */
* Usage: `auto tuple = listProduceSignature(resultList.bytecodes, bytecode); resultList.signatures.push_back({std::get<0>(tuple), std::get<1>(tuple)});` */
const std::tuple<typename List::value_type::const_iterator, typename List::value_type::const_iterator> listProduceSignature(const List &list, const typename List::value_type &value) {
ptrdiff_t smallest = value.size();
auto itBegin = value.cbegin(), itEnd = value.cend();
Expand Down
2 changes: 1 addition & 1 deletion cxx/ClassSys.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include "ClassPortableExecutable.hxx" /* FilePath */
#include "Macros.hxx" /* IF_SUSUWU_CPLUSPLUS, SUSUWU_ERROR SUSUWU_NOEXCEPT SUSUWU_POSIX */
#include <cassert> /* assert */
#include IF_SUSUWU_CPLUSPLUS(<cstdio>, <stdio.h>) /* FILE fopen */
#include <chrono> /* std::chrono */
#include IF_SUSUWU_CPLUSPLUS(<cstdio>, <stdio.h>) /* FILE fopen */
#include <exception> /* std::exception */
#include <iomanip> /* std::dec std::hex */
#include <ios> /* std::streamsize */
Expand Down
7 changes: 4 additions & 3 deletions cxx/VirusAnalysis.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,10 @@ const VirusAnalysisResult signatureAnalysis(const PortableExecutable &file, cons
void produceAbortListSignatures(const ResultList &passList, ResultList &abortList) {
abortList.signatures.reserve(abortList.bytecodes.size());
for(const auto &file : abortList.bytecodes) {
auto tuple = listProduceSignature(passList.bytecodes, file);
if(std::get<0>(tuple) < std::get<1>(tuple)) { /* require `(0 < ResultListSignature.size())` to prevent crashes */
abortList.signatures.push_back(ResultListSignature(std::get<0>(tuple), std::get<1>(tuple)));
const auto tuple = listProduceSignature(passList.bytecodes, file);
const auto itBegin = std::get<0>(tuple), itEnd = std::get<1>(tuple);
if(itBegin < itEnd) { /* require `(0 < ResultListSignature.size())` to prevent crashes */
abortList.signatures.push_back(ResultListSignature(itBegin, itEnd));
}
} /* The most simple signature is a substring, but some analyses use regexes. */
}
Expand Down
2 changes: 1 addition & 1 deletion cxx/main.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ static const int susuwuUnitTestsMacrosBit = 1 << 0; /* 1: `Macros.hxx`
static const int susuwuUnitTestsConsoleBit = 1 << 1; /* 2: `classSys.hxx`:`classSysSetConsoleInput()` */
static const int susuwuUnitTestsClassSysBit = 1 << 2; /* 4: `ClassSys.hxx`:`classSysTestsNoexcept()` */
static const int susuwuUnitTestsClassSha2Bit = 1 << 3; /* 8: `ClassSha2.hxx`:`classSha2TestsNoexcept()` */
static const int susuwuUnitTestsClassResultListBit = 1 << 4; /* 16: `ClassSys.hxx`:`classSysTestsNoexcept()` */
static const int susuwuUnitTestsClassResultListBit = 1 << 4; /* 16: `ClassResultList.hxx`:`classResultListTestsNoexcept()` */
static const int susuwuUnitTestsVirusAnalysisBit = 1 << 5; /* 32: `VirusAnalysis.hxx`:`virusAnalysisTestsNoexcept()` */
static const int susuwuUnitTestsAssistantCnsBit = 1 << 6; /* 64: `AssistantCns.hxx`:`assistantCnsTestsNoexcept()` */
/* `clang-tidy` on: NOLINTEND(hicpp-signed-bitwise) */
Expand Down
23 changes: 14 additions & 9 deletions posts/VirusAnalysis.md
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ const bool listHasSubstr(const List &list, typename List::value_type::const_iter
}
template<class List>
/* Returns shortest substr from `value`, which is not found in `list`
* Usage: `resultList.signatures.push_back({listProduceSignature(resultList.bytecodes, bytecode));` */
* Usage: `auto tuple = listProduceSignature(resultList.bytecodes, bytecode); resultList.signatures.push_back({std::get<0>(tuple), std::get<1>(tuple)});` */
const std::tuple<typename List::value_type::const_iterator, typename List::value_type::const_iterator> listProduceSignature(const List &list, const typename List::value_type &value) {
ptrdiff_t smallest = value.size();
auto itBegin = value.cbegin(), itEnd = value.cend();
Expand Down Expand Up @@ -1479,9 +1479,10 @@ const VirusAnalysisResult signatureAnalysis(const PortableExecutable &file, cons
void produceAbortListSignatures(const ResultList &passList, ResultList &abortList) {
abortList.signatures.reserve(abortList.bytecodes.size());
for(const auto &file : abortList.bytecodes) {
auto tuple = listProduceSignature(passList.bytecodes, file);
if(std::get<0>(tuple) < std::get<1>(tuple)) { /* require `(0 < ResultListSignature.size())` to prevent crashes */
abortList.signatures.push_back(ResultListSignature(std::get<0>(tuple), std::get<1>(tuple)));
const auto tuple = listProduceSignature(passList.bytecodes, file);
const auto itBegin = std::get<0>(tuple), itEnd = std::get<1>(tuple);
if(itBegin < itEnd) { /* require `(0 < ResultListSignature.size())` to prevent crashes */
abortList.signatures.push_back(ResultListSignature(itBegin, itEnd));
}
} /* The most simple signature is a substring, but some analyses use regexes. */
}
Expand Down Expand Up @@ -1635,7 +1636,7 @@ static const int susuwuUnitTestsMacrosBit = 1 << 0; /* 1: `Macros.hxx`
static const int susuwuUnitTestsConsoleBit = 1 << 1; /* 2: `classSys.hxx`:`classSysSetConsoleInput()` */
static const int susuwuUnitTestsClassSysBit = 1 << 2; /* 4: `ClassSys.hxx`:`classSysTestsNoexcept()` */
static const int susuwuUnitTestsClassSha2Bit = 1 << 3; /* 8: `ClassSha2.hxx`:`classSha2TestsNoexcept()` */
static const int susuwuUnitTestsClassResultListBit = 1 << 4; /* 16: `ClassSys.hxx`:`classSysTestsNoexcept()` */
static const int susuwuUnitTestsClassResultListBit = 1 << 4; /* 16: `ClassResultList.hxx`:`classResultListTestsNoexcept()` */
static const int susuwuUnitTestsVirusAnalysisBit = 1 << 5; /* 32: `VirusAnalysis.hxx`:`virusAnalysisTestsNoexcept()` */
static const int susuwuUnitTestsAssistantCnsBit = 1 << 6; /* 64: `AssistantCns.hxx`:`assistantCnsTestsNoexcept()` */
const SusuwuUnitTestsBitmask susuwuUnitTests();
Expand Down Expand Up @@ -1808,12 +1809,16 @@ const bool assistantCnsTests() {
}
void produceAssistantCns(const ResultList &questionsOrNull, const ResultList &responsesOrNull, Cns &cns) {
std::vector<std::tuple<ResultListBytecode, ResultListBytecode>> inputsToOutputs;
const size_t maxConvolutionsOfMessages = 6666; /* is not conversation's max message count, but max steps to compute output. TODO: compute this value */
const size_t maxResponseSize = listMaxSize(responsesOrNull.bytecodes);
const size_t maxQuestionSize = listMaxSize(questionsOrNull.bytecodes);
const size_t maxWidthOfMessages = (maxResponseSize > maxQuestionSize) ? maxResponseSize : maxQuestionSize;
cns.setInputMode(cnsModeString);
cns.setOutputMode(cnsModeString);
cns.setInputNeurons(listMaxSize(questionsOrNull.bytecodes));
cns.setOutputNeurons(listMaxSize(responsesOrNull.bytecodes));
cns.setLayersOfNeurons(6666);
cns.setNeuronsPerLayer(26666);
cns.setInputNeurons(maxQuestionSize);
cns.setOutputNeurons(maxResponseSize);
cns.setLayersOfNeurons(maxConvolutionsOfMessages);
cns.setNeuronsPerLayer(maxWidthOfMessages /* TODO: reduce this */);
assert(questionsOrNull.bytecodes.size() == questionsOrNull.bytecodes.size());
inputsToOutputs.reserve(questionsOrNull.bytecodes.size());
for(size_t x = 0; questionsOrNull.bytecodes.size() > x; ++x) {
Expand Down

0 comments on commit b8023f3

Please sign in to comment.