Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: sonarcloud fixes #479

Merged
merged 22 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
3d8fd2a
chore(ci): update sonarcloud image to latest
nfrechette Oct 14, 2023
1ba98cc
fix(ci): remove deprecated sonarcloud property usage
nfrechette Oct 14, 2023
bbdc933
chore: update to latest sjson-cpp develop
nfrechette Oct 14, 2023
8029677
chore: update to latest rtm develop
nfrechette Oct 14, 2023
8dee09a
fix: mark assert functions as noreturn
nfrechette Oct 21, 2023
6c0bab9
fix(compression): make variable const when it doesn't change
nfrechette Oct 21, 2023
68dc9aa
style: don't explicitly call constructors
nfrechette Oct 21, 2023
e194262
fix(compression): properly handle track array looping policy when moving
nfrechette Oct 21, 2023
d3c0df4
style: cleanup whitespace
nfrechette Oct 21, 2023
6484e90
fix(core): use default initializer
nfrechette Oct 21, 2023
abc6feb
style(core): remove redundant parenthesis
nfrechette Oct 21, 2023
34fbe18
style(compression): use default initializer
nfrechette Oct 21, 2023
a079194
fix(core): use RTM macros for cpp version & compiler detection
nfrechette Oct 21, 2023
c035b73
style(decompression): fix whitespace
nfrechette Oct 21, 2023
99a15b2
style(compression): use explicit default initializer
nfrechette Oct 22, 2023
3edfcf3
style(compression): use explicit default initializer
nfrechette Oct 22, 2023
25abd8e
feat: introduce a bit_cast shim
nfrechette Oct 22, 2023
b63196d
fix: use bit_cast instead of reinterpret_cast for safety
nfrechette Oct 22, 2023
78a343c
fix(core): force integral type to be same width as pointer before bit…
nfrechette Oct 24, 2023
090af1c
style(core): add function comment and clean up template argument names
nfrechette Oct 24, 2023
499983c
fix(core): let template argument auto-deduce to avoid type safety issue
nfrechette Oct 24, 2023
829f11f
fix(compression): add missing const keyword
nfrechette Oct 24, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ jobs:
with:
submodules: 'recursive'
- name: Build with wrapper
uses: docker://ghcr.io/nfrechette/toolchain-amd64-linux-sonarcloud:v2
uses: docker://ghcr.io/nfrechette/toolchain-amd64-linux-sonarcloud:v3
with:
args: '/build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir bw_output python3 make.py -compiler clang14 -config Release -cpu x64 -build'
args: '/build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir bw_output python3 make.py -compiler clang15 -config Release -cpu x64 -build'
- name: Run Sonar Scanner and upload to Sonarcloud
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: https://sonarcloud.io
uses: docker://ghcr.io/nfrechette/toolchain-amd64-linux-sonarcloud:v2
uses: docker://ghcr.io/nfrechette/toolchain-amd64-linux-sonarcloud:v3
with:
args: '/sonar-scanner-4.7.0.2747-linux/bin/sonar-scanner'
args: '/sonar-scanner-5.0.1.3006-linux/bin/sonar-scanner'
17 changes: 9 additions & 8 deletions includes/acl/compression/impl/compress.database.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "acl/core/error_result.h"
#include "acl/core/hash.h"
#include "acl/core/iallocator.h"
#include "acl/core/impl/bit_cast.impl.h"

#include <cstdint>

Expand Down Expand Up @@ -110,7 +111,7 @@ namespace acl

if (tracks->get_version() >= compressed_tracks_version16::v02_01_99_2)
{
clip_error.keyframe_metadata = reinterpret_cast<const keyframe_stripping_metadata_t*>(metadata_header.get_contributing_error(*tracks));
clip_error.keyframe_metadata = bit_cast<const keyframe_stripping_metadata_t*>(metadata_header.get_contributing_error(*tracks));
}
else
{
Expand All @@ -121,7 +122,7 @@ namespace acl
const uint32_t* segment_start_indices = has_multiple_segments ? transform_header.get_segment_start_indices() : nullptr;
const uint32_t num_segments = has_multiple_segments ? transform_header.num_segments : 1; // HACK to avoid static analysis warning

const frame_contributing_error* contributing_errors = reinterpret_cast<const frame_contributing_error*>(metadata_header.get_contributing_error(*tracks));
const frame_contributing_error* contributing_errors = bit_cast<const frame_contributing_error*>(metadata_header.get_contributing_error(*tracks));

for (uint32_t segment_index = 0; segment_index < num_segments; ++segment_index)
{
Expand Down Expand Up @@ -681,7 +682,7 @@ namespace acl
std::memset(buffer, 0, buffer_size);

uint8_t* buffer_start = buffer;
out_compressed_tracks[list_index] = reinterpret_cast<compressed_tracks*>(buffer);
out_compressed_tracks[list_index] = bit_cast<compressed_tracks*>(buffer);

raw_buffer_header* buffer_header = safe_ptr_cast<raw_buffer_header>(buffer);
buffer += sizeof(raw_buffer_header);
Expand Down Expand Up @@ -739,7 +740,7 @@ namespace acl

if (metadata_size != 0)
{
optional_metadata_header* metadata_header = reinterpret_cast<optional_metadata_header*>(buffer_start + buffer_size - sizeof(optional_metadata_header));
optional_metadata_header* metadata_header = bit_cast<optional_metadata_header*>(buffer_start + buffer_size - sizeof(optional_metadata_header));
uint32_t metadata_offset = metadata_start_offset; // Relative to the start of our compressed_tracks

// Setup our metadata offsets
Expand Down Expand Up @@ -1107,7 +1108,7 @@ namespace acl
}

// Calculate the finale offset for our chunk's data relative to the bulk data start and the final header size
const uint32_t chunk_data_offset = static_cast<uint32_t>(reinterpret_cast<uint8_t*>(chunk_header) - bulk_data);
const uint32_t chunk_data_offset = static_cast<uint32_t>(bit_cast<uint8_t*>(chunk_header) - bulk_data);
const uint32_t chunk_header_size = sizeof(database_chunk_header) + chunk_header->num_segments * sizeof(database_chunk_segment_header);

// Update the sample offset from being relative to the start of the sample data to the start of the bulk data
Expand Down Expand Up @@ -1161,7 +1162,7 @@ namespace acl
uint8_t* database_buffer = allocate_type_array_aligned<uint8_t>(context.allocator, database_buffer_size, alignof(compressed_database));
std::memset(database_buffer, 0, database_buffer_size);

compressed_database* database = reinterpret_cast<compressed_database*>(database_buffer);
compressed_database* database = bit_cast<compressed_database*>(database_buffer);

const uint8_t* database_buffer_start = database_buffer;

Expand Down Expand Up @@ -1344,7 +1345,7 @@ namespace acl

// Allocate and setup our new database
uint8_t* database_buffer = allocate_type_array_aligned<uint8_t>(allocator, db_size, alignof(compressed_database));
out_split_database = reinterpret_cast<compressed_database*>(database_buffer);
out_split_database = bit_cast<compressed_database*>(database_buffer);

std::memcpy(database_buffer, &database, db_size);

Expand Down Expand Up @@ -1429,7 +1430,7 @@ namespace acl
// Allocate and setup our new database
uint8_t* database_buffer = allocate_type_array_aligned<uint8_t>(allocator, database_buffer_size, alignof(compressed_database));
std::memset(database_buffer, 0, database_buffer_size);
out_stripped_database = reinterpret_cast<compressed_database*>(database_buffer);
out_stripped_database = bit_cast<compressed_database*>(database_buffer);

raw_buffer_header* database_buffer_header = safe_ptr_cast<raw_buffer_header>(database_buffer);
database_buffer += sizeof(raw_buffer_header);
Expand Down
5 changes: 3 additions & 2 deletions includes/acl/compression/impl/compress.scalar.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "acl/core/error_result.h"
#include "acl/core/iallocator.h"
#include "acl/core/scope_profiler.h"
#include "acl/core/impl/bit_cast.impl.h"
#include "acl/compression/compression_settings.h"
#include "acl/compression/output_stats.h"
#include "acl/compression/track_array.h"
Expand Down Expand Up @@ -137,7 +138,7 @@ namespace acl
std::memset(buffer, 0, buffer_size);

uint8_t* buffer_start = buffer;
out_compressed_tracks = reinterpret_cast<compressed_tracks*>(buffer);
out_compressed_tracks = bit_cast<compressed_tracks*>(buffer);

raw_buffer_header* buffer_header = safe_ptr_cast<raw_buffer_header>(buffer);
buffer += sizeof(raw_buffer_header);
Expand Down Expand Up @@ -206,7 +207,7 @@ namespace acl
uint32_t written_metadata_track_descriptions_size = 0;
if (metadata_size != 0)
{
optional_metadata_header* metadada_header = reinterpret_cast<optional_metadata_header*>(buffer_start + buffer_size - sizeof(optional_metadata_header));
optional_metadata_header* metadada_header = bit_cast<optional_metadata_header*>(buffer_start + buffer_size - sizeof(optional_metadata_header));
uint32_t metadata_offset = metadata_start_offset;

if (settings.metadata.include_track_list_name)
Expand Down
5 changes: 3 additions & 2 deletions includes/acl/compression/impl/compress.transform.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "acl/core/floating_point_exceptions.h"
#include "acl/core/iallocator.h"
#include "acl/core/scope_profiler.h"
#include "acl/core/impl/bit_cast.impl.h"
#include "acl/compression/compression_settings.h"
#include "acl/compression/output_stats.h"
#include "acl/compression/track_array.h"
Expand Down Expand Up @@ -386,7 +387,7 @@ namespace acl
std::memset(buffer, 0, buffer_size);

uint8_t* buffer_start = buffer;
out_compressed_tracks = reinterpret_cast<compressed_tracks*>(buffer);
out_compressed_tracks = bit_cast<compressed_tracks*>(buffer);

raw_buffer_header* buffer_header = safe_ptr_cast<raw_buffer_header>(buffer);
buffer += sizeof(raw_buffer_header);
Expand Down Expand Up @@ -459,7 +460,7 @@ namespace acl
uint32_t written_metadata_contributing_error_size = 0;
if (metadata_size != 0)
{
optional_metadata_header* metadata_header = reinterpret_cast<optional_metadata_header*>(buffer_start + buffer_size - sizeof(optional_metadata_header));
optional_metadata_header* metadata_header = bit_cast<optional_metadata_header*>(buffer_start + buffer_size - sizeof(optional_metadata_header));
uint32_t metadata_offset = metadata_start_offset; // Relative to the start of our compressed_tracks

if (settings.metadata.include_track_list_name)
Expand Down
25 changes: 13 additions & 12 deletions includes/acl/compression/impl/convert.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "acl/core/error_result.h"
#include "acl/core/iallocator.h"
#include "acl/core/track_formats.h"
#include "acl/core/impl/bit_cast.impl.h"
#include "acl/core/impl/debug_track_writer.h"
#include "acl/decompression/decompress.h"

Expand Down Expand Up @@ -173,22 +174,22 @@ namespace acl
switch (track_type)
{
case track_type8::float1f:
*reinterpret_cast<float*>(track_[sample_index]) = writer.read_float1(track_index);
*acl_impl::bit_cast<float*>(track_[sample_index]) = writer.read_float1(track_index);
break;
case track_type8::float2f:
rtm::vector_store2(writer.read_float2(track_index), reinterpret_cast<rtm::float2f*>(track_[sample_index]));
rtm::vector_store2(writer.read_float2(track_index), acl_impl::bit_cast<rtm::float2f*>(track_[sample_index]));
break;
case track_type8::float3f:
rtm::vector_store3(writer.read_float3(track_index), reinterpret_cast<rtm::float3f*>(track_[sample_index]));
rtm::vector_store3(writer.read_float3(track_index), acl_impl::bit_cast<rtm::float3f*>(track_[sample_index]));
break;
case track_type8::float4f:
rtm::vector_store(writer.read_float4(track_index), reinterpret_cast<rtm::float4f*>(track_[sample_index]));
rtm::vector_store(writer.read_float4(track_index), acl_impl::bit_cast<rtm::float4f*>(track_[sample_index]));
break;
case track_type8::vector4f:
*reinterpret_cast<rtm::vector4f*>(track_[sample_index]) = writer.read_vector4(track_index);
*acl_impl::bit_cast<rtm::vector4f*>(track_[sample_index]) = writer.read_vector4(track_index);
break;
case track_type8::qvvf:
*reinterpret_cast<rtm::qvvf*>(track_[sample_index]) = writer.read_qvv(track_index);
*acl_impl::bit_cast<rtm::qvvf*>(track_[sample_index]) = writer.read_qvv(track_index);
break;
default:
ACL_ASSERT(false, "Unexpected track type");
Expand Down Expand Up @@ -223,22 +224,22 @@ namespace acl
switch (track_type)
{
case track_type8::float1f:
*reinterpret_cast<float*>(track_[sample_index]) = writer.read_float1(track_index);
*acl_impl::bit_cast<float*>(track_[sample_index]) = writer.read_float1(track_index);
break;
case track_type8::float2f:
rtm::vector_store2(writer.read_float2(track_index), reinterpret_cast<rtm::float2f*>(track_[sample_index]));
rtm::vector_store2(writer.read_float2(track_index), acl_impl::bit_cast<rtm::float2f*>(track_[sample_index]));
break;
case track_type8::float3f:
rtm::vector_store3(writer.read_float3(track_index), reinterpret_cast<rtm::float3f*>(track_[sample_index]));
rtm::vector_store3(writer.read_float3(track_index), acl_impl::bit_cast<rtm::float3f*>(track_[sample_index]));
break;
case track_type8::float4f:
rtm::vector_store(writer.read_float4(track_index), reinterpret_cast<rtm::float4f*>(track_[sample_index]));
rtm::vector_store(writer.read_float4(track_index), acl_impl::bit_cast<rtm::float4f*>(track_[sample_index]));
break;
case track_type8::vector4f:
*reinterpret_cast<rtm::vector4f*>(track_[sample_index]) = writer.read_vector4(track_index);
*acl_impl::bit_cast<rtm::vector4f*>(track_[sample_index]) = writer.read_vector4(track_index);
break;
case track_type8::qvvf:
*reinterpret_cast<rtm::qvvf*>(track_[sample_index]) = writer.read_qvv(track_index);
*acl_impl::bit_cast<rtm::qvvf*>(track_[sample_index]) = writer.read_qvv(track_index);
break;
default:
ACL_ASSERT(false, "Unexpected track type");
Expand Down
2 changes: 1 addition & 1 deletion includes/acl/compression/impl/pre_process.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ namespace acl
if (context.settings.precision_policy == pre_process_precision_policy::lossless)
return; // This pre-process action is lossy, do nothing

track_array& track_list = context.track_list;
const track_array& track_list = context.track_list;
const track_category8 track_category = track_list.get_track_category();

if (track_category == track_category8::scalarf)
Expand Down
27 changes: 13 additions & 14 deletions includes/acl/compression/impl/track.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "acl/core/track_desc.h"
#include "acl/core/track_traits.h"
#include "acl/core/track_types.h"
#include "acl/core/impl/bit_cast.impl.h"

#include <cstdint>

Expand All @@ -51,8 +52,6 @@ namespace acl
, m_type(track_type8::float1f)
, m_category(track_category8::scalarf)
, m_sample_size(0)
, m_desc()
, m_name()
{}

inline track::track(track&& other) noexcept
Expand Down Expand Up @@ -217,7 +216,7 @@ namespace acl
inline void track::get_copy_impl(iallocator& allocator, track& out_track) const
{
out_track.m_allocator = &allocator;
out_track.m_data = reinterpret_cast<uint8_t*>(allocator.allocate(m_data_size));
out_track.m_data = acl_impl::bit_cast<uint8_t*>(allocator.allocate(m_data_size));
out_track.m_num_samples = m_num_samples;
out_track.m_stride = m_stride;
out_track.m_data_size = m_data_size;
Expand Down Expand Up @@ -250,28 +249,28 @@ namespace acl
inline typename track_typed<track_type_>::sample_type& track_typed<track_type_>::operator[](uint32_t index)
{
ACL_ASSERT(index < m_num_samples, "Invalid sample index. %u >= %u", index, m_num_samples);
return *reinterpret_cast<sample_type*>(m_data + (size_t(index) * m_stride));
return *acl_impl::bit_cast<sample_type*>(m_data + (size_t(index) * m_stride));
}

template<track_type8 track_type_>
inline const typename track_typed<track_type_>::sample_type& track_typed<track_type_>::operator[](uint32_t index) const
{
ACL_ASSERT(index < m_num_samples, "Invalid sample index. %u >= %u", index, m_num_samples);
return *reinterpret_cast<const sample_type*>(m_data + (size_t(index) * m_stride));
return *acl_impl::bit_cast<const sample_type*>(m_data + (size_t(index) * m_stride));
}

template<track_type8 track_type_>
inline typename track_typed<track_type_>::sample_type* track_typed<track_type_>::get_data()
{
ACL_ASSERT(m_stride == sizeof(sample_type), "Samples are not contiguous in memory, this function is unsafe");
return reinterpret_cast<sample_type*>(m_data);
return acl_impl::bit_cast<sample_type*>(m_data);
}

template<track_type8 track_type_>
inline const typename track_typed<track_type_>::sample_type* track_typed<track_type_>::get_data() const
{
ACL_ASSERT(m_stride == sizeof(sample_type), "Samples are not contiguous in memory, this function is unsafe");
return reinterpret_cast<const sample_type*>(m_data);
return acl_impl::bit_cast<const sample_type*>(m_data);
}

template<track_type8 track_type_>
Expand Down Expand Up @@ -307,35 +306,35 @@ namespace acl
{
const size_t num_samples_ = num_samples;
const size_t data_size = num_samples_ * sizeof(sample_type);
const uint8_t* data_raw = reinterpret_cast<const uint8_t*>(data);
const uint8_t* data_raw = acl_impl::bit_cast<const uint8_t*>(data);

// Copy the data manually to avoid preserving the stride
sample_type* data_copy = reinterpret_cast<sample_type*>(allocator.allocate(data_size));
sample_type* data_copy = acl_impl::bit_cast<sample_type*>(allocator.allocate(data_size));
for (size_t index = 0; index < num_samples_; ++index)
data_copy[index] = *reinterpret_cast<const sample_type*>(data_raw + (index * stride));
data_copy[index] = *acl_impl::bit_cast<const sample_type*>(data_raw + (index * stride));

return track_typed<track_type_>(&allocator, reinterpret_cast<uint8_t*>(data_copy), num_samples, sizeof(sample_type), data_size, sample_rate, desc);
return track_typed<track_type_>(&allocator, acl_impl::bit_cast<uint8_t*>(data_copy), num_samples, sizeof(sample_type), data_size, sample_rate, desc);
}

template<track_type8 track_type_>
inline track_typed<track_type_> track_typed<track_type_>::make_reserve(const typename track_typed<track_type_>::desc_type& desc, iallocator& allocator, uint32_t num_samples, float sample_rate)
{
const size_t data_size = size_t(num_samples) * sizeof(sample_type);
return track_typed<track_type_>(&allocator, reinterpret_cast<uint8_t*>(allocator.allocate(data_size)), num_samples, sizeof(sample_type), data_size, sample_rate, desc);
return track_typed<track_type_>(&allocator, acl_impl::bit_cast<uint8_t*>(allocator.allocate(data_size)), num_samples, sizeof(sample_type), data_size, sample_rate, desc);
}

template<track_type8 track_type_>
inline track_typed<track_type_> track_typed<track_type_>::make_owner(const typename track_typed<track_type_>::desc_type& desc, iallocator& allocator, sample_type* data, uint32_t num_samples, float sample_rate, uint32_t stride)
{
const size_t data_size = size_t(num_samples) * stride;
return track_typed<track_type_>(&allocator, reinterpret_cast<uint8_t*>(data), num_samples, stride, data_size, sample_rate, desc);
return track_typed<track_type_>(&allocator, acl_impl::bit_cast<uint8_t*>(data), num_samples, stride, data_size, sample_rate, desc);
}

template<track_type8 track_type_>
inline track_typed<track_type_> track_typed<track_type_>::make_ref(const typename track_typed<track_type_>::desc_type& desc, sample_type* data, uint32_t num_samples, float sample_rate, uint32_t stride)
{
const size_t data_size = size_t(num_samples) * stride;
return track_typed<track_type_>(nullptr, reinterpret_cast<uint8_t*>(data), num_samples, stride, data_size, sample_rate, desc);
return track_typed<track_type_>(nullptr, acl_impl::bit_cast<uint8_t*>(data), num_samples, stride, data_size, sample_rate, desc);
}

template<track_type8 track_type_>
Expand Down
5 changes: 2 additions & 3 deletions includes/acl/compression/impl/track_array.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,20 @@ namespace acl
, m_tracks(nullptr)
, m_num_tracks(0)
, m_looping_policy(sample_looping_policy::non_looping)
, m_name()
{}

inline track_array::track_array(iallocator& allocator, uint32_t num_tracks)
: m_allocator(&allocator)
, m_tracks(allocate_type_array<track>(allocator, num_tracks))
, m_num_tracks(num_tracks)
, m_looping_policy(sample_looping_policy::non_looping)
, m_name()
{}

inline track_array::track_array(track_array&& other) noexcept
: m_allocator(other.m_allocator)
, m_tracks(other.m_tracks)
, m_num_tracks(other.m_num_tracks)
, m_looping_policy(sample_looping_policy::non_looping)
, m_looping_policy(other.m_looping_policy)
, m_name(std::move(other.m_name))
{
other.m_allocator = nullptr; // Make sure we don't free our data since we no longer own it
Expand All @@ -82,6 +80,7 @@ namespace acl
std::swap(m_allocator, other.m_allocator);
std::swap(m_tracks, other.m_tracks);
std::swap(m_num_tracks, other.m_num_tracks);
std::swap(m_looping_policy, other.m_looping_policy);
std::swap(m_name, other.m_name);
return *this;
}
Expand Down
Loading
Loading