Package: valentina
Version: 1.0.0~dfsg-4
Severity: normal
Tags: patch ftbfs
User: [email protected]
Usertags: origin-ubuntu resolute ubuntu-patch

Dear Maintainer,

https://launchpadlibrarian.net/835569381/buildlog_ubuntu-resolute-riscv64.valentina_1.0.0~dfsg-4_BUILDING.txt.gz

shows a build failure on riscv64 due to incorrect alignments:

/src/libs/vdxf/libdxfrw/intern/dxfreader.cpp:121:14:
error: cast from ‘char*’ to ‘short unsigned int*’
increases required alignment of target type [-Werror=cast-align]

The upstream MR https://gitlab.com/smart-pattern/valentina/-/merge_requests/22
fixes the issue.

Ubuntu handles this in
https://bugs.launchpad.net/ubuntu/+source/valentina/+bug/2134600

Thanks for considering the patch.


-- System Information:
Debian Release: forky/sid
  APT prefers resolute
  APT policy: (500, 'resolute')
Architecture: amd64 (x86_64)
Foreign Architectures: i386, riscv64

Kernel: Linux 6.17.0-6-generic (SMP w/32 CPU threads; PREEMPT)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled
diff -Nru 
valentina-1.0.0~dfsg/debian/patches/0001-libdxfrw-avoid-alignment-errors-in-dxfreader.cpp.patch
 
valentina-1.0.0~dfsg/debian/patches/0001-libdxfrw-avoid-alignment-errors-in-dxfreader.cpp.patch
--- 
valentina-1.0.0~dfsg/debian/patches/0001-libdxfrw-avoid-alignment-errors-in-dxfreader.cpp.patch
     1970-01-01 01:00:00.000000000 +0100
+++ 
valentina-1.0.0~dfsg/debian/patches/0001-libdxfrw-avoid-alignment-errors-in-dxfreader.cpp.patch
     2025-12-11 18:42:38.000000000 +0100
@@ -0,0 +1,111 @@
+From: Heinrich Schuchardt <[email protected]>
+Date: Thu, 11 Dec 2025 18:33:39 +0100
+Subject: [PATCH 1/4] libdxfrw: avoid alignment errors in dxfreader.cpp
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Reinterpret_cast is only allowable if the from type satisfies the alignment
+requirement of the target. Using GCC 15.2 on RISC-V the current code of
+dxfreader leads to errors like
+
+    dxfreader.cpp:121:14: error: cast from ‘char*’ to ‘short unsigned int*’
+    increases required alignment of target type [-Werror=cast-align]
+
+We can avoid reinterpret_cast by using unions.
+
+Signed-off-by: Heinrich Schuchardt <[email protected]>
+Origin: 
https://gitlab.com/smart-pattern/valentina/-/commit/8b3fb765bebc858566e041448473bb0582df4f21
+---
+ src/libs/vdxf/libdxfrw/intern/dxfreader.cpp | 50 +++++++++++----------
+ 1 file changed, 26 insertions(+), 24 deletions(-)
+
+diff --git a/src/libs/vdxf/libdxfrw/intern/dxfreader.cpp 
b/src/libs/vdxf/libdxfrw/intern/dxfreader.cpp
+index bd0ba5898..6b18b0d89 100644
+--- a/src/libs/vdxf/libdxfrw/intern/dxfreader.cpp
++++ b/src/libs/vdxf/libdxfrw/intern/dxfreader.cpp
+@@ -115,18 +115,18 @@ auto dxfReader::getHandleString() -> int
+ 
+ auto dxfReaderBinary::readCode(int *code) -> bool
+ {
+-    unsigned short *int16p;
+-    char buffer[2];
+-    filestr->read(buffer,2);
+-    int16p = reinterpret_cast<unsigned short *>(buffer);
++    union {
++        unsigned short val;
++        char buf[2];
++    } buffer;
++    filestr->read(buffer.buf,2);
+ //exist a 32bits int (code 90) with 2 bytes???
+-    if ((*code == 90) && (*int16p>2000)){
++    if ((*code == 90) && (buffer.val>2000)){
+         DRW_DBG(*code); DRW_DBG(" de 16bits\n");
+         filestr->seekg(-4, std::ios_base::cur);
+-        filestr->read(buffer,2);
+-        int16p = reinterpret_cast<unsigned short *>(buffer);
++        filestr->read(buffer.buf,2);
+     }
+-    *code = *int16p;
++    *code = buffer.val;
+     DRW_DBG(*code); DRW_DBG("\n");
+ 
+     return (filestr->good());
+@@ -172,11 +172,12 @@ auto dxfReaderBinary::readInt16() -> bool
+ auto dxfReaderBinary::readInt32() -> bool
+ {
+     type = INT32;
+-    unsigned *int32p;
+-    char buffer[4];
+-    filestr->read(buffer,4);
+-    int32p = reinterpret_cast<unsigned *>(buffer);
+-    intData = static_cast<signed int>(*int32p);
++    union {
++        signed int val;
++        char buf[4];
++    } buffer;
++    filestr->read(buffer.buf,4);
++    intData = buffer.val;
+     // cppcheck-suppress danglingLifetime
+     DRW_DBG(intData); DRW_DBG("\n");
+     return (filestr->good());
+@@ -185,11 +186,12 @@ auto dxfReaderBinary::readInt32() -> bool
+ auto dxfReaderBinary::readInt64() -> bool
+ {
+     type = INT64;
+-    unsigned long long int *int64p; //64 bits integer pointer
+-    char buffer[8];
+-    filestr->read(buffer,8);
+-    int64p = reinterpret_cast<unsigned long long int *>(buffer);
+-    int64 = *int64p;
++    union {
++        unsigned long long int val;
++        char buf[8];
++    } buffer;
++    filestr->read(buffer.buf,8);
++    int64 = buffer.val;
+     // cppcheck-suppress danglingLifetime
+     DRW_DBG(int64); DRW_DBG(" int64\n");
+     return (filestr->good());
+@@ -198,12 +200,12 @@ auto dxfReaderBinary::readInt64() -> bool
+ auto dxfReaderBinary::readDouble() -> bool
+ {
+     type = DOUBLE;
+-    double *result;
+-    char buffer[8];
+-    filestr->read(buffer,8);
+-    // cppcheck-suppress invalidPointerCast
+-    result = reinterpret_cast<double *>(buffer);
+-    doubleData = *result;
++    union {
++        double val;
++        char buf[8];
++    } buffer;
++    filestr->read(buffer.buf,8);
++    doubleData = buffer.val;
+     // cppcheck-suppress danglingLifetime
+     DRW_DBG(doubleData); DRW_DBG("\n");
+     return (filestr->good());
+-- 
+2.51.0
+
diff -Nru 
valentina-1.0.0~dfsg/debian/patches/0002-vposter-avoid-illegal-reinterpret_cast.patch
 
valentina-1.0.0~dfsg/debian/patches/0002-vposter-avoid-illegal-reinterpret_cast.patch
--- 
valentina-1.0.0~dfsg/debian/patches/0002-vposter-avoid-illegal-reinterpret_cast.patch
       1970-01-01 01:00:00.000000000 +0100
+++ 
valentina-1.0.0~dfsg/debian/patches/0002-vposter-avoid-illegal-reinterpret_cast.patch
       2025-12-11 18:42:38.000000000 +0100
@@ -0,0 +1,48 @@
+From: Heinrich Schuchardt <[email protected]>
+Date: Fri, 12 Dec 2025 11:18:17 +0100
+Subject: [PATCH 2/4] vposter: avoid illegal reinterpret_cast
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+A reinterpret_cast where the target has a higher alignment requirement
+than the source leads to an error as observed with GCC 15.2 on riscv64:
+
+    vposter.cpp:73:30: error:
+    cast from ‘uchar*’ {aka ‘unsigned char*’} to ‘QRgb*’
+    {aka ‘unsigned int*’} increases required alignment of target type
+    [-Werror=cast-align]
+
+As we know that QImage::scanLine() returns 32bit aligned data
+use an unsafe conversion via a void * pointer instead.
+
+Signed-off-by: Heinrich Schuchardt <[email protected]>
+Origin: 
https://gitlab.com/smart-pattern/valentina/-/commit/499a7df1975953d905b73e3857cd4029678c75f6
+---
+ src/libs/vlayout/vposter.cpp | 8 +++++---
+ 1 file changed, 5 insertions(+), 3 deletions(-)
+
+diff --git a/src/libs/vlayout/vposter.cpp b/src/libs/vlayout/vposter.cpp
+index 889fee0c0..05633c363 100644
+--- a/src/libs/vlayout/vposter.cpp
++++ b/src/libs/vlayout/vposter.cpp
+@@ -66,11 +66,13 @@ auto Grayscale(QImage image) -> QImage
+ {
+     for (int ii = 0; ii < image.height(); ii++)
+     {
+-        uchar *scan = image.scanLine(ii);
+-        int const depth = 4;
++        // Scanline data is at least 32-bit aligned.
++        // https://doc.qt.io/qt-6/qimage.html#scanLine
++        void *voidPtr = image.scanLine(ii);
++        auto *scan = static_cast<QRgb *>(voidPtr);
+         for (int jj = 0; jj < image.width(); jj++)
+         {
+-            auto *rgbpixel = reinterpret_cast<QRgb *>(scan + jj * depth);
++            auto *rgbpixel = &scan[jj];
+             int const gray = qGray(*rgbpixel);
+             *rgbpixel = QColor(gray, gray, gray, qAlpha(*rgbpixel)).rgba();
+         }
+-- 
+2.51.0
+
diff -Nru 
valentina-1.0.0~dfsg/debian/patches/0003-stylehelper-avoid-illegal-reinterpret_cast.patch
 
valentina-1.0.0~dfsg/debian/patches/0003-stylehelper-avoid-illegal-reinterpret_cast.patch
--- 
valentina-1.0.0~dfsg/debian/patches/0003-stylehelper-avoid-illegal-reinterpret_cast.patch
   1970-01-01 01:00:00.000000000 +0100
+++ 
valentina-1.0.0~dfsg/debian/patches/0003-stylehelper-avoid-illegal-reinterpret_cast.patch
   2025-12-11 18:42:38.000000000 +0100
@@ -0,0 +1,52 @@
+From: Heinrich Schuchardt <[email protected]>
+Date: Fri, 12 Dec 2025 09:43:50 +0100
+Subject: [PATCH 3/4] stylehelper: avoid illegal reinterpret_cast
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+A reinterpret_cast where the target has a higher alignment requirement
+than the source leads to an error as observed with GCC 15.2 on riscv64:
+
+    stylehelper.cpp:157:34: error:
+    cast from ‘uchar*’ {aka ‘unsigned char*’} to ‘QRgb*’
+    {aka ‘unsigned int*’} increases required alignment
+    of target type [-Werror=cast-align]
+
+As we know that QImage::scanLine() returns 32bit aligned data
+use an unsafe conversion via a void * pointer instead.
+
+Signed-off-by: Heinrich Schuchardt <[email protected]>
+https://gitlab.com/smart-pattern/valentina/-/commit/b42d67d8bc0ea8afd9a9c9818dd6789891a0371f
+---
+ src/libs/vwidgets/fancytabbar/stylehelper.cpp | 9 ++++++---
+ 1 file changed, 6 insertions(+), 3 deletions(-)
+
+diff --git a/src/libs/vwidgets/fancytabbar/stylehelper.cpp 
b/src/libs/vwidgets/fancytabbar/stylehelper.cpp
+index 81f8617c4..120f02e8a 100644
+--- a/src/libs/vwidgets/fancytabbar/stylehelper.cpp
++++ b/src/libs/vwidgets/fancytabbar/stylehelper.cpp
+@@ -154,14 +154,17 @@ void StyleHelper::drawIconWithShadow(const QIcon &icon, 
const QRect &rect, QPain
+ 
+             for (int y = 0; y < im.height(); ++y)
+             {
+-                // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
+-                auto *scanLine = reinterpret_cast<QRgb *>(im.scanLine(y));
++                // Scanline data is at least 32-bit aligned.
++                // https://doc.qt.io/qt-6/qimage.html#scanLine
++                void *voidPtr = im.scanLine(y);
++                auto *scanLine = static_cast<QRgb *>(voidPtr);
++
+                 for (int x = 0; x < im.width(); ++x)
+                 {
+                     QRgb const pixel = *scanLine;
+                     auto const intensity = static_cast<char>(qGray(pixel));
+                     *scanLine = qRgba(intensity, intensity, intensity, 
qAlpha(pixel));
+-                    ++scanLine; // 
NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
++                    ++scanLine;
+                 }
+             }
+             px = QPixmap::fromImage(im);
+-- 
+2.51.0
+
diff -Nru 
valentina-1.0.0~dfsg/debian/patches/0004-vptilefactory-avoid-illegal-reinterpret_cast.patch
 
valentina-1.0.0~dfsg/debian/patches/0004-vptilefactory-avoid-illegal-reinterpret_cast.patch
--- 
valentina-1.0.0~dfsg/debian/patches/0004-vptilefactory-avoid-illegal-reinterpret_cast.patch
 1970-01-01 01:00:00.000000000 +0100
+++ 
valentina-1.0.0~dfsg/debian/patches/0004-vptilefactory-avoid-illegal-reinterpret_cast.patch
 2025-12-11 18:42:38.000000000 +0100
@@ -0,0 +1,48 @@
+From: Heinrich Schuchardt <[email protected]>
+Date: Fri, 12 Dec 2025 12:37:45 +0100
+Subject: [PATCH 4/4] vptilefactory: avoid illegal reinterpret_cast
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+A reinterpret_cast where the target has a higher alignment requirement
+than the source leads to an error as observed with GCC 15.2 on riscv64:
+
+    vptilefactory.cpp:120:30: error:
+    cast from ‘uchar*’ {aka ‘unsigned char*’} to ‘QRgb*’
+    {aka ‘unsigned int*’} increases required alignment of target type
+    [-Werror=cast-align]
+
+As we know that QImage::constScanLine() returns 32bit aligned data
+use an unsafe conversion via a void * pointer instead.
+
+Signed-off-by: Heinrich Schuchardt <[email protected]>
+Origin: 
https://gitlab.com/smart-pattern/valentina/-/commit/3e523bc88da9f92f876a8deabd21f0557bd6d775
+---
+ src/app/puzzle/vptilefactory.cpp | 8 +++++---
+ 1 file changed, 5 insertions(+), 3 deletions(-)
+
+diff --git a/src/app/puzzle/vptilefactory.cpp 
b/src/app/puzzle/vptilefactory.cpp
+index 725768883..1100e477d 100644
+--- a/src/app/puzzle/vptilefactory.cpp
++++ b/src/app/puzzle/vptilefactory.cpp
+@@ -113,11 +113,13 @@ auto Grayscale(QImage image) -> QImage
+ {
+     for (int ii = 0; ii < image.height(); ii++)
+     {
+-        uchar *scan = image.scanLine(ii);
+-        int const depth = 4;
++        // Scanline data is at least 32-bit aligned.
++        // https://doc.qt.io/qt-6/qimage.html#scanLine
++        void *voidPtr = image.scanLine(ii);
++        auto *scan = static_cast<QRgb *>(voidPtr);
+         for (int jj = 0; jj < image.width(); jj++)
+         {
+-            auto *rgbpixel = reinterpret_cast<QRgb *>(scan + jj * depth); // 
NOLINT
++            auto *rgbpixel = scan + jj;
+             int const gray = qGray(*rgbpixel);
+             *rgbpixel = QColor(gray, gray, gray, qAlpha(*rgbpixel)).rgba();
+         }
+-- 
+2.51.0
+
diff -Nru valentina-1.0.0~dfsg/debian/patches/series 
valentina-1.0.0~dfsg/debian/patches/series
--- valentina-1.0.0~dfsg/debian/patches/series  2025-11-09 22:36:39.000000000 
+0100
+++ valentina-1.0.0~dfsg/debian/patches/series  2025-12-11 18:42:38.000000000 
+0100
@@ -9,3 +9,7 @@
 1001_open_helper_tools_only_from_PATH.patch
 1002_path_to_tables.patch
 2004_rename_helper_tools.patch
+0001-libdxfrw-avoid-alignment-errors-in-dxfreader.cpp.patch
+0002-vposter-avoid-illegal-reinterpret_cast.patch
+0003-stylehelper-avoid-illegal-reinterpret_cast.patch
+0004-vptilefactory-avoid-illegal-reinterpret_cast.patch

Reply via email to