[PATCH] system: vm: Use 2^32 - 1 as hash size.

DoneSubmitted by Mathieu Othacehe.
Details
2 participants
  • Ludovic Courtès
  • Mathieu Othacehe
Owner
unassigned
Severity
normal
M
M
Mathieu Othacehe wrote on 3 Nov 2017 13:49
(address . guix-patches@gnu.org)(name . Mathieu Othacehe)(address . m.othacehe@gmail.com)
1509713344-16963-1-git-send-email-m.othacehe@gmail.com
* gnu/system/vm.scm (operating-system-uuid): Use 2^32 - 1 instead of 2^32 as hash size.
On some 32 bit system (ARM for example), 2^32 exceeds hash maxsize (ULONG_MAX = 2^32 - 1).--- gnu/system/vm.scm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
Toggle diff (24 lines)diff --git a/gnu/system/vm.scm b/gnu/system/vm.scmindex 3127b30..4424608 100644--- a/gnu/system/vm.scm+++ b/gnu/system/vm.scm@@ -372,13 +372,13 @@ TYPE (one of 'iso9660 or 'dce). Return a UUID object." (bytevector->uuid (uint-list->bytevector (list (hash file-system-type- (expt 2 32))+ (- (expt 2 32) 1)) (hash (operating-system-host-name os)- (expt 2 32))+ (- (expt 2 32) 1)) (hash (operating-system-services os)- (expt 2 32))+ (- (expt 2 32) 1)) (hash (operating-system-file-systems os)- (expt 2 32)))+ (- (expt 2 32) 1))) (endianness little) 4) type)))-- 2.7.4
L
L
Ludovic Courtès wrote on 5 Nov 2017 21:48
(name . Mathieu Othacehe)(address . m.othacehe@gmail.com)(address . 29132@debbugs.gnu.org)
87bmkgo3ij.fsf@gnu.org
Hello!
Mathieu Othacehe <m.othacehe@gmail.com> skribis:
Toggle quote (20 lines)> * gnu/system/vm.scm (operating-system-uuid): Use 2^32 - 1 instead of> 2^32 as hash size.>> On some 32 bit system (ARM for example), 2^32 exceeds hash max> size (ULONG_MAX = 2^32 - 1).> ---> gnu/system/vm.scm | 8 ++++----> 1 file changed, 4 insertions(+), 4 deletions(-)>> diff --git a/gnu/system/vm.scm b/gnu/system/vm.scm> index 3127b30..4424608 100644> --- a/gnu/system/vm.scm> +++ b/gnu/system/vm.scm> @@ -372,13 +372,13 @@ TYPE (one of 'iso9660 or 'dce). Return a UUID object."> (bytevector->uuid> (uint-list->bytevector> (list (hash file-system-type> - (expt 2 32))> + (- (expt 2 32) 1))
‘hash’ is documented like this:
-- Scheme Procedure: hash key size -- Scheme Procedure: hashq key size -- Scheme Procedure: hashv key size -- C Function: scm_hash (key, size) -- C Function: scm_hashq (key, size) -- C Function: scm_hashv (key, size) Return a hash value for KEY. This is a number in the range 0 to SIZE-1, which is suitable for use in a hash table of the given SIZE.
So I take it that you always get something in the range 0–2³²-1, no?
Ludo’.
M
M
Mathieu Othacehe wrote on 5 Nov 2017 21:56
(name . Ludovic Courtès)(address . ludo@gnu.org)(address . 29132@debbugs.gnu.org)
87shdsmolu.fsf@gmail.com
Hey Ludo,
Toggle quote (2 lines)> So I take it that you always get something in the range 0–2³²-1, no?
Well I agree, but looking to hash code, we have :
Toggle snippet (5 lines)#define FUNC_NAME s_scm_hash{ unsigned long sz = scm_to_unsigned_integer (size, 1, ULONG_MAX);
And 2^32 > ULONG_MAX == 2^32 - 1 on ARM.
This results in this exception :
Toggle snippet (5 lines)scheme@(guile-user)> (hash 'test (expt 2 32))ERROR: In procedure hash:ERROR: Value out of range 1 to 4294967295: 4294967296
Mathieu
L
L
Ludovic Courtès wrote on 6 Nov 2017 09:41
(name . Mathieu Othacehe)(address . m.othacehe@gmail.com)(address . 29132@debbugs.gnu.org)
87r2tber4q.fsf@gnu.org
Mathieu Othacehe <m.othacehe@gmail.com> skribis:
Toggle quote (10 lines)> Hey Ludo,>>> So I take it that you always get something in the range 0–2³²-1, no?>> Well I agree, but looking to hash code, we have :>> #define FUNC_NAME s_scm_hash> {> unsigned long sz = scm_to_unsigned_integer (size, 1, ULONG_MAX);
Oh, got it. Well, OK for the patch!
Thank you,Ludo’.
M
M
Mathieu Othacehe wrote on 6 Nov 2017 20:04
(name . Ludovic Courtès)(address . ludo@gnu.org)(address . 29132@debbugs.gnu.org)
87mv3zmdov.fsf@gmail.com
Toggle quote (2 lines)> Oh, got it. Well, OK for the patch!
Thanks, pushed as b1a30793477c705a136546798d8e1d27802dd4b7.
M
M
Mathieu Othacehe wrote on 6 Nov 2017 20:05
control message for bug #29132
(address . control@debbugs.gnu.org)
87h8u7mdnk.fsf@gmail.com
tags 29132 fixedclose 29132
?
Your comment

This issue is archived.

To comment on this conversation send email to 29132@debbugs.gnu.org