Fixed some code scanning alerts

This commit is contained in:
emeric
2022-12-14 20:49:59 +01:00
parent 998def846d
commit 1def36b8f0
13 changed files with 27 additions and 23 deletions
+2
View File
@@ -18,6 +18,8 @@
* along with LMS. If not, see <http://www.gnu.org/licenses/>. * along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once
#include <string_view> #include <string_view>
#include <Wt/WDate.h> #include <Wt/WDate.h>
@@ -467,7 +467,7 @@ CREATE TABLE "starred_track" (
return itScrobbler->second; return itScrobbler->second;
auto query {session.getDboSession().query<Scrobbler>("SELECT scrobbler FROM user WHERE id = ?").bind(userId)}; auto query {session.getDboSession().query<Scrobbler>("SELECT scrobbler FROM user WHERE id = ?").bind(userId)};
auto [itInserted, inserted] {userScrobblers.emplace(userId, query.resultValue())}; [[maybe_unused]] auto [itInserted, inserted] {userScrobblers.emplace(userId, query.resultValue())};
assert(inserted); assert(inserted);
return itInserted->second; return itInserted->second;
}}; }};
@@ -53,8 +53,8 @@ TEST_F(DatabaseFixture, MultiTracksSingleArtistSingleRelease)
ASSERT_EQ(releases.results.size(), 1); ASSERT_EQ(releases.results.size(), 1);
EXPECT_EQ(releases.results.front(), release.getId()); EXPECT_EQ(releases.results.front(), release.getId());
const auto tracks {Track::find(session, Track::FindParameters {}.setRelease(release.getId()))}; const auto releaseTracks {Track::find(session, Track::FindParameters {}.setRelease(release.getId()))};
EXPECT_EQ(tracks.results.size(), nbTracks); EXPECT_EQ(releaseTracks.results.size(), nbTracks);
} }
} }
+5 -3
View File
@@ -39,9 +39,11 @@ TEST_F(DatabaseFixture, Release)
EXPECT_EQ(Release::getCount(session), 1); EXPECT_EQ(Release::getCount(session), 1);
EXPECT_TRUE(Release::exists(session, release.getId())); EXPECT_TRUE(Release::exists(session, release.getId()));
auto releases {Release::findOrphans(session, Range {})}; {
ASSERT_EQ(releases.results.size(), 1); auto releases {Release::findOrphans(session, Range {})};
EXPECT_EQ(releases.results.front(), release.getId()); ASSERT_EQ(releases.results.size(), 1);
EXPECT_EQ(releases.results.front(), release.getId());
}
{ {
auto releases {Release::find(session, Release::FindParameters {})}; auto releases {Release::find(session, Release::FindParameters {})};
@@ -410,7 +410,7 @@ FeaturesEngine::load(const SOM::Network& network, const TrackPositions& trackPos
auto itArtists {_artistMatrix.find(artistLink->getType())}; auto itArtists {_artistMatrix.find(artistLink->getType())};
if (itArtists == std::cend(_artistMatrix)) if (itArtists == std::cend(_artistMatrix))
{ {
auto [it, inserted] = _artistMatrix.try_emplace(artistLink->getType(), ArtistMatrix {width, height}); [[maybe_unused]] auto [it, inserted] = _artistMatrix.try_emplace(artistLink->getType(), ArtistMatrix {width, height});
assert(inserted); assert(inserted);
itArtists = it; itArtists = it;
} }
@@ -17,6 +17,8 @@
* along with LMS. If not, see <http://www.gnu.org/licenses/>. * along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once
#include "services/scrobbling/Exception.hpp" #include "services/scrobbling/Exception.hpp"
namespace Scrobbling::ListenBrainz namespace Scrobbling::ListenBrainz
@@ -23,7 +23,6 @@
#include <Wt/Json/Object.h> #include <Wt/Json/Object.h>
#include <Wt/Json/Value.h> #include <Wt/Json/Value.h>
#include <Wt/Json/Parser.h> #include <Wt/Json/Parser.h>
//#include <Wt/Json/Serializer.h>
#include "services/scrobbling/Exception.hpp" #include "services/scrobbling/Exception.hpp"
#include "Exception.hpp" #include "Exception.hpp"
@@ -17,6 +17,8 @@
* along with LMS. If not, see <http://www.gnu.org/licenses/>. * along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once
#include <string_view> #include <string_view>
#include "FeedbackTypes.hpp" #include "FeedbackTypes.hpp"
@@ -234,7 +234,7 @@ namespace Scrobbling::ListenBrainz
auto itContext {_userContexts.find(userId)}; auto itContext {_userContexts.find(userId)};
if (itContext == std::cend(_userContexts)) if (itContext == std::cend(_userContexts))
{ {
auto [itNewContext, inserted] {_userContexts.emplace(userId, userId)}; [[maybe_unused]] auto [itNewContext, inserted] {_userContexts.emplace(userId, userId)};
itContext = itNewContext; itContext = itNewContext;
} }
@@ -246,7 +246,7 @@ namespace Scrobbling::ListenBrainz
{ {
return std::any_of(std::cbegin(_userContexts), std::cend(_userContexts), [](const auto& contextEntry) return std::any_of(std::cbegin(_userContexts), std::cend(_userContexts), [](const auto& contextEntry)
{ {
const auto& [userId, context] {contextEntry}; [[maybe_unused]] const auto& [userId, context] {contextEntry};
return context.syncing; return context.syncing;
}); });
} }
@@ -354,7 +354,7 @@ namespace Scrobbling::ListenBrainz
auto itContext {_userContexts.find(userId)}; auto itContext {_userContexts.find(userId)};
if (itContext == std::cend(_userContexts)) if (itContext == std::cend(_userContexts))
{ {
auto [itNewContext, inserted] {_userContexts.emplace(userId, userId)}; [[maybe_unused]] auto [itNewContext, inserted] {_userContexts.emplace(userId, userId)};
itContext = itNewContext; itContext = itNewContext;
} }
@@ -366,7 +366,7 @@ namespace Scrobbling::ListenBrainz
{ {
return std::any_of(std::cbegin(_userContexts), std::cend(_userContexts), [](const auto& contextEntry) return std::any_of(std::cbegin(_userContexts), std::cend(_userContexts), [](const auto& contextEntry)
{ {
const auto& [userId, context] {contextEntry}; [[maybe_unused]] const auto& [userId, context] {contextEntry};
return context.syncing; return context.syncing;
}); });
} }
+7 -8
View File
@@ -993,10 +993,9 @@ handleGetMusicDirectoryRequest(RequestContext& context)
// Mandatory params // Mandatory params
const auto artistId {getParameterAs<ArtistId>(context.parameters, "id")}; const auto artistId {getParameterAs<ArtistId>(context.parameters, "id")};
const auto releaseId {getParameterAs<ReleaseId>(context.parameters, "id")}; const auto releaseId {getParameterAs<ReleaseId>(context.parameters, "id")};
const auto trackId {getParameterAs<TrackId>(context.parameters, "id")};
const auto root {getParameterAs<RootId>(context.parameters, "id")}; const auto root {getParameterAs<RootId>(context.parameters, "id")};
if (!root && !artistId && !releaseId && !trackId) if (!root && !artistId && !releaseId)
throw BadParameterGenericError {"id"}; throw BadParameterGenericError {"id"};
Response response {Response::createOkResponse(context.serverProtocolVersion)}; Response response {Response::createOkResponse(context.serverProtocolVersion)};
@@ -1013,10 +1012,10 @@ handleGetMusicDirectoryRequest(RequestContext& context)
directoryNode.setAttribute("id", idToString(RootId {})); directoryNode.setAttribute("id", idToString(RootId {}));
directoryNode.setAttribute("name", "Music"); directoryNode.setAttribute("name", "Music");
auto artistIds {Artist::find(context.dbSession, Artist::FindParameters {}.setSortMethod(ArtistSortMethod::BySortName))}; auto rootArtistIds {Artist::find(context.dbSession, Artist::FindParameters {}.setSortMethod(ArtistSortMethod::BySortName))};
for (const ArtistId artistId : artistIds.results) for (const ArtistId rootArtistId : rootArtistIds.results)
{ {
const Artist::pointer artist {Artist::find(context.dbSession, artistId)}; const Artist::pointer artist {Artist::find(context.dbSession, rootArtistId)};
directoryNode.addArrayChild("child", artistToResponseNode(artist, context.dbSession, user, false /* no id3 */)); directoryNode.addArrayChild("child", artistToResponseNode(artist, context.dbSession, user, false /* no id3 */));
} }
} }
@@ -1030,10 +1029,10 @@ handleGetMusicDirectoryRequest(RequestContext& context)
directoryNode.setAttribute("name", makeNameFilesystemCompatible(artist->getName())); directoryNode.setAttribute("name", makeNameFilesystemCompatible(artist->getName()));
const auto releases {Release::find(context.dbSession, Release::FindParameters {}.setArtist(*artistId))}; const auto artistReleases {Release::find(context.dbSession, Release::FindParameters {}.setArtist(*artistId))};
for (const ReleaseId releaseId : releases.results) for (const ReleaseId artistReleaseId : artistReleases.results)
{ {
const Release::pointer release {Release::find(context.dbSession, releaseId)}; const Release::pointer release {Release::find(context.dbSession, artistReleaseId)};
directoryNode.addArrayChild("child", releaseToResponseNode(release, context.dbSession, user, false /* no id3 */)); directoryNode.addArrayChild("child", releaseToResponseNode(release, context.dbSession, user, false /* no id3 */));
} }
} }
+1 -2
View File
@@ -54,8 +54,7 @@ DownloadResource::handleRequest(const Wt::Http::Request& request, Wt::Http::Resp
std::shared_ptr<Zip::Zipper> zipper; std::shared_ptr<Zip::Zipper> zipper;
// First, see if this request is for a continuation // First, see if this request is for a continuation
Wt::Http::ResponseContinuation *continuation = request.continuation(); if (Wt::Http::ResponseContinuation *continuation {request.continuation()})
if (continuation)
zipper = Wt::cpp17::any_cast<std::shared_ptr<Zip::Zipper>>(continuation->data()); zipper = Wt::cpp17::any_cast<std::shared_ptr<Zip::Zipper>>(continuation->data());
else else
{ {
-1
View File
@@ -66,7 +66,6 @@ int main(int argc, char* argv[])
Zip::SizeType nbTotalWrittenBytes {}; Zip::SizeType nbTotalWrittenBytes {};
while (!zipper.isComplete()) while (!zipper.isComplete())
{ {
//std::array<std::byte, Zipper::minOutputBufferSize> buffer;
std::array<std::byte, 65536> buffer; std::array<std::byte, 65536> buffer;
const Zip::SizeType nbWrittenBytes {zipper.writeSome(buffer.data(), buffer.size())}; const Zip::SizeType nbWrittenBytes {zipper.writeSome(buffer.data(), buffer.size())};