fix array->list
authorAndy Wingo <wingo@pobox.com>
Thu, 7 Jan 2010 15:40:13 +0000 (16:40 +0100)
committerAndy Wingo <wingo@pobox.com>
Thu, 7 Jan 2010 15:40:13 +0000 (16:40 +0100)
* libguile/generalized-arrays.c (array_to_list): Fix buggy
  implementation. Thanks to Daniel Llorens del Río for the bug repor.

THANKS
libguile/generalized-arrays.c

diff --git a/THANKS b/THANKS
index 9ffb0f041dba0484c980762769c09fce91fd67fa..94b86a102123400eac60fe6bc14a4ec349967d08 100644 (file)
--- a/THANKS
+++ b/THANKS
@@ -70,6 +70,7 @@ For fixes or providing information which led to a fix:
            Matt Kraai
          Daniel Kraft
        Miroslav Lichvar
+         Daniel Llorens del Río
            Jeff Long
          Marco Maggi
         Gregory Marton
index 8bbbed4d14954c77d50a09558ebe8deddf5b04e7..ea5388d83a0857cc30204aba406b766570aec2b6 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1995,1996,1997,1998,2000,2001,2002,2003,2004, 2005, 2006, 2009 Free Software Foundation, Inc.
+/* Copyright (C) 1995,1996,1997,1998,2000,2001,2002,2003,2004, 2005, 2006, 2009, 2010 Free Software Foundation, Inc.
  * 
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public License
@@ -243,14 +243,13 @@ array_to_list (scm_t_array_handle *h, size_t dim, unsigned long pos)
     {
       SCM res = SCM_EOL;
       long inc;
-      size_t i, lbnd;
+      size_t i;
 
-      i = h->dims[dim].ubnd;
-      lbnd = h->dims[dim].lbnd;
+      i = h->dims[dim].ubnd - h->dims[dim].lbnd + 1;
       inc = h->dims[dim].inc;
-      pos += (i - h->dims[dim].ubnd) * inc;
+      pos += (i - 1) * inc;
 
-      for (; i >= lbnd; i--, pos -= inc)
+      for (; i > 0; i--, pos -= inc)
         res = scm_cons (array_to_list (h, dim + 1, pos), res);
       return res;
     }