[med-svn] [Git][med-team/charls][upstream] New upstream version 2.3.2+dfsg

Mathieu Malaterre (@malat) gitlab at salsa.debian.org
Mon Jan 31 12:43:54 GMT 2022



Mathieu Malaterre pushed to branch upstream at Debian Med / charls


Commits:
5f56f16a by Mathieu Malaterre at 2022-01-31T13:33:53+01:00
New upstream version 2.3.2+dfsg
- - - - -


14 changed files:

- CHANGELOG.md
- CMakeLists.txt
- CharLS.sln.DotSettings
- SECURITY.md
- fuzztest/main.cpp
- include/charls/version.h
- src/CMakeLists.txt
- + src/charls.version
- src/color_transform.h
- + src/conditional_static_cast.h
- src/jpegls.cpp
- src/lookup_table.h
- test/performance.cpp
- unittest/util.cpp


Changes:

=====================================
CHANGELOG.md
=====================================
@@ -4,6 +4,19 @@ All notable changes to this project are documented in this file.
 
 The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
 
+## [2.3.2] - 2021-1-29
+
+### Fixed
+
+- Fixed [#160](https://github.com/team-charls/charls/issues/160), warning: cast from ‘unsigned char*’ to ‘uint16_t*’ increases required alignment of target type
+- Fixed [#161](https://github.com/team-charls/charls/issues/161), warning: useless cast to type ‘size_t’ {aka ‘unsigned int’} [-Wuseless-cast]
+
+### Changed
+
+- Updates to the CMakeLists.txt for Unix builds (except macOS) to hide more symbols from the shared library.
+- C++14 is now the minimum version instead of explicitly required. This allows consuming applications more flexibility.
+Typically CMake will select the latest C++ standard version that used C++ compiler supports.
+
 ## [2.3.1] - 2021-1-25
 
 ### Fixed


=====================================
CMakeLists.txt
=====================================
@@ -36,9 +36,7 @@ option(BUILD_SHARED_LIBS "Will control if charls lib is build as shared lib/DLL
 option(CHARLS_PEDANTIC_WARNINGS "Enable extra warnings and static analysis." OFF)
 option(CHARLS_TREAT_WARNING_AS_ERROR "Treat a warning as an error." OFF)
 
-# CharLS requires C++14 or newer.
-set(CMAKE_CXX_STANDARD 14)
-set(CMAKE_CXX_STANDARD_REQUIRED ON)
+# CharLS is written in portable c++:
 set(CMAKE_CXX_EXTENSIONS OFF)
 
 # Configure the supported C++ compilers: gcc, clang and MSVC
@@ -73,6 +71,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
     -Wvector-operation-performance
     -Wsized-deallocation
     -Wattributes
+    -Wuseless-cast
   )
   if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0)
       set(PEDANTIC_CXX_COMPILE_FLAGS ${PEDANTIC_CXX_COMPILE_FLAGS}
@@ -81,6 +80,11 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
         -Wduplicated-cond
       )
   endif()
+  if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0)
+      set(PEDANTIC_CXX_COMPILE_FLAGS ${PEDANTIC_CXX_COMPILE_FLAGS}
+        -Wcast-align=strict
+      )
+  endif()
 
   set(WARNINGS_AS_ERRORS_FLAG_COMPILER -Werror)
   set(WARNINGS_AS_ERRORS_FLAG_LINKER LINKER:--fatal-warnings)
@@ -92,7 +96,6 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
       -Wextra # (-W is synonym)
       -Wnon-gcc
       -Wpedantic
-      -Walloca
       -Wcast-qual
       -Wformat=2
       -Wvla
@@ -128,6 +131,11 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
       -Wno-undefined-func-template            # Ignore, linker will complain if final template code is not available.
     )
   endif()
+  if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10.0)
+    set(PEDANTIC_CXX_COMPILE_FLAGS ${PEDANTIC_CXX_COMPILE_FLAGS}
+      -Walloca
+    )
+  endif()
 
   set(WARNINGS_AS_ERRORS_FLAG_COMPILER -Werror)
   if (NOT CMAKE_CXX_COMPILER_ID MATCHES "AppleClang")


=====================================
CharLS.sln.DotSettings
=====================================
@@ -44,6 +44,7 @@
 	<s:Boolean x:Key="/Default/UserDictionary/Words/=anymap/@EntryIndexedValue">True</s:Boolean>
 	<s:Boolean x:Key="/Default/UserDictionary/Words/=banny/@EntryIndexedValue">True</s:Boolean>
 	<s:Boolean x:Key="/Default/UserDictionary/Words/=Bgra/@EntryIndexedValue">True</s:Boolean>
+	<s:Boolean x:Key="/Default/UserDictionary/Words/=Braun/@EntryIndexedValue">True</s:Boolean>
 	<s:Boolean x:Key="/Default/UserDictionary/Words/=bugprone/@EntryIndexedValue">True</s:Boolean>
 	<s:Boolean x:Key="/Default/UserDictionary/Words/=byteswap/@EntryIndexedValue">True</s:Boolean>
 	<s:Boolean x:Key="/Default/UserDictionary/Words/=CHARLS/@EntryIndexedValue">True</s:Boolean>
@@ -70,6 +71,7 @@
 	<s:Boolean x:Key="/Default/UserDictionary/Words/=grayscale/@EntryIndexedValue">True</s:Boolean>
 	<s:Boolean x:Key="/Default/UserDictionary/Words/=hicpp/@EntryIndexedValue">True</s:Boolean>
 	<s:Boolean x:Key="/Default/UserDictionary/Words/=HRES/@EntryIndexedValue">True</s:Boolean>
+	<s:Boolean x:Key="/Default/UserDictionary/Words/=Intelli/@EntryIndexedValue">True</s:Boolean>
 	<s:Boolean x:Key="/Default/UserDictionary/Words/=jbig/@EntryIndexedValue">True</s:Boolean>
 	<s:Boolean x:Key="/Default/UserDictionary/Words/=jfif/@EntryIndexedValue">True</s:Boolean>
 	<s:Boolean x:Key="/Default/UserDictionary/Words/=jpegls/@EntryIndexedValue">True</s:Boolean>


=====================================
SECURITY.md
=====================================
@@ -4,7 +4,8 @@
 
 | Version | Supported          |
 | ------- | ------------------ |
-| 2.3.1   | :white_check_mark: |
+| 2.3.2   | :white_check_mark: |
+| 2.3.1   | :x:                |
 | 2.3.0   | :x:                |
 | 2.2.0   | :x:                |
 | 2.1.0   | :x:                |


=====================================
fuzztest/main.cpp
=====================================
@@ -3,6 +3,8 @@
 
 #include <charls/charls.h>
 
+#include "../src/conditional_static_cast.h"
+
 #ifdef _MSC_VER
 #include <io.h>
 #else
@@ -19,6 +21,9 @@
 #include <iostream>
 #include <vector>
 
+using namespace charls;
+using std::vector;
+
 #if defined(__clang__)
 #pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wreserved-id-macro"
@@ -39,14 +44,14 @@
 
 namespace {
 
-std::vector<uint8_t> generate_once()
+vector<uint8_t> generate_once()
 {
-    const std::vector<uint8_t> source(3);
+    const vector<uint8_t> source(3);
 
-    charls::jpegls_encoder encoder;
+    jpegls_encoder encoder;
     encoder.frame_info({1, 1, 8, 3});
 
-    std::vector<uint8_t> destination(encoder.estimated_destination_size());
+    vector<uint8_t> destination(encoder.estimated_destination_size());
     encoder.destination(destination);
 
     const size_t bytes_written{encoder.encode(source)};
@@ -70,9 +75,10 @@ int main(const int argc, const char* const argv[]) // NOLINT(bugprone-exception-
                 // Write some small-ish JPEG-LS file to stdout
                 const auto encoded_data{generate_once()};
 #ifdef _MSC_VER
-                const int result{_write(1, encoded_data.data(), static_cast<unsigned int>(encoded_data.size()))};
+                const int result{_write(1, encoded_data.data(), conditional_static_cast<unsigned int>(encoded_data.size()))};
 #else
-                const ssize_t result{write(1, encoded_data.data(), static_cast<unsigned int>(encoded_data.size()))};
+                const ssize_t result{
+                    write(1, encoded_data.data(), conditional_static_cast<unsigned int>(encoded_data.size()))};
 #endif
                 return result != -1 && result == static_cast<int>(encoded_data.size()) ? EXIT_SUCCESS : EXIT_FAILURE;
             }
@@ -95,16 +101,16 @@ int main(const int argc, const char* const argv[]) // NOLINT(bugprone-exception-
 
     while (__AFL_LOOP(100))
     {
-        std::vector<uint8_t> source(static_cast<size_t>(1024) * 1024);
-        const size_t input_length = _read(fd, source.data(), static_cast<unsigned int>(source.size()));
+        vector<uint8_t> source(static_cast<size_t>(1024) * 1024);
+        const size_t input_length = _read(fd, source.data(), charls::conditional_static_cast<unsigned int>(source.size()));
         source.resize(input_length);
 
         try
         {
-            std::vector<uint8_t> destination;
-            charls::jpegls_decoder::decode(source, destination);
+            vector<uint8_t> destination;
+            jpegls_decoder::decode(source, destination);
         }
-        catch (const charls::jpegls_error&)
+        catch (const jpegls_error&)
         {
         }
     }


=====================================
include/charls/version.h
=====================================
@@ -16,7 +16,7 @@ extern "C" {
 
 #define CHARLS_VERSION_MAJOR 2
 #define CHARLS_VERSION_MINOR 3
-#define CHARLS_VERSION_PATCH 1
+#define CHARLS_VERSION_PATCH 2
 
 /// <summary>
 /// Returns the version of CharLS in the semver format "major.minor.patch" or "major.minor.patch-pre_release"


=====================================
src/CMakeLists.txt
=====================================
@@ -48,6 +48,8 @@ set_target_properties(charls PROPERTIES
                       SOVERSION ${PROJECT_VERSION_MAJOR})
 
 target_compile_definitions(charls PRIVATE CHARLS_LIBRARY_BUILD)
+# CharLS requires C++14 or newer.
+target_compile_features(charls PUBLIC cxx_std_14)
 
 set(HEADERS
     "include/charls/api_abi.h"
@@ -65,8 +67,16 @@ foreach(header HEADERS)
 endforeach()
 
 set_target_properties(charls PROPERTIES CXX_VISIBILITY_PRESET hidden)
+set_target_properties(charls PROPERTIES VISIBILITY_INLINES_HIDDEN 1)
 set_property(TARGET charls PROPERTY PUBLIC_HEADER ${HEADERS})
 
+set_target_properties(charls PROPERTIES
+  LINK_DEPENDS ${CMAKE_CURRENT_LIST_DIR}/charls.version)
+if(UNIX AND NOT APPLE)
+  set_property(TARGET charls APPEND_STRING PROPERTY
+    LINK_FLAGS " -Wl,--version-script=${CMAKE_CURRENT_LIST_DIR}/charls.version")
+endif()
+
 target_sources(charls
   PUBLIC
     ${CHARLS_PUBLIC_HEADERS}
@@ -76,6 +86,7 @@ target_sources(charls
     "${CMAKE_CURRENT_LIST_DIR}/charls_jpegls_encoder.cpp"
     "${CMAKE_CURRENT_LIST_DIR}/coding_parameters.h"
     "${CMAKE_CURRENT_LIST_DIR}/color_transform.h"
+    "${CMAKE_CURRENT_LIST_DIR}/conditional_static_cast.h"
     "${CMAKE_CURRENT_LIST_DIR}/constants.h"
     "${CMAKE_CURRENT_LIST_DIR}/context_regular_mode.h"
     "${CMAKE_CURRENT_LIST_DIR}/context_run_mode.h"


=====================================
src/charls.version
=====================================
@@ -0,0 +1,21 @@
+{
+  global:
+    JpegLs*;
+    charls_*;
+    extern "C++" {
+      JpegLs*;
+      charls_*;
+    };
+  local:
+    # Hide all the std namespace symbols. std namespace is explicitly marked
+    # as visibility(default) and header-only functions or methods (such as those
+    # from templates) should be exposed in shared libraries as weak symbols but
+    # this is only needed when we expose those types in the shared library API
+    # in any way. We don't use C++ std types in the API and we also don't
+    # support exceptions in the library.
+    # See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=36022 for a discussion
+    # about this.
+    extern "C++" {
+      *std::*;
+    };
+};


=====================================
src/color_transform.h
=====================================
@@ -49,7 +49,7 @@ struct transform_hp1 final
 
         FORCE_INLINE triplet<T> operator()(const int v1, const int v2, const int v3) const noexcept
         {
-            return triplet<T>(v1 + v2 - Range / 2, v2, v3 + v2 - Range / 2);
+            return triplet<T>(v1 + v2 - range_ / 2, v2, v3 + v2 - range_ / 2);
         }
     };
 
@@ -57,13 +57,13 @@ struct transform_hp1 final
     {
         triplet<T> hp1;
         hp1.v2 = static_cast<T>(green);
-        hp1.v1 = static_cast<T>(red - green + Range / 2);
-        hp1.v3 = static_cast<T>(blue - green + Range / 2);
+        hp1.v1 = static_cast<T>(red - green + range_ / 2);
+        hp1.v3 = static_cast<T>(blue - green + range_ / 2);
         return hp1;
     }
 
 private:
-    static constexpr size_t Range = 1 << (sizeof(T) * 8);
+    static constexpr size_t range_{1 << (sizeof(T) * 8)};
 };
 
 
@@ -83,20 +83,20 @@ struct transform_hp2 final
         FORCE_INLINE triplet<T> operator()(const int v1, const int v2, const int v3) const noexcept
         {
             triplet<T> rgb;
-            rgb.R = static_cast<T>(v1 + v2 - Range / 2);                     // new R
+            rgb.R = static_cast<T>(v1 + v2 - range_ / 2);                     // new R
             rgb.G = static_cast<T>(v2);                                      // new G
-            rgb.B = static_cast<T>(v3 + ((rgb.R + rgb.G) >> 1) - Range / 2); // new B
+            rgb.B = static_cast<T>(v3 + ((rgb.R + rgb.G) >> 1) - range_ / 2); // new B
             return rgb;
         }
     };
 
     FORCE_INLINE triplet<T> operator()(const int red, const int green, const int blue) const noexcept
     {
-        return triplet<T>(red - green + Range / 2, green, blue - ((red + green) >> 1) - Range / 2);
+        return triplet<T>(red - green + range_ / 2, green, blue - ((red + green) >> 1) - range_ / 2);
     }
 
 private:
-    static constexpr size_t Range = 1 << (sizeof(T) * 8);
+    static constexpr size_t range_{1 << (sizeof(T) * 8)};
 };
 
 
@@ -115,11 +115,11 @@ struct transform_hp3 final
 
         FORCE_INLINE triplet<T> operator()(const int v1, const int v2, const int v3) const noexcept
         {
-            const int g = v1 - ((v3 + v2) >> 2) + Range / 4;
+            const int g = v1 - ((v3 + v2) >> 2) + range_ / 4;
             triplet<T> rgb;
-            rgb.R = static_cast<T>(v3 + g - Range / 2); // new R
+            rgb.R = static_cast<T>(v3 + g - range_ / 2); // new R
             rgb.G = static_cast<T>(g);                  // new G
-            rgb.B = static_cast<T>(v2 + g - Range / 2); // new B
+            rgb.B = static_cast<T>(v2 + g - range_ / 2); // new B
             return rgb;
         }
     };
@@ -127,14 +127,14 @@ struct transform_hp3 final
     FORCE_INLINE triplet<T> operator()(const int red, const int green, const int blue) const noexcept
     {
         triplet<T> hp3;
-        hp3.v2 = static_cast<T>(blue - green + Range / 2);
-        hp3.v3 = static_cast<T>(red - green + Range / 2);
-        hp3.v1 = static_cast<T>(green + ((hp3.v2 + hp3.v3) >> 2)) - Range / 4;
+        hp3.v2 = static_cast<T>(blue - green + range_ / 2);
+        hp3.v3 = static_cast<T>(red - green + range_ / 2);
+        hp3.v1 = static_cast<T>(green + ((hp3.v2 + hp3.v3) >> 2)) - range_ / 4;
         return hp3;
     }
 
 private:
-    static constexpr size_t Range = 1 << (sizeof(T) * 8);
+    static constexpr size_t range_{1 << (sizeof(T) * 8)};
 };
 
 } // namespace charls


=====================================
src/conditional_static_cast.h
=====================================
@@ -0,0 +1,25 @@
+// Copyright (c) Team CharLS.
+// SPDX-License-Identifier: BSD-3-Clause
+
+#pragma once
+
+#include <type_traits>
+
+// Some cross platform builds require an explicit static_cast, while others don't.
+// These templates can be used to keep code compatible with the GCC useless-cast warning and ReSharper.
+
+namespace charls {
+
+template<typename T, typename U, std::enable_if_t<!std::is_same<T, U>::value, int> = 0>
+T conditional_static_cast(U value) noexcept
+{
+    return static_cast<T>(value);
+}
+
+template<typename T, typename U, std::enable_if_t<std::is_same<T, U>::value, int> = 0>
+T conditional_static_cast(U value) noexcept
+{
+    return value;
+}
+
+} // namespace charls


=====================================
src/jpegls.cpp
=====================================
@@ -1,6 +1,7 @@
 // Copyright (c) Team CharLS.
 // SPDX-License-Identifier: BSD-3-Clause
 
+#include "conditional_static_cast.h"
 #include "default_traits.h"
 #include "encoder_strategy.h"
 #include "jls_codec_factory.h"
@@ -85,7 +86,7 @@ golomb_code_table initialize_table(const int32_t k) noexcept
         if (static_cast<size_t>(pair_code.first) > golomb_code_table::byte_bit_count)
             break;
 
-        const golomb_code code(error_value, static_cast<int16_t>(pair_code.first));
+        const golomb_code code(error_value, conditional_static_cast<int16_t>(pair_code.first));
         table.add_entry(static_cast<uint8_t>(pair_code.second), code);
     }
 
@@ -148,17 +149,15 @@ unique_ptr<Strategy> jls_codec_factory<Strategy>::create_codec(const frame_info&
     {
         if (frame.bits_per_sample <= 8)
         {
-            default_traits<uint8_t, uint8_t> traits(
-                calculate_maximum_sample_value(frame.bits_per_sample), parameters.near_lossless,
-                preset_coding_parameters.reset_value);
+            default_traits<uint8_t, uint8_t> traits(calculate_maximum_sample_value(frame.bits_per_sample),
+                                                    parameters.near_lossless, preset_coding_parameters.reset_value);
             traits.maximum_sample_value = preset_coding_parameters.maximum_sample_value;
             codec = make_unique<jls_codec<default_traits<uint8_t, uint8_t>, Strategy>>(traits, frame, parameters);
         }
         else
         {
-            default_traits<uint16_t, uint16_t> traits(
-                calculate_maximum_sample_value(frame.bits_per_sample), parameters.near_lossless,
-                preset_coding_parameters.reset_value);
+            default_traits<uint16_t, uint16_t> traits(calculate_maximum_sample_value(frame.bits_per_sample),
+                                                      parameters.near_lossless, preset_coding_parameters.reset_value);
             traits.maximum_sample_value = preset_coding_parameters.maximum_sample_value;
             codec = make_unique<jls_codec<default_traits<uint16_t, uint16_t>, Strategy>>(traits, frame, parameters);
         }
@@ -170,7 +169,7 @@ unique_ptr<Strategy> jls_codec_factory<Strategy>::create_codec(const frame_info&
 
 template<typename Strategy>
 unique_ptr<Strategy> jls_codec_factory<Strategy>::try_create_optimized_codec(const frame_info& frame,
-                                                                         const coding_parameters& parameters)
+                                                                             const coding_parameters& parameters)
 {
     if (parameters.interleave_mode == interleave_mode::sample && frame.component_count != 3 && frame.component_count != 4)
         return nullptr;


=====================================
src/lookup_table.h
=====================================
@@ -3,6 +3,7 @@
 
 #pragma once
 
+#include "conditional_static_cast.h"
 #include "util.h"
 
 #include <array>
@@ -45,7 +46,7 @@ public:
         const uint32_t length{c.length()};
         ASSERT(static_cast<size_t>(length) <= byte_bit_count);
 
-        for (size_t i{}; i < static_cast<size_t>(1U) << (byte_bit_count - length); ++i)
+        for (size_t i{}; i < conditional_static_cast<size_t>(1U) << (byte_bit_count - length); ++i)
         {
             ASSERT(types_[(static_cast<size_t>(value) << (byte_bit_count - length)) + i].length() == 0);
             types_[(static_cast<size_t>(value) << (byte_bit_count - length)) + i] = c;


=====================================
test/performance.cpp
=====================================
@@ -31,7 +31,9 @@ void test_file16_bit_as12(const char* filename, const int offset, const rect_siz
     vector<uint8_t> uncompressed_data{read_file(filename, offset)};
     fix_endian(&uncompressed_data, little_endian_file);
 
-    auto* const p{reinterpret_cast<uint16_t*>(uncompressed_data.data())};
+    // Dynamic allocated memory is properly aligned: safe to use void*
+    void* const data{uncompressed_data.data()};
+    auto* const p{static_cast<uint16_t*>(data)};
     for (size_t i{}; i != uncompressed_data.size() / 2; ++i)
     {
         p[i] = p[i] >> 4;


=====================================
unittest/util.cpp
=====================================
@@ -272,8 +272,10 @@ void test_compliance(const vector<uint8_t>& encoded_source, const vector<uint8_t
         }
         else
         {
-            const auto* source16 = reinterpret_cast<const uint16_t*>(uncompressed_source.data());
-            const auto* destination16 = reinterpret_cast<const uint16_t*>(destination.data());
+            const void* data{uncompressed_source.data()};
+            const auto* source16{static_cast<const uint16_t*>(data)};
+            data = destination.data();
+            const auto* destination16{static_cast<const uint16_t*>(data)};
 
             for (size_t i{}; i != uncompressed_source.size() / 2; ++i)
             {



View it on GitLab: https://salsa.debian.org/med-team/charls/-/commit/5f56f16ae9b94bac958f47727baa6c4145f36d39

-- 
View it on GitLab: https://salsa.debian.org/med-team/charls/-/commit/5f56f16ae9b94bac958f47727baa6c4145f36d39
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/debian-med-commit/attachments/20220131/b67a6d0f/attachment-0001.htm>


More information about the debian-med-commit mailing list