Skip to content

Commit

Permalink
Use a stricter clang-tidy config, retire clang-analyze
Browse files Browse the repository at this point in the history
  • Loading branch information
attah committed Dec 15, 2024
1 parent 92dc020 commit 9cbad23
Show file tree
Hide file tree
Showing 35 changed files with 284 additions and 258 deletions.
3 changes: 3 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Checks: 'clang-analyzer-*,bugprone-*,performance-*,readability-*,modernize-*,-bugprone-easily-swappable-parameters,-bugprone-assignment-in-if-condition,-bugprone-narrowing-conversions,-bugprone-implicit-widening-of-multiplication-result,-bugprone-branch-clone,-bugprone-string-literal-with-embedded-nul,-bugprone-macro-parentheses,-bugprone-exception-escape,-performance-avoid-endl,-readability-identifier-length,-readability-named-parameter,-readability-implicit-bool-conversion,-readability-magic-numbers,-readability-else-after-return,-readability-function-cognitive-complexity,-readability-avoid-nested-conditional-operator,-readability-convert-member-functions-to-static,-readability-container-size-empty,-readability-use-anyofallof,-modernize-use-trailing-return-type,-modernize-use-auto,-modernize-return-braced-init-list'
WarningsAsErrors: '*'
FormatStyle: 'file'
2 changes: 0 additions & 2 deletions .github/workflows/ccpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,5 @@ jobs:
- name: test
run: ./test
working-directory: ./tests
- name: analyze
run: make analyze
- name: tidy
run: make tidy
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ ippdiscover: ippdiscover.o ippdiscovery.o bytestream.o
clean:
rm -f *.o $(OFFICIAL) $(EXTRAS)

analyze:
$(CLANGXX) --analyze $(CXXFLAGS) $(SILLY_CLANG_FLAGS) lib/*.cpp utils/*.cpp

tidy:
$(CLANG_TIDY) lib/*.cpp utils/*.cpp -- $(CXXFLAGS)

Expand Down
2 changes: 1 addition & 1 deletion bytestream
7 changes: 4 additions & 3 deletions lib/baselinify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct bts_source_mgr: jpeg_source_mgr
jpeg_source_mgr::skip_input_data = skip_input_data;
jpeg_source_mgr::resync_to_restart = jpeg_resync_to_restart;
jpeg_source_mgr::term_source = term_source;
jpeg_source_mgr::bytes_in_buffer = (size_t)bts.size();
jpeg_source_mgr::bytes_in_buffer = bts.size();
jpeg_source_mgr::next_input_byte = (const JOCTET *)bts.raw();
}

Expand Down Expand Up @@ -73,15 +73,16 @@ struct bts_destination_mgr: jpeg_destination_mgr
dest->bts.putBytes(dest->buffer, size);
}

JOCTET buffer[BS_REASONABLE_FILE_SIZE];
Array<JOCTET> buffer = Array<JOCTET>(BS_REASONABLE_FILE_SIZE);
Bytestream& bts;
};

void baselinify(Bytestream& inBts, Bytestream& outBts)
{
struct jpeg_decompress_struct srcInfo;
struct jpeg_compress_struct dstInfo;
struct jpeg_error_mgr jSrcErr, jDstErr;
struct jpeg_error_mgr jSrcErr;
struct jpeg_error_mgr jDstErr;
jvirt_barray_ptr* coefArrays;

#if MADNESS
Expand Down
14 changes: 7 additions & 7 deletions lib/curlrequester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <cstring>
#include <thread>

CurlRequester::CurlRequester(std::string addr, bool ignoreSslErrors)
CurlRequester::CurlRequester(const std::string& addr, bool ignoreSslErrors)
: _curl(curl_easy_init())
{
curl_easy_setopt(_curl, CURLOPT_URL, addr.c_str());
Expand All @@ -21,7 +21,7 @@ CurlRequester::CurlRequester(std::string addr, bool ignoreSslErrors)
curl_easy_setopt(_curl, CURLOPT_SSL_VERIFYSTATUS, 0L);
}

_opts = NULL;
_opts = nullptr;
#ifdef USER_AGENT
_opts = curl_slist_append(_opts, "User-Agent: " USER_AGENT);
#endif
Expand Down Expand Up @@ -156,7 +156,7 @@ void CurlIppPosterBase::setCompression(Compression compression)
deflateInit2(&_zstrm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, level, 7, Z_DEFAULT_STRATEGY);
}

std::string http_url(std::string str)
std::string http_url(const std::string& str)
{
Url url(str);
if(url.getScheme() == "ipp")
Expand All @@ -178,7 +178,7 @@ std::string http_url(std::string str)
return url.toStr();
}

CurlIppPosterBase::CurlIppPosterBase(std::string addr, bool ignoreSslErrors)
CurlIppPosterBase::CurlIppPosterBase(const std::string& addr, bool ignoreSslErrors)
: CurlRequester(http_url(addr), ignoreSslErrors)
{
_canWrite.unlock();
Expand Down Expand Up @@ -207,22 +207,22 @@ CURLcode CurlIppPosterBase::await(Bytestream* data)
return CurlRequester::await(data);
}

CurlIppPoster::CurlIppPoster(std::string addr, Bytestream&& data, bool ignoreSslErrors)
CurlIppPoster::CurlIppPoster(const std::string& addr, Bytestream&& data, bool ignoreSslErrors)
: CurlIppPosterBase(addr, ignoreSslErrors)
{
curl_easy_setopt(_curl, CURLOPT_POSTFIELDSIZE, data.size());
write(std::move(data));
doRun();
}

CurlIppStreamer::CurlIppStreamer(std::string addr, bool ignoreSslErrors)
CurlIppStreamer::CurlIppStreamer(const std::string& addr, bool ignoreSslErrors)
: CurlIppPosterBase(addr, ignoreSslErrors)
{
_opts = curl_slist_append(_opts, "Transfer-Encoding: chunked");
doRun();
}

CurlHttpGetter::CurlHttpGetter(std::string addr, bool ignoreSslErrors)
CurlHttpGetter::CurlHttpGetter(const std::string& addr, bool ignoreSslErrors)
: CurlRequester(addr, ignoreSslErrors)
{
doRun();
Expand Down
10 changes: 5 additions & 5 deletions lib/curlrequester.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class CurlRequester

protected:

CurlRequester(std::string addr, bool ignoreSslErrors);
CurlRequester(const std::string& addr, bool ignoreSslErrors);

void doRun();

Expand Down Expand Up @@ -94,7 +94,7 @@ class CurlIppPosterBase : public CurlRequester
}

protected:
CurlIppPosterBase(std::string addr, bool ignoreSslErrors);
CurlIppPosterBase(const std::string& addr, bool ignoreSslErrors);

private:
std::mutex _canWrite;
Expand All @@ -106,19 +106,19 @@ class CurlIppPosterBase : public CurlRequester
class CurlIppPoster : public CurlIppPosterBase
{
public:
CurlIppPoster(std::string addr, Bytestream&& data, bool ignoreSslErrors = false);
CurlIppPoster(const std::string& addr, Bytestream&& data, bool ignoreSslErrors = false);
};

class CurlIppStreamer : public CurlIppPosterBase
{
public:
CurlIppStreamer(std::string addr, bool ignoreSslErrors = false);
CurlIppStreamer(const std::string& addr, bool ignoreSslErrors = false);
};

class CurlHttpGetter : public CurlRequester
{
public:
CurlHttpGetter(std::string addr, bool ignoreSslErrors = false);
CurlHttpGetter(const std::string& addr, bool ignoreSslErrors = false);
};

#endif // CURLREQUESTER_H
18 changes: 9 additions & 9 deletions lib/ippattr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ std::string IppIntRange::toStr() const
return ss.str();
}

IppIntRange IppIntRange::fromJSON(const Json::object json)
IppIntRange IppIntRange::fromJSON(const Json::object& json)
{
return IppIntRange {json.at("low").int_value(), json.at("high").int_value()};
}
Expand All @@ -41,7 +41,7 @@ std::string IppResolution::toStr() const
return ss.str();
}

IppResolution IppResolution::fromJSON(const Json::object json)
IppResolution IppResolution::fromJSON(const Json::object& json)
{
return IppResolution {(uint32_t)json.at("x").int_value(),
(uint32_t)json.at("y").int_value(),
Expand Down Expand Up @@ -80,7 +80,7 @@ std::string IppDateTime::toStr() const
return ss.str();
}

IppDateTime IppDateTime::fromJSON(const Json::object)
IppDateTime IppDateTime::fromJSON(const Json::object&)
{
// TODO
return IppDateTime();
Expand All @@ -103,7 +103,7 @@ IppOneSetOf IppAttr::asList() const
}
}

IppAttr IppAttr::fromString(std::string string, IppTag tag)
IppAttr IppAttr::fromString(const std::string& string, IppTag tag)
{
switch(tag)
{
Expand Down Expand Up @@ -157,7 +157,7 @@ IppAttr IppAttr::fromString(std::string string, IppTag tag)
}
}

IppAttr IppAttr::fromJSON(Json::object json)
IppAttr IppAttr::fromJSON(const Json::object& json)
{
IppTag tag = (IppTag)json.at("tag").int_value();
return IppAttr(tag, valuefromJSON(tag, json.at("value")));
Expand Down Expand Up @@ -218,7 +218,7 @@ IppValue IppAttr::valuefromJSON(IppTag tag, const Json& json)
}
}

Json IppAttr::valueToJSON(IppValue value)
Json IppAttr::valueToJSON(const IppValue& value)
{
Json j;
if(value.is<std::string>())
Expand Down Expand Up @@ -317,17 +317,17 @@ std::ostream& operator<<(std::ostream& os, const IppValue& iv)
return os;
}

bool IppCollection::has(std::string key) const
bool IppCollection::has(const std::string& key) const
{
return find(key) != end();
}

void IppCollection::set(std::string key, IppAttr value)
void IppCollection::set(const std::string& key, IppAttr value)
{
insert_or_assign(key, value);
}

IppAttrs IppAttrs::fromJSON(Json::object json)
IppAttrs IppAttrs::fromJSON(const Json::object& json)
{
IppAttrs attrs;
for(const auto& [key, value] : json)
Expand Down
24 changes: 12 additions & 12 deletions lib/ippattr.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ struct IppIntRange

bool operator==(const IppIntRange& other) const;
std::string toStr() const;
static IppIntRange fromJSON(const Json::object json);
static IppIntRange fromJSON(const Json::object& json);
Json::object toJSON() const;
};

Expand All @@ -74,7 +74,7 @@ struct IppResolution

bool operator==(const IppResolution& other) const;
std::string toStr() const;
static IppResolution fromJSON(const Json::object json);
static IppResolution fromJSON(const Json::object& json);
Json::object toJSON() const;
};

Expand All @@ -93,7 +93,7 @@ struct IppDateTime

bool operator==(const IppDateTime& other) const;
std::string toStr() const;
static IppDateTime fromJSON(const Json::object json);
static IppDateTime fromJSON(const Json::object& json);
Json toJSON() const;
};

Expand All @@ -109,8 +109,8 @@ struct IppOneSetOf: public List<IppValue>
struct IppCollection: public std::map<std::string, IppAttr>
{
using std::map<std::string, IppAttr>::map;
bool has(std::string key) const;
void set(std::string key, IppAttr value);
bool has(const std::string& key) const;
void set(const std::string& key, IppAttr value);
};

class IppAttr : public IppValue
Expand All @@ -124,14 +124,14 @@ class IppAttr : public IppValue

IppTag tag() const {return _tag;}
IppValue value() const {return *this;}
static IppAttr fromString(std::string string, IppTag tag);
static IppAttr fromString(const std::string& string, IppTag tag);

static IppAttr fromJSON(Json::object json);
static IppAttr fromJSON(const Json::object& json);
Json toJSON() const;

private:
static IppValue valuefromJSON(IppTag tag, const Json& json);
static Json valueToJSON(IppValue value);
static Json valueToJSON(const IppValue& value);

IppTag _tag;

Expand All @@ -141,7 +141,7 @@ struct IppAttrs: public std::map<std::string, IppAttr>
{
using std::map<std::string, IppAttr>::map;

bool has(std::string key) const
bool has(const std::string& key) const
{
return find(key) != end();
}
Expand All @@ -159,13 +159,13 @@ struct IppAttrs: public std::map<std::string, IppAttr>
}
}

void set(std::string key, IppAttr value)
void set(const std::string& key, IppAttr value)
{
insert_or_assign(key, value);
}

template <typename T>
List<T> getList(std::string name) const
List<T> getList(const std::string& name) const
{
List<T> res;
if(has(name))
Expand All @@ -178,7 +178,7 @@ struct IppAttrs: public std::map<std::string, IppAttr>
return res;
}

static IppAttrs fromJSON(Json::object json);
static IppAttrs fromJSON(const Json::object& json);
Json toJSON() const;

};
Expand Down
Loading

0 comments on commit 9cbad23

Please sign in to comment.