Skip to content

Commit fc664f0

Browse files
metsmakristelmerilain
authored andcommitted
Fix Coverity warnings
IB-8531 Signed-off-by: Raul Metsma <raul@metsma.ee>
1 parent 6e941c4 commit fc664f0

9 files changed

Lines changed: 20 additions & 12 deletions

File tree

build.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ Try {
2323
& wix > $null
2424
}
2525
Catch {
26-
& dotnet tool install -g --version 6.0.1 wix
27-
& wix extension add -g WixToolset.UI.wixext/6.0.1
26+
& dotnet tool install -g --version 6.0.2 wix
27+
& wix extension add -g WixToolset.UI.wixext/6.0.2
2828
}
2929

3030
if(!(Test-Path -Path $vcpkg)) {

src/ASiC_S.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ ASiC_S::ASiC_S(const string &path)
9898
string tst = z.extract<stringstream>(uri).str();
9999
addSignature(make_unique<SignatureTST>(file, ::move(doc), tst, this));
100100
metadata.push_back({file, string(mime), xml.str()});
101-
metadata.push_back({uri, string(ref["MimeType"]), std::move(tst)});
101+
metadata.push_back({std::move(uri), string(ref["MimeType"]), std::move(tst)});
102102
};
103103
add(file, "text/xml");
104104
}

src/ASiContainer.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,12 @@ void ASiContainer::addDataFile(const string &path, const string &mediaType)
170170
{
171171
string fileName = File::fileName(path);
172172
addDataFileChecks(fileName, mediaType);
173-
auto size = File::fileSize(path);
173+
auto nativePath = File::encodeName(path);
174+
auto size = File::fileSize(nativePath);
174175
if(size == 0)
175176
THROW("Document file '%s' does not exist or is empty.", path.c_str());
176177

177-
unique_ptr<istream> is = make_unique<ifstream>(File::encodeName(path), ifstream::binary);
178+
unique_ptr<istream> is = make_unique<ifstream>(nativePath, ifstream::binary);
178179
if(!*is)
179180
THROW("Failed to open file for reading: %s.", path.c_str());
180181
if(size <= MAX_MEM_FILE)

src/SignatureTST.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ void SignatureTST::validate() const
123123
string_view method = (ref/DigestMethod)["Algorithm"];
124124
auto uri = util::File::fromUriPath(ref["URI"]);
125125
vector<unsigned char> digest = file->fileName() == uri ?
126-
dynamic_cast<const DataFilePrivate*>(file)->calcDigest(string(method)) :
126+
static_cast<const DataFilePrivate*>(file)->calcDigest(string(method)) :
127127
asicSDoc->fileDigest(uri, method).result();
128128
if(vector<unsigned char> digestValue = ref/DigestValue; digest != digestValue)
129129
THROW("Reference %s digest does not match", uri.c_str());

src/XMLDocument.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ struct XMLDocument: public unique_free_d<xmlFreeDoc>, public XMLNode
456456
return ctx->status == xmlSecDSigStatusSucceeded;
457457
}
458458

459-
static void schemaValidationError(void *ctx, const char *msg, ...) noexcept
459+
static void schemaValidationError(void *ctx, const char *msg, ...) noexcept try
460460
{
461461
va_list args{};
462462
va_start(args, msg);
@@ -469,15 +469,19 @@ struct XMLDocument: public unique_free_d<xmlFreeDoc>, public XMLNode
469469
}
470470
else
471471
ERR("Schema validation error: %s", m.c_str());
472+
} catch(const std::exception &e) {
473+
std::printf("Unexpected error: %s", e.what());
472474
}
473475

474-
static void schemaValidationWarning(void */*ctx*/, const char *msg, ...) noexcept
476+
static void schemaValidationWarning(void */*ctx*/, const char *msg, ...) noexcept try
475477
{
476478
va_list args{};
477479
va_start(args, msg);
478480
std::string m = Log::formatArgList(msg, args);
479481
va_end(args);
480482
WARN("Schema validation warning: %s", m.c_str());
483+
} catch(const std::exception &e) {
484+
std::printf("Unexpected error: %s", e.what());
481485
}
482486
};
483487

src/XmlConf.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ auto XmlConf::Private::loadDoc(const string &path) const
146146
void XmlConf::Private::init(const string& path, bool global)
147147
{
148148
DEBUG("XmlConfPrivate::init(%s, %u)", path.c_str(), global);
149-
if(File::fileSize(path) == 0)
149+
if(File::fileSize(File::encodeName(path)) == 0)
150150
return;
151151

152152
auto doc = loadDoc(path);

src/digidoc-tool.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,4 +1060,7 @@ int main(int argc, char *argv[]) try
10601060
} catch(const Exception &e) {
10611061
cout << "Caught Exception:" << endl << e;
10621062
return EXIT_FAILURE;
1063+
} catch(const std::exception &e) {
1064+
cout << "Caught Exception:" << endl << e.what();
1065+
return EXIT_FAILURE;
10631066
}

src/util/File.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,10 @@ bool File::fileExtension(string_view path, initializer_list<string_view> list)
156156
/**
157157
* Returns file size
158158
*/
159-
unsigned long File::fileSize(string_view path) noexcept
159+
unsigned long File::fileSize(const std::filesystem::path &path) noexcept
160160
{
161161
error_code ec;
162-
auto result = fs::file_size(encodeName(path), ec);
162+
auto result = fs::file_size(path, ec);
163163
return ec ? 0 : result;
164164
}
165165

src/util/File.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ namespace digidoc
4242
static void updateModifiedTime(const std::string &path, time_t time);
4343
static bool fileExists(const std::string& path);
4444
static bool fileExtension(std::string_view path, std::initializer_list<std::string_view> list);
45-
static unsigned long fileSize(std::string_view path) noexcept;
45+
static unsigned long fileSize(const std::filesystem::path &path) noexcept;
4646
static std::string fileName(const std::string& path);
4747
static std::string directory(const std::string& path);
4848
static std::string path(std::string dir, std::string_view relativePath);

0 commit comments

Comments
 (0)