summaryrefslogtreecommitdiff
path: root/libguile/sort.c
diff options
context:
space:
mode:
authorAndreas Rottmann <a.rottmann@gmx.at>2011-06-09 22:11:02 +0200
committerAndreas Rottmann <a.rottmann@gmx.at>2011-06-09 22:11:02 +0200
commit589bc528bd63291d2faa4bbcef9e402e62e1f72d (patch)
tree14f0dad4e940c5afc8f017a2c7a578eb440145a6 /libguile/sort.c
parente108c961fed2ffdedddcd10bad9c6aae44491b1e (diff)
downloadguile-589bc528bd63291d2faa4bbcef9e402e62e1f72d.tar.gz
Fix likely crash in `stable-sort!'
* libguile/sort.c (scm_stable_sort_x): Properly handle zero-length vectors. * test-suite/tests/sort.test ("stable-sort"): Add test for this case.
Diffstat (limited to 'libguile/sort.c')
-rw-r--r--libguile/sort.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/libguile/sort.c b/libguile/sort.c
index 5fdbb177c..ecadd82ea 100644
--- a/libguile/sort.c
+++ b/libguile/sort.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1999,2000,2001,2002, 2004, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+/* Copyright (C) 1999,2000,2001,2002, 2004, 2006, 2007, 2008, 2009, 2010, 2011 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
* as published by the Free Software Foundation; either version 3 of
@@ -495,6 +495,11 @@ SCM_DEFINE (scm_stable_sort_x, "stable-sort!", 2, 0, 0,
vec_elts = scm_vector_writable_elements (items, &vec_handle,
&len, &inc);
+ if (len == 0) {
+ scm_array_handle_release (&vec_handle);
+ return items;
+ }
+
temp = scm_c_make_vector (len, SCM_UNDEFINED);
temp_elts = scm_vector_writable_elements (temp, &temp_handle,
NULL, NULL);