Skip to content

Commit 398c8ef

Browse files
committed
Resolve clang-tidy 19.1 warnings
1 parent 2307157 commit 398c8ef

8 files changed

+21
-17
lines changed

.clang-tidy

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) Team CharLS.
1+
# SPDX-FileCopyrightText: © 2020 Team CharLS
22
# SPDX-License-Identifier: BSD-3-Clause
33

44
# The approach for using clang tidy is to enable all warnings unless it adds no practical value to the CharLS projects
@@ -57,6 +57,7 @@
5757
# -altera-id-dependent-backward-branch => Does not apply (is for openCL)
5858
# -bugprone-easily-swappable-parameters => To many do not fix warnings
5959
# -performance-enum-size => No performance gain, enums are not used in arrays.
60+
# -boost-use-ranges => CharLS has by design not a dependency on Boost.
6061

6162
---
6263
Checks: '*,
@@ -112,7 +113,8 @@ Checks: '*,
112113
-readability-function-cognitive-complexity,
113114
-bugprone-easily-swappable-parameters,
114115
-concurrency-mt-unsafe,
115-
-performance-enum-size'
116+
-performance-enum-size,
117+
-boost-use-ranges'
116118
WarningsAsErrors: false
117119
HeaderFilterRegex: ''
118120
FormatStyle: none

Directory.Build.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
C5026 = 'type': move constructor was implicitly defined as deleted [Just informational]
5656
C5027 = 'type': move assignment operator was implicitly defined as deleted [Just informational]
5757
C5045 = Compiler will insert Spectre mitigation for memory load if /Qspectre switch specified [Just informational]
58-
C5246 = the initialization of a subobject should be wrapped in braces [prevents simple usage of std::byte]
58+
C5246 = the initialization of a sub-object should be wrapped in braces [prevents simple usage of std::byte]
5959
C5264 = 'const' variable is not used [reported for const in header files]
6060
C5258 = explicit capture of '' is not required for this use [VS 2019 requires capture of constexpr]
6161
-->

samples/convert.c/main.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,11 @@ static void triplet_to_planar(const uint8_t* triplet_buffer, uint8_t* planar_buf
149149
const size_t line_start = line * stride;
150150
for (size_t pixel = 0; pixel < width; ++pixel)
151151
{
152-
const size_t column = line_start + pixel * bytes_per_rgb_pixel;
152+
const size_t column = line_start + (pixel * bytes_per_rgb_pixel);
153153

154154
planar_buffer[plane_column] = triplet_buffer[column];
155-
planar_buffer[plane_column + 1 * byte_count_plane] = triplet_buffer[column + 1];
156-
planar_buffer[plane_column + 2 * byte_count_plane] = triplet_buffer[column + 2];
155+
planar_buffer[plane_column + (1 * byte_count_plane)] = triplet_buffer[column + 1];
156+
planar_buffer[plane_column + (2 * byte_count_plane)] = triplet_buffer[column + 2];
157157
++plane_column;
158158
}
159159
}
@@ -428,6 +428,7 @@ int main(const int argc, char* argv[])
428428
if (!convert_bottom_up_to_top_down(pixel_data, dib_header.width, (size_t)dib_header.height, stride))
429429
{
430430
printf("Failed to convert the pixels from bottom up to top down\n");
431+
free(pixel_data);
431432
return EXIT_FAILURE;
432433
}
433434
}

samples/convert.cpp/main.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ std::vector<uint8_t> triplet_to_planar(const std::vector<uint8_t>& buffer, const
4242
const auto line_start{line * stride};
4343
for (size_t pixel{}; pixel != width; ++pixel)
4444
{
45-
const auto column{line_start + pixel * bytes_per_rgb_pixel};
45+
const auto column{line_start + (pixel * bytes_per_rgb_pixel)};
4646
result[plane_column] = buffer[column];
47-
result[plane_column + 1 * byte_count_plane] = buffer[column + 1];
48-
result[plane_column + 2 * byte_count_plane] = buffer[column + 2];
47+
result[plane_column + (1 * byte_count_plane)] = buffer[column + 1];
48+
result[plane_column + (2 * byte_count_plane)] = buffer[column + 2];
4949
++plane_column;
5050
}
5151
}

src/jpeg_stream_reader.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -517,19 +517,19 @@ void jpeg_stream_reader::read_oversize_image_dimension()
517517
switch (dimension_size)
518518
{
519519
case 2:
520-
check_segment_size(pc_and_dimension_bytes + sizeof(uint16_t) * 2);
520+
check_segment_size(pc_and_dimension_bytes + (sizeof(uint16_t) * 2));
521521
height = read_uint16();
522522
width = read_uint16();
523523
break;
524524

525525
case 3:
526-
check_segment_size(pc_and_dimension_bytes + (sizeof(uint16_t) + 1) * 2);
526+
check_segment_size(pc_and_dimension_bytes + ((sizeof(uint16_t) + 1) * 2));
527527
height = read_uint24();
528528
width = read_uint24();
529529
break;
530530

531531
case 4:
532-
check_segment_size(pc_and_dimension_bytes + sizeof(uint32_t) * 2);
532+
check_segment_size(pc_and_dimension_bytes + (sizeof(uint32_t) * 2));
533533
height = read_uint32();
534534
width = read_uint32();
535535
break;

src/jpeg_stream_writer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ void jpeg_stream_writer::write_application_data_segment(const int32_t applicatio
139139

140140
void jpeg_stream_writer::write_jpegls_preset_parameters_segment(const jpegls_pc_parameters& preset_coding_parameters)
141141
{
142-
write_segment_header(jpeg_marker_code::jpegls_preset_parameters, 1 + 5 * sizeof(uint16_t));
142+
write_segment_header(jpeg_marker_code::jpegls_preset_parameters, 1 + (5 * sizeof(uint16_t)));
143143
write_uint8(to_underlying_type(jpegls_preset_parameters_type::preset_coding_parameters));
144144
write_uint16(preset_coding_parameters.maximum_sample_value);
145145
write_uint16(preset_coding_parameters.threshold1);
@@ -152,7 +152,7 @@ void jpeg_stream_writer::write_jpegls_preset_parameters_segment(const jpegls_pc_
152152
void jpeg_stream_writer::write_jpegls_preset_parameters_segment(const uint32_t height, const uint32_t width)
153153
{
154154
// Format is defined in ISO/IEC 14495-1, C.2.4.1.4
155-
write_segment_header(jpeg_marker_code::jpegls_preset_parameters, size_t{1} + 1 + 2 * sizeof(uint32_t));
155+
write_segment_header(jpeg_marker_code::jpegls_preset_parameters, size_t{1} + 1 + (2 * sizeof(uint32_t)));
156156
write_uint8(to_underlying_type(jpegls_preset_parameters_type::oversize_image_dimension));
157157
write_uint8(sizeof(uint32_t)); // Wxy: number of bytes used to represent Ye and Xe [2..4]. Always 4 for simplicity.
158158
write_uint32(height); // Ye: number of lines in the image.

src/quantization_lut.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "quantization_lut.hpp"
77

88
#include <charls/public_types.h>
9+
910
#include "jpegls_algorithm.hpp"
1011
#include "jpegls_preset_coding_parameters.hpp"
1112

test/compliance.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ void triplet2_planar(vector<byte>& buffer, const rect_size size)
4141
const size_t byte_count{size.cx * size.cy};
4242
for (size_t i{}; i != byte_count; ++i)
4343
{
44-
work_buffer[i] = buffer[i * 3 + 0];
45-
work_buffer[i + 1 * byte_count] = buffer[i * 3 + 1];
46-
work_buffer[i + 2 * byte_count] = buffer[i * 3 + 2];
44+
work_buffer[i] = buffer[i * 3];
45+
work_buffer[i + (1 * byte_count)] = buffer[(i * 3) + 1];
46+
work_buffer[i + (2 * byte_count)] = buffer[(i * 3) + 2];
4747
}
4848
swap(buffer, work_buffer);
4949
}

0 commit comments

Comments
 (0)