Hello Gary,

OK, thanks for the fast feedback. It looks like you have supplied a fix that is more than just a hammer fix. Your new file certainly looks cleaner. I will test it, and if it works here on Ubuntu 16.04 and cross-compiled Windows, I will release it.

Thanks,
Kern

On 06/20/2017 05:01 AM, Gary R. Schmidt wrote:
On 20/06/2017 00:46, Kern Sibbald wrote:


On 06/19/2017 03:23 PM, Gary R. Schmidt wrote:
Hi Kern,

On 19/06/2017 22:48, Kern Sibbald wrote:
You need to checkout Branch-7.9. The code you need is at the HEAD of that branch and there is as of this moment no specific tag setup for it.

The easiest is to clone the repository then checkout Branch-7.9.

Thanks for that, I got it out eventually, but I can't get at the S10 system at the moment, that doesn't matter, I have an S11 box right in front of me...


Your fix doesn't work on Solaris 11. Nor will it work on Solaris 5.2.1, 6, 7, 8, or 9.
Well that is a big surprise because I implemented the change to work only on Solaris 10 (i.e 5.10).

And the code is invalid on HP-UX and AIX unless you use GCC to compile.
That is possible. Not many people know how to write portable code these days :-(

I've spent more than three decades being paid to write portable C (and Pascal and other) code, but mainly C, so please just apply this fix, it is correct, portable, readable, and maintainable.

It will work on any C or C++ compiler that supports the pack() pragma and #if defined(), so that's pretty much anything in use for the past twenty-five or more years. I'd say forty, but I can't recall pragmas from the original K&R compiler (or the Portable C Compiler or VAX-C or Greenhills or ...).

The corrected code is below, as are "diff -c" and "diff -u" output, and the entire file is attached as well.

I will submit this fix to the lz4 maintainer.

Remove the setting of "HAVE_SOLARIS10" it is pointless.

Make the dodgy part of lz4.c look like this:
=======================================================================
#if !defined(LZ4_FORCE_UNALIGNED_ACCESS)
#  pragma pack(1)
#endif

typedef struct _U16_S { U16 v; } U16_S;
typedef struct _U32_S { U32 v; } U32_S;
typedef struct _U64_S { U64 v; } U64_S;

#if !defined(LZ4_FORCE_UNALIGNED_ACCESS)
#  pragma pack()
#endif
=======================================================================
It is so much neater and more legible that what was there, and for extra points replace "#if !defined(LZ4_FORCE_UNALIGNED_ACCESS)" with "#ifndef LZ4_FORCE_UNALIGNED_ACCESS" as well.

diff -c:
=======================================================================
$ diff -c lz4.c.worse lz4.c
*** lz4.c.worse Tue Jun 20 12:42:47 2017
--- lz4.c       Tue Jun 20 12:43:56 2017
***************
*** 167,192 ****
    typedef unsigned long long  U64;
  #endif

! #if defined(__GNUC__)  && !defined(LZ4_FORCE_UNALIGNED_ACCESS)
! #  define _PACKED __attribute__ ((packed))
! #else
! #  define _PACKED
! #endif
!
! #if !defined(LZ4_FORCE_UNALIGNED_ACCESS) && !defined(__GNUC__) && defined(HAVE_SOLARIS10)
  #  pragma pack(1)
- #elif !defined(LZ4_FORCE_UNALIGNED_ACCESS) && !defined(__GNUC__)
- #  pragma pack(push, 1)
  #endif

! typedef struct _U16_S { U16 v; } _PACKED U16_S;
! typedef struct _U32_S { U32 v; } _PACKED U32_S;
! typedef struct _U64_S { U64 v; } _PACKED U64_S;

! #if !defined(LZ4_FORCE_UNALIGNED_ACCESS) && !defined(__GNUC__) && defined(HAVE_SOLARIS10)
  #  pragma pack()
- #elif !defined(LZ4_FORCE_UNALIGNED_ACCESS) && !defined(__GNUC__)
- #  pragma pack(pop)
  #endif

  #define A64(x) (((U64_S *)(x))->v)
--- 167,182 ----
    typedef unsigned long long  U64;
  #endif

! #if !defined(LZ4_FORCE_UNALIGNED_ACCESS)
  #  pragma pack(1)
  #endif

! typedef struct _U16_S { U16 v; } U16_S;
! typedef struct _U32_S { U32 v; } U32_S;
! typedef struct _U64_S { U64 v; } U64_S;

! #if !defined(LZ4_FORCE_UNALIGNED_ACCESS)
  #  pragma pack()
  #endif

  #define A64(x) (((U64_S *)(x))->v)
=======================================================================

diff -u:
=======================================================================
paranoia ~/src/bacula/bacula/src/lib $ diff -u lz4.c.worse lz4.c
--- lz4.c.worse Tue Jun 20 12:42:47 2017
+++ lz4.c       Tue Jun 20 12:43:56 2017
@@ -167,26 +167,16 @@
   typedef unsigned long long  U64;
 #endif

-#if defined(__GNUC__)  && !defined(LZ4_FORCE_UNALIGNED_ACCESS)
-#  define _PACKED __attribute__ ((packed))
-#else
-#  define _PACKED
-#endif
-
-#if !defined(LZ4_FORCE_UNALIGNED_ACCESS) && !defined(__GNUC__) && defined(HAVE_SOLARIS10)
+#if !defined(LZ4_FORCE_UNALIGNED_ACCESS)
 #  pragma pack(1)
-#elif !defined(LZ4_FORCE_UNALIGNED_ACCESS) && !defined(__GNUC__)
-#  pragma pack(push, 1)
 #endif

-typedef struct _U16_S { U16 v; } _PACKED U16_S;
-typedef struct _U32_S { U32 v; } _PACKED U32_S;
-typedef struct _U64_S { U64 v; } _PACKED U64_S;
+typedef struct _U16_S { U16 v; } U16_S;
+typedef struct _U32_S { U32 v; } U32_S;
+typedef struct _U64_S { U64 v; } U64_S;

-#if !defined(LZ4_FORCE_UNALIGNED_ACCESS) && !defined(__GNUC__) && defined(HAVE_SOLARIS10)
+#if !defined(LZ4_FORCE_UNALIGNED_ACCESS)
 #  pragma pack()
-#elif !defined(LZ4_FORCE_UNALIGNED_ACCESS) && !defined(__GNUC__)
-#  pragma pack(pop)
 #endif

 #define A64(x) (((U64_S *)(x))->v)
=======================================================================

And I have attached the file as well.


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Bacula-devel mailing list
Bacula-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bacula-devel

Reply via email to