Skip to content

Commit dbe7741

Browse files
committed
OSX: don't try to call *nrm2 blas calls if incx < 1 or N < 1
Because calling nrm2 with negative incx will lead to a crash on OSX. See issue #37.
1 parent 7471dcb commit dbe7741

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/tests/correctness/blas-lapack.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,22 +840,50 @@ int izamax( int n, doublecomplex *x, int incx)
840840

841841
float snrm2( int n, float *x, int incx)
842842
{
843+
#ifdef __APPLE__
844+
if (n < 1 || incx < 1) {
845+
return 0;
846+
}
847+
return cblas_snrm2(n, x, incx);
848+
#else
843849
return snrm2_(&n, x, &incx);
850+
#endif
844851
}
845852

846853
double dnrm2( int n, double *x, int incx)
847854
{
855+
#ifdef __APPLE__
856+
if (n < 1 || incx < 1) {
857+
return 0;
858+
}
859+
return cblas_dnrm2(n, x, incx);
860+
#else
848861
return dnrm2_(&n, x, &incx);
862+
#endif
849863
}
850864

851865
float scnrm2( int n, complex *x, int incx)
852866
{
867+
#ifdef __APPLE__
868+
if (n < 1 || incx < 1) {
869+
return 0;
870+
}
871+
return cblas_scnrm2(n, x, incx);
872+
#else
853873
return scnrm2_(&n, x, &incx);
874+
#endif
854875
}
855876

856877
double dznrm2( int n, doublecomplex *x, int incx)
857878
{
879+
#ifdef __APPLE__
880+
if (n < 1 || incx < 1) {
881+
return 0;
882+
}
883+
return cblas_dznrm2(n, x, incx);
884+
#else
858885
return dznrm2_(&n, x, &incx);
886+
#endif
859887
}
860888

861889
float sasum( int n, float *x, int incx)

0 commit comments

Comments
 (0)