[DRE-commits] [ruby-numo-narray] 08/13: fix cheking negative index
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 9912b080e7993edeb6f3e8f2a4b6ee69b164a70c
Author: Masahiro TANAKA <masa16.tanaka at gmail.com>
Date: Mon Jun 5 01:59:45 2017 +0900
fix cheking negative index
Gbp-Pq: Name 0008-fix-cheking-negative-index.patch
---
ext/numo/narray/index.c | 25 +++++++++++++------------
1 file changed, 13 insertions(+), 12 deletions(-)
diff --git a/ext/numo/narray/index.c b/ext/numo/narray/index.c
index 3a649b3..ae25845 100644
--- a/ext/numo/narray/index.c
+++ b/ext/numo/narray/index.c
@@ -173,26 +173,27 @@ static void
na_parse_range(VALUE range, ssize_t step, int orig_dim, ssize_t size, na_index_arg_t *q)
{
int n;
- ssize_t beg, end;
+ VALUE excl_end;
+ ssize_t beg, end, beg_orig, end_orig;
+ const char *dot = "..", *edot = "...";
- beg = NUM2LONG(rb_funcall(range,id_beg,0));
- if (beg<0) {
+ beg = beg_orig = NUM2SSIZET(rb_funcall(range,id_beg,0));
+ if (beg < 0) {
beg += size;
}
-
- end = NUM2LONG(rb_funcall(range,id_end,0));
- if (end<0) {
+ end = end_orig = NUM2SSIZET(rb_funcall(range,id_end,0));
+ if (end < 0) {
end += size;
}
-
- if (RTEST(rb_funcall(range,id_exclude_end,0))) {
+ excl_end = rb_funcall(range,id_exclude_end,0);
+ if (RTEST(excl_end)) {
end--;
+ dot = edot;
}
- if (beg < -size || beg >= size ||
- end < -size || end >= size) {
+ if (beg < 0 || beg >= size || end < 0 || end >= size) {
rb_raise(rb_eRangeError,
- "beg=%"SZF"d,end=%"SZF"d is out of array size (%"SZF"d)",
- beg, end, size);
+ "%"SZF"d%s%"SZF"d is out of range for size=%"SZF"d",
+ beg_orig, dot, end_orig, size);
}
n = (end-beg)/step+1;
if (n<0) n=0;
--
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