[DRE-commits] [ruby-numo-narray] 11/13: fix sort_index: avoid zero-division when n==1 (#38)

Youhei SASAKI uwabami-guest at moszumanska.debian.org
Wed Jun 21 08:37:49 UTC 2017


This is an automated email from the git hooks/post-receive script.

uwabami-guest pushed a commit to branch patch-queue/master
in repository ruby-numo-narray.

commit c8bf8186a88234397a83e05de0207b677353114d
Author: Masahiro TANAKA <masa16.tanaka at gmail.com>
Date:   Fri Jun 9 19:56:40 2017 +0900

    fix sort_index: avoid zero-division when n==1 (#38)
    
    
    Gbp-Pq: Name 0011-fix-sort_index-avoid-zero-division-when-n-1-38.patch
---
 ext/numo/narray/gen/tmpl/sort_index.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/ext/numo/narray/gen/tmpl/sort_index.c b/ext/numo/narray/gen/tmpl/sort_index.c
index 39dc160..35687ff 100644
--- a/ext/numo/narray/gen/tmpl/sort_index.c
+++ b/ext/numo/narray/gen/tmpl/sort_index.c
@@ -18,6 +18,11 @@ static void
 
     //printf("(ptr=%lx, d_ptr=%lx,d_step=%ld, i_ptr=%lx,i_step=%ld, o_ptr=%lx,o_step=%ld)\n",(size_t)ptr,(size_t)d_ptr,(ssize_t)d_step,(size_t)i_ptr,(ssize_t)i_step,(size_t)o_ptr,(ssize_t)o_step);
 
+    if (n==1) {
+        *(idx_t*)o_ptr = *(idx_t*)(i_ptr);
+        return;
+    }
+
     for (i=0; i<n; i++) {
         ptr[i] = d_ptr + d_step * i;
         //printf("(%ld,%.3f)",i,*(double*)ptr[i]);
@@ -94,7 +99,7 @@ static VALUE
     }
     rb_funcall(idx, rb_intern("seq"), 0);
 
-    size = na->size*sizeof(void*);
+    size = na->size*sizeof(void*); // max capa
     buf = rb_alloc_tmp_buffer(&tmp, size);
     res = na_ndloop3(&ndf, buf, 3, self, idx, reduce);
     rb_free_tmp_buffer(&tmp);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-numo-narray.git



More information about the Pkg-ruby-extras-commits mailing list