[PATCH 1/2] lib: fix byte order test in libsha1.c

2013-11-25 Thread Tomi Ollila
On Sun, Nov 24 2013, david at tethera.net wrote:

> From: David Bremner 
>
> Previously PLATFORM_BYTE_ORDER and IS_LITTLE_ENDIAN were not defined,
> so the little endian code was always compiled in.
>
> This will have the effect that the "SHA1s" on big endian architectures
> will change (i.e. become actual sha1s). So someone re-indexing their
> database could conceivable lose tags on messages without a message-id
> header.
> ---
>  lib/libsha1.c | 14 ++
>  1 file changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/lib/libsha1.c b/lib/libsha1.c
> index 5d16f6a..794854b 100644
> --- a/lib/libsha1.c
> +++ b/lib/libsha1.c
> @@ -49,11 +49,17 @@ extern "C"
>  
>  #define bswap_32(x) ((rotr32((x), 24) & 0x00ff00ff) | (rotr32((x), 8) & 
> 0xff00ff00))
>  
> -#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
> -#define bsw_32(p,n) \
> -{ int _i = (n); while(_i--) ((uint32_t*)p)[_i] = 
> bswap_32(((uint32_t*)p)[_i]); }
> +#ifdef __BYTE_ORDER__
> +#  if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
> +#define bsw_32(p,n) \
> +   { int _i = (n); while(_i--) ((uint32_t*)p)[_i] = 
> bswap_32(((uint32_t*)p)[_i]); }
> +#  elif (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
> +#define bsw_32(p,n)
> +#  else
> +#error "unknown byte order"
> +#  endif
>  #else
> -#define bsw_32(p,n)
> +#error "macro __BYTE_ORDER__ is not defined"
>  #endif

LGTM. 

When you modify te NEWS entry by adding instructions how to find
out those sha1's of message-id:s that are affected (Austin's code)
You could perhaps add note of the origin of these macros
(i.e. something like 
/* These "Common Predefined Macros" below are GNU C extensions */ )

See http://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
for reference.

Tomi

>  
>  #define SHA1_MASK   (SHA1_BLOCK_SIZE - 1)
> -- 
> 1.8.4.2


Re: [PATCH 1/2] lib: fix byte order test in libsha1.c

2013-11-25 Thread Tomi Ollila
On Sun, Nov 24 2013, da...@tethera.net wrote:

 From: David Bremner da...@tethera.net

 Previously PLATFORM_BYTE_ORDER and IS_LITTLE_ENDIAN were not defined,
 so the little endian code was always compiled in.

 This will have the effect that the SHA1s on big endian architectures
 will change (i.e. become actual sha1s). So someone re-indexing their
 database could conceivable lose tags on messages without a message-id
 header.
 ---
  lib/libsha1.c | 14 ++
  1 file changed, 10 insertions(+), 4 deletions(-)

 diff --git a/lib/libsha1.c b/lib/libsha1.c
 index 5d16f6a..794854b 100644
 --- a/lib/libsha1.c
 +++ b/lib/libsha1.c
 @@ -49,11 +49,17 @@ extern C
  
  #define bswap_32(x) ((rotr32((x), 24)  0x00ff00ff) | (rotr32((x), 8)  
 0xff00ff00))
  
 -#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
 -#define bsw_32(p,n) \
 -{ int _i = (n); while(_i--) ((uint32_t*)p)[_i] = 
 bswap_32(((uint32_t*)p)[_i]); }
 +#ifdef __BYTE_ORDER__
 +#  if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
 +#define bsw_32(p,n) \
 +   { int _i = (n); while(_i--) ((uint32_t*)p)[_i] = 
 bswap_32(((uint32_t*)p)[_i]); }
 +#  elif (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
 +#define bsw_32(p,n)
 +#  else
 +#error unknown byte order
 +#  endif
  #else
 -#define bsw_32(p,n)
 +#error macro __BYTE_ORDER__ is not defined
  #endif

LGTM. 

When you modify te NEWS entry by adding instructions how to find
out those sha1's of message-id:s that are affected (Austin's code)
You could perhaps add note of the origin of these macros
(i.e. something like 
/* These Common Predefined Macros below are GNU C extensions */ )

See http://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
for reference.

Tomi

  
  #define SHA1_MASK   (SHA1_BLOCK_SIZE - 1)
 -- 
 1.8.4.2
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH 1/2] lib: fix byte order test in libsha1.c

2013-11-24 Thread da...@tethera.net
From: David Bremner 

Previously PLATFORM_BYTE_ORDER and IS_LITTLE_ENDIAN were not defined,
so the little endian code was always compiled in.

This will have the effect that the "SHA1s" on big endian architectures
will change (i.e. become actual sha1s). So someone re-indexing their
database could conceivable lose tags on messages without a message-id
header.
---
 lib/libsha1.c | 14 ++
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/lib/libsha1.c b/lib/libsha1.c
index 5d16f6a..794854b 100644
--- a/lib/libsha1.c
+++ b/lib/libsha1.c
@@ -49,11 +49,17 @@ extern "C"

 #define bswap_32(x) ((rotr32((x), 24) & 0x00ff00ff) | (rotr32((x), 8) & 
0xff00ff00))

-#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
-#define bsw_32(p,n) \
-{ int _i = (n); while(_i--) ((uint32_t*)p)[_i] = 
bswap_32(((uint32_t*)p)[_i]); }
+#ifdef __BYTE_ORDER__
+#  if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
+#define bsw_32(p,n) \
+   { int _i = (n); while(_i--) ((uint32_t*)p)[_i] = 
bswap_32(((uint32_t*)p)[_i]); }
+#  elif (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
+#define bsw_32(p,n)
+#  else
+#error "unknown byte order"
+#  endif
 #else
-#define bsw_32(p,n)
+#error "macro __BYTE_ORDER__ is not defined"
 #endif

 #define SHA1_MASK   (SHA1_BLOCK_SIZE - 1)
-- 
1.8.4.2



[PATCH 1/2] lib: fix byte order test in libsha1.c

2013-11-24 Thread david
From: David Bremner da...@tethera.net

Previously PLATFORM_BYTE_ORDER and IS_LITTLE_ENDIAN were not defined,
so the little endian code was always compiled in.

This will have the effect that the SHA1s on big endian architectures
will change (i.e. become actual sha1s). So someone re-indexing their
database could conceivable lose tags on messages without a message-id
header.
---
 lib/libsha1.c | 14 ++
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/lib/libsha1.c b/lib/libsha1.c
index 5d16f6a..794854b 100644
--- a/lib/libsha1.c
+++ b/lib/libsha1.c
@@ -49,11 +49,17 @@ extern C
 
 #define bswap_32(x) ((rotr32((x), 24)  0x00ff00ff) | (rotr32((x), 8)  
0xff00ff00))
 
-#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
-#define bsw_32(p,n) \
-{ int _i = (n); while(_i--) ((uint32_t*)p)[_i] = 
bswap_32(((uint32_t*)p)[_i]); }
+#ifdef __BYTE_ORDER__
+#  if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
+#define bsw_32(p,n) \
+   { int _i = (n); while(_i--) ((uint32_t*)p)[_i] = 
bswap_32(((uint32_t*)p)[_i]); }
+#  elif (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
+#define bsw_32(p,n)
+#  else
+#error unknown byte order
+#  endif
 #else
-#define bsw_32(p,n)
+#error macro __BYTE_ORDER__ is not defined
 #endif
 
 #define SHA1_MASK   (SHA1_BLOCK_SIZE - 1)
-- 
1.8.4.2

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch