Skip to content

Commit

Permalink
fix cppcheck static analysis warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
williamyang98 committed Feb 22, 2024
1 parent fe8f0e3 commit 50be690
Show file tree
Hide file tree
Showing 39 changed files with 225 additions and 224 deletions.
8 changes: 4 additions & 4 deletions examples/app_helpers/app_io_buffers.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class FileWrapper {
FILE* m_file = nullptr;
std::shared_mutex m_mutex;
public:
FileWrapper(FILE* file): m_file(file) {}
explicit FileWrapper(FILE* file): m_file(file) {}
virtual ~FileWrapper() { close(); }
void close() {
auto lock = std::unique_lock(m_mutex);
Expand All @@ -53,7 +53,7 @@ template <typename T>
class InputFile: public InputBuffer<T>, public FileWrapper {
private:
public:
InputFile(FILE* file): FileWrapper(file) {}
explicit InputFile(FILE* file): FileWrapper(file) {}
~InputFile() override = default;
size_t read(tcb::span<T> dest) override {
return FileWrapper::read(dest);
Expand All @@ -63,7 +63,7 @@ class InputFile: public InputBuffer<T>, public FileWrapper {
template <typename T>
class OutputFile: public OutputBuffer<T>, public FileWrapper {
public:
OutputFile(FILE* file): FileWrapper(file) {}
explicit OutputFile(FILE* file): FileWrapper(file) {}
~OutputFile() override = default;
size_t write(tcb::span<const T> src) override {
return FileWrapper::write(src);
Expand All @@ -73,7 +73,7 @@ class OutputFile: public OutputBuffer<T>, public FileWrapper {
template <typename T>
class InputOutputFile: public InputBuffer<T>, public OutputBuffer<T>, public FileWrapper {
public:
InputOutputFile(FILE* file): FileWrapper(file) {}
explicit InputOutputFile(FILE* file): FileWrapper(file) {}
~InputOutputFile() override = default;
size_t read(tcb::span<T> dest) override {
return FileWrapper::read(dest);
Expand Down
6 changes: 5 additions & 1 deletion examples/audio/audio_pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ void AudioPipeline::set_sink(std::unique_ptr<AudioPipelineSink>&& sink) {

void AudioPipeline::mix_sources_to_sink(tcb::span<Frame<float>> dest, float dest_sampling_rate) {
const size_t N_dest = dest.size();
std::memset(dest.data(), 0, sizeof(Frame<float>) * N_dest);
for (auto& v: dest) {
for (size_t i = 0; i < Frame<float>::TOTAL_AUDIO_CHANNELS; i++) {
v.channels[i] = 0.0f;
}
}
std::vector<std::shared_ptr<AudioPipelineSource>> sources;
{
auto lock = std::scoped_lock(m_mutex_sources);
Expand Down
2 changes: 1 addition & 1 deletion examples/device/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void Device::SetAutoGain(void) {
void Device::SetNearestGain(const float target_gain) {
float min_err = 10000.0f;
float nearest_gain = 0.0f;
for (auto& gain: m_gain_list) {
for (const auto& gain: m_gain_list) {
const float err = std::abs(gain-target_gain);
if (err < min_err) {
min_err = err;
Expand Down
4 changes: 2 additions & 2 deletions examples/gui/basic_radio/formatters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "dab/constants/language_table.h"
#include "dab/constants/programme_type_table.h"

std::string GetSubchannelProtectionLabel(Subchannel& subchannel) {
std::string GetSubchannelProtectionLabel(const Subchannel& subchannel) {
if (subchannel.is_uep) {
return fmt::format("UEP {}", subchannel.uep_prot_index);
}
Expand All @@ -15,7 +15,7 @@ std::string GetSubchannelProtectionLabel(Subchannel& subchannel) {
return fmt::format("EEP {}-{}", protection_id, is_type_A ? 'A' : 'B');
}

uint32_t GetSubchannelBitrate(Subchannel& subchannel) {
uint32_t GetSubchannelBitrate(const Subchannel& subchannel) {
if (subchannel.is_uep) {
const auto descriptor = GetUEPDescriptor(subchannel);
return descriptor.bitrate;
Expand Down
4 changes: 2 additions & 2 deletions examples/gui/basic_radio/formatters.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include "dab/database/dab_database_entities.h"
#include "dab/audio/aac_frame_processor.h"

std::string GetSubchannelProtectionLabel(Subchannel& subchannel);
uint32_t GetSubchannelBitrate(Subchannel& subchannel);
std::string GetSubchannelProtectionLabel(const Subchannel& subchannel);
uint32_t GetSubchannelBitrate(const Subchannel& subchannel);
const char* GetTransportModeString(const TransportMode transport_mode);
const char* GetAudioTypeString(const AudioServiceType audio_type);
const char* GetDataTypeString(const DataServiceType data_type);
Expand Down
74 changes: 52 additions & 22 deletions examples/gui/basic_radio/render_basic_radio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
#include "basic_radio/basic_audio_channel.h"
#include "basic_radio/basic_dab_plus_channel.h"
#include "basic_radio/basic_dab_channel.h"
#include "dab/database/dab_database_entities.h"
#include "dab/database/dab_database.h"
#include "dab/database/dab_database_entities.h"
#include "dab/database/dab_database_types.h"
#include "dab/database/dab_database_updater.h"

template <typename T, typename F>
Expand All @@ -32,13 +33,13 @@ static T* find_by_callback(std::vector<T>& vec, F&& func) {
}

static void RenderSimple_ServiceList(BasicRadio& radio, BasicRadioViewController& controller);
static void RenderSimple_Service(BasicRadio& radio, BasicRadioViewController& controller, Service* service);
static void RenderSimple_ServiceComponentList(BasicRadio& radio, BasicRadioViewController& controller, Service* service);
static void RenderSimple_Service(BasicRadio& radio, BasicRadioViewController& controller, const Service* service);
static void RenderSimple_ServiceComponentList(BasicRadio& radio, BasicRadioViewController& controller, const Service* service);
static void RenderSimple_ServiceComponent(BasicRadio& radio, BasicRadioViewController& controller, ServiceComponent& component);
static void RenderSimple_Basic_Audio_Channel(BasicRadio& radio, BasicRadioViewController& controller, Basic_Audio_Channel& channel, const subchannel_id_t subchannel_id);
static void RenderSimple_Basic_Data_Channel(BasicRadio& radio, BasicRadioViewController& controller, Basic_Data_Packet_Channel& channel, const subchannel_id_t subchannel_id);
static void RenderSimple_BasicSlideshowSelected(BasicRadio& radio, BasicRadioViewController& controller);
static void RenderSimple_LinkServices(BasicRadio& radio, BasicRadioViewController& controller, Service* service);
static void RenderSimple_LinkServices(BasicRadio& radio, BasicRadioViewController& controller, const Service* service);
static void RenderSimple_LinkService(BasicRadio& radio, BasicRadioViewController& controller, const LinkService& link_service);
static void RenderSimple_GlobalBasicAudioChannelControls(BasicRadio& radio);
static void RenderSimple_Basic_DAB_Plus_Channel_Status(Basic_DAB_Plus_Channel& channel);
Expand Down Expand Up @@ -128,12 +129,9 @@ void RenderSimple_ServiceList(BasicRadio& radio, BasicRadioViewController& contr
ImGui::End();
}

void RenderSimple_Service(BasicRadio& radio, BasicRadioViewController& controller, Service* service) {
auto& db = radio.GetDatabase();
auto& ensemble = db.ensemble;

void RenderSimple_Service(BasicRadio& radio, BasicRadioViewController& controller, const Service* service) {
if (ImGui::Begin("Service Description") && service) {
ImGuiTableFlags flags = ImGuiTableFlags_Resizable | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable | ImGuiTableFlags_Borders;
const ImGuiTableFlags flags = ImGuiTableFlags_Resizable | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable | ImGuiTableFlags_Borders;
if (ImGui::BeginTable("Service Description", 2, flags)) {
ImGui::TableSetupColumn("Field", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableSetupColumn("Value", ImGuiTableColumnFlags_WidthStretch);
Expand All @@ -150,17 +148,20 @@ void RenderSimple_Service(BasicRadio& radio, BasicRadioViewController& controlle
ImGui::PopID();\
}\

const auto& db = radio.GetDatabase();
const auto& ensemble = db.ensemble;
FIELD_MACRO("Name", "%.*s", int(service->label.length()), service->label.c_str());
FIELD_MACRO("ID", "%u", service->reference);
FIELD_MACRO("Country Code", "0x%02X.%01X", service->extended_country_code, service->country_id);
{
extended_country_id_t extended_country_code = (service->extended_country_code != 0) ? service->extended_country_code : ensemble.extended_country_code;
extended_country_id_t country_id = (service->country_id != 0) ? service->country_id : ensemble.country_id;
FIELD_MACRO("Country", "%s (0x%02X.%01X)", GetCountryString(extended_country_code, country_id), extended_country_code, country_id);
}
FIELD_MACRO("Programme Type", "%s (%u)",
GetProgrammeTypeString(ensemble.international_table_id, service->programme_type),
service->programme_type);
FIELD_MACRO("Language", "%s (%u)", GetLanguageTypeString(service->language), service->language);
FIELD_MACRO("Closed Caption", "%u", service->closed_caption);
// FIELD_MACRO("Country Name", "%s", GetCountryString(
// service->extended_country_code ? service->extended_country_code : ensemble.extended_country_code,
// service->country_id ? service->country_id : ensemble.country_id));

#undef FIELD_MACRO

Expand All @@ -170,7 +171,7 @@ void RenderSimple_Service(BasicRadio& radio, BasicRadioViewController& controlle
ImGui::End();
}

void RenderSimple_ServiceComponentList(BasicRadio& radio, BasicRadioViewController& controller, Service* service) {
void RenderSimple_ServiceComponentList(BasicRadio& radio, BasicRadioViewController& controller, const Service* service) {
auto& db = radio.GetDatabase();
static std::vector<ServiceComponent*> service_components;
service_components.clear();
Expand Down Expand Up @@ -299,7 +300,7 @@ static void RenderSimple_Slideshow_Manager(BasicRadioViewController& controller,
ImGuiChildFlags child_flags = ImGuiChildFlags_Border;
ImGuiWindowFlags window_flags = ImGuiWindowFlags_None;
if (ImGui::BeginChild("Slideshow", ImVec2(0, 0), child_flags, window_flags)) {
ImGuiStyle& style = ImGui::GetStyle();
const ImGuiStyle& style = ImGui::GetStyle();
static std::vector<std::shared_ptr<Basic_Slideshow>> slideshows;
{
auto lock = std::unique_lock(slideshow_manager.GetSlideshowsMutex());
Expand All @@ -313,7 +314,7 @@ static void RenderSimple_Slideshow_Manager(BasicRadioViewController& controller,
float curr_x = 0.0f;
int slideshow_id = 0;
for (auto& slideshow: slideshows) {
auto& texture = controller.GetTexture(subchannel_id, slideshow->transport_id, slideshow->image_data);
const auto& texture = controller.GetTexture(subchannel_id, slideshow->transport_id, slideshow->image_data);
// Determine size of thumbnail
const auto texture_id = reinterpret_cast<ImTextureID>(texture.GetTextureID());
const float target_height = 200.0f;
Expand Down Expand Up @@ -530,8 +531,8 @@ void RenderSimple_BasicSlideshowSelected(BasicRadio& radio, BasicRadioViewContro
}
}

void RenderSimple_LinkServices(BasicRadio& radio, BasicRadioViewController& controller, Service* service) {
auto& db = radio.GetDatabase();
void RenderSimple_LinkServices(BasicRadio& radio, BasicRadioViewController& controller, const Service* service) {
const auto& db = radio.GetDatabase();
static std::vector<const LinkService*> link_services;
link_services.clear();
if (service) {
Expand Down Expand Up @@ -599,15 +600,15 @@ void RenderSimple_LinkService(BasicRadio& radio, BasicRadioViewController& contr
ImGui::TableHeadersRow();

int row_id = 0;
for (auto& fm_service: fm_services) {
for (const auto& fm_service: fm_services) {
ImGui::PushID(row_id++);
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
ImGui::TextWrapped("%04X", fm_service->RDS_PI_code);
ImGui::TableSetColumnIndex(1);
ImGui::TextWrapped("%s", fm_service->is_time_compensated ? "Yes" : "No");
ImGui::TableSetColumnIndex(2);
for (auto& freq: fm_service->frequencies) {
for (const auto& freq: fm_service->frequencies) {
ImGui::Text("%3.3f MHz", static_cast<float>(freq)*1e-6f);
}
ImGui::PopID();
Expand All @@ -634,15 +635,44 @@ void RenderSimple_LinkService(BasicRadio& radio, BasicRadioViewController& contr
ImGui::TableHeadersRow();

int row_id = 0;
for (auto& drm_service: drm_services) {
for (const auto& drm_service: drm_services) {
ImGui::PushID(row_id++);
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
ImGui::TextWrapped("%u", drm_service->drm_code);
ImGui::TableSetColumnIndex(1);
ImGui::TextWrapped("%s", drm_service->is_time_compensated ? "Yes" : "No");
ImGui::TableSetColumnIndex(2);
for (auto& freq: drm_service->frequencies) {
for (const auto& freq: drm_service->frequencies) {
ImGui::Text("%3.3f MHz", static_cast<float>(freq)*1e-6f);
}
ImGui::PopID();
}
ImGui::EndTable();
}
}
}

// AMSS Services
if (db.amss_services.size() > 0) {
const auto amss_label = fmt::format("AMSS Services ({})###AMSS Services", db.amss_services.size());
if (ImGui::CollapsingHeader(amss_label.c_str())) {
if (ImGui::BeginTable("AMSS Table", 3, flags)) {
ImGui::TableSetupColumn("ID", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableSetupColumn("Time compensated", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableSetupColumn("Frequencies", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableHeadersRow();

int row_id = 0;
for (const auto& amss_service: db.amss_services) {
ImGui::PushID(row_id++);
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
ImGui::TextWrapped("%u", amss_service.amss_code);
ImGui::TableSetColumnIndex(1);
ImGui::TextWrapped("%s", amss_service.is_time_compensated ? "Yes" : "No");
ImGui::TableSetColumnIndex(2);
for (const auto& freq: amss_service.frequencies) {
ImGui::Text("%3.3f MHz", static_cast<float>(freq)*1e-6f);
}
ImGui::PopID();
Expand Down
14 changes: 6 additions & 8 deletions examples/gui/basic_radio/render_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ void RenderSubchannels(BasicRadio& radio) {

// Render the ensemble information
void RenderEnsemble(BasicRadio& radio) {
auto& db = radio.GetDatabase();
auto& ensemble = db.ensemble;

if (ImGui::Begin("Ensemble")) {
ImGuiTableFlags flags = ImGuiTableFlags_Resizable | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable | ImGuiTableFlags_Borders;
if (ImGui::BeginTable("Ensemble description", 2, flags)) {
Expand All @@ -117,6 +114,8 @@ void RenderEnsemble(BasicRadio& radio) {
}\

int row_id = 0;
auto& db = radio.GetDatabase();
auto& ensemble = db.ensemble;
const float LTO = float(ensemble.local_time_offset) / 10.0f;
FIELD_MACRO("Name", "%.*s", int(ensemble.label.length()), ensemble.label.c_str());
FIELD_MACRO("ID", "%u", ensemble.reference);
Expand All @@ -137,7 +136,6 @@ void RenderEnsemble(BasicRadio& radio) {

// Render misc information about the date and time
void RenderDateTime(BasicRadio& radio) {
const auto& info = radio.GetMiscInfo();
if (ImGui::Begin("Date & Time")) {
ImGuiTableFlags flags = ImGuiTableFlags_Resizable | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable | ImGuiTableFlags_Borders;
if (ImGui::BeginTable("Date & Time", 2, flags)) {
Expand All @@ -156,6 +154,7 @@ void RenderDateTime(BasicRadio& radio) {
}\

int row_id = 0;
const auto& info = radio.GetMiscInfo();
FIELD_MACRO("Date", "%02d/%02d/%04d",
info.datetime.day, info.datetime.month, info.datetime.year);
FIELD_MACRO("Time", "%02u:%02u:%02u.%03u",
Expand All @@ -174,7 +173,6 @@ void RenderDateTime(BasicRadio& radio) {

// Database statistics
void RenderDatabaseStatistics(BasicRadio& radio) {
const auto& stats = radio.GetDatabaseStatistics();
if (ImGui::Begin("Database Stats")) {
ImGuiTableFlags flags = ImGuiTableFlags_Resizable | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable | ImGuiTableFlags_Borders;
if (ImGui::BeginTable("Date & Time", 2, flags)) {
Expand All @@ -193,6 +191,7 @@ void RenderDatabaseStatistics(BasicRadio& radio) {
}\

int row_id = 0;
const auto& stats = radio.GetDatabaseStatistics();
FIELD_MACRO("Total", "%zu", stats.nb_total);
FIELD_MACRO("Pending", "%zu", stats.nb_pending);
FIELD_MACRO("Completed", "%zu", stats.nb_completed);
Expand All @@ -209,8 +208,7 @@ void RenderDatabaseStatistics(BasicRadio& radio) {
// Linked ensembles
void RenderOtherEnsembles(BasicRadio& radio) {
auto& db = radio.GetDatabase();
auto label = fmt::format("Other Ensembles ({})###Other Ensembles",
db.other_ensembles.size());
auto label = fmt::format("Other Ensembles ({})###Other Ensembles", db.other_ensembles.size());

if (ImGui::Begin(label.c_str())) {
ImGuiTableFlags flags = ImGuiTableFlags_Resizable | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable | ImGuiTableFlags_Borders;
Expand All @@ -225,7 +223,7 @@ void RenderOtherEnsembles(BasicRadio& radio) {
ImGui::TableHeadersRow();

int row_id = 0;
for (auto& ensemble: db.other_ensembles) {
for (const auto& ensemble: db.other_ensembles) {
ImGui::PushID(row_id++);

const float frequency = static_cast<float>(ensemble.frequency) * 1e-6f;
Expand Down
Loading

0 comments on commit 50be690

Please sign in to comment.