Fix crash calling RINDEX with a zero needle length
[pspp] / src / language / expressions / operations.def
index 37af54a9118abf8755fd0205cdaebdbe20021f46..471fa1d30d331c4cb6e924b6c6822dcbe4570bde 100644 (file)
@@ -1,7 +1,7 @@
 // -*- c -*-
 //
 // PSPP - a program for statistical analysis.
-// Copyright (C) 2005, 2006, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
+// Copyright (C) 2005, 2006, 2009, 2010, 2011, 2012, 2015 Free Software Foundation, Inc.
 // 
 // This program is free software: you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
@@ -84,7 +84,9 @@ function LG10(x) = check_errno (log10 (x));
 function LN (x) = check_errno (log (x));
 function LNGAMMA (x >= 0) = gsl_sf_lngamma (x);
 function MOD10 (x) = fmod (x, 10);
-function RND (x) = x >= 0. ? floor (x + .5) : -floor (-x + .5);
+function RND (x) = round_nearest (x, 1, 0);
+function RND (x, mult != 0) = round_nearest (x, mult, 0);
+function RND (x, mult != 0, fuzzbits >= 0) = round_nearest (x, mult, fuzzbits);
 function SIN (x) = sin (x);
 function SQRT (x >= 0) = sqrt (x);
 function TAN (x) = check_errno (tan (x));
@@ -415,7 +417,7 @@ function RINDEX (string haystack, string needle)
 
 function RINDEX (string haystack, string needles, needle_len_d)
 {
-  if (needle_len_d <= INT_MIN || needle_len_d >= INT_MAX
+  if (needle_len_d <= 0 || needle_len_d >= INT_MAX
       || (int) needle_len_d != needle_len_d
       || needles.length == 0)
     return SYSMIS;