Skip to content
Back to formatted view

Raw Message

Message-ID: <5170FD4A.4010403@stats.ox.ac.uk>
Date: 2013-04-19T08:16:10Z
From: Brian Ripley
Subject: stack imbalance in max.col for non-real matrices
In-Reply-To: <CAOQ5NyeJ_PNB3ehDQU9FPchEy+A14fKmhunFnGm4AN8BLpZG=Q@mail.gmail.com>

On 17/04/2013 21:25, Michael Lawrence wrote:
> It's tough to reliably reproduce, but I often get stack imbalance warnings
> when calling max.col() on non-real/double matrix. The code is conditionally
> PROTECTing but not incrementing its nprot counter for the eventual
> UNPROTECT. Pretty sure this would fix (but I haven't tested it):

I can't reproduce it either, but that seems the right fix so 
incorporated now, thanks.

>
> Index: array.c
> ===================================================================
> --- array.c    (revision 61606)
> +++ array.c    (working copy)
> @@ -1614,7 +1614,10 @@
>       SEXP m = CAR(args);
>       int method = asInteger(CADR(args));
>       int nr = nrows(m), nc = ncols(m), nprot = 1;
> -    if (TYPEOF(m) != REALSXP) PROTECT(m = coerceVector(m, REALSXP));
> +    if (TYPEOF(m) != REALSXP) {
> +      PROTECT(m = coerceVector(m, REALSXP));
> +      nprot++;
> +    }
>       SEXP ans = allocVector(INTSXP, nr);
>       PROTECT(ans);
>       R_max_col(REAL(m), &nr, &nc, INTEGER(ans), &method);
>
> Thanks,
> Michael
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>


-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595