Fixed crash from FLIP when a numeric variable is specified on NEWNAMES
[pspp] / src / expr-evl.c
index 15b4434c9bee0e3d789f56c4b1192e776ef37101..100571c6443fd3c3785ebeb96423307ab95ddc38 100644 (file)
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
    02111-1307, USA. */
 
-/* AIX requires this to be the first thing in the file.  */
 #include <config.h>
-#if __GNUC__
-#define alloca __builtin_alloca
-#else
-#if HAVE_ALLOCA_H
-#include <alloca.h>
-#else
-#ifdef _AIX
-#pragma alloca
-#else
-#ifndef alloca                 /* predefined by HP cc +Olibcalls */
-char *alloca ();
-#endif
-#endif
-#endif
-#endif
 
 #if TIME_WITH_SYS_TIME
 #include <sys/time.h>
@@ -47,6 +31,8 @@ char *alloca ();
 #endif
 
 #include <ctype.h>
+#include "expr.h"
+#include "exprP.h"
 #include <assert.h>
 #include <math.h>
 #include <errno.h>
@@ -54,15 +40,12 @@ char *alloca ();
 #include "approx.h"
 #include "data-in.h"
 #include "error.h"
-#include "expr.h"
-#include "exprP.h"
 #include "julcal/julcal.h"
 #include "magic.h"
 #include "random.h"
 #include "stats.h"
 #include "str.h"
 #include "var.h"
-#include "vector.h"
 #include "vfm.h"
 #include "vfmP.h"
 
@@ -710,7 +693,8 @@ expr_evaluate (struct expression *e, struct ccase *c, union value *v)
            sp->f *= 60. * 60. * 24.;
          break;
        case OP_DATE_MOYR:
-         (--sp)->f = yrmoda (sp[1].f, sp[0].f, 1);
+          sp--;
+         sp->f = yrmoda (sp[1].f, sp[0].f, 1);
          if (sp->f != SYSMIS)
            sp->f *= 60. * 60. * 24.;
          break;
@@ -1201,11 +1185,11 @@ expr_evaluate (struct expression *e, struct ccase *c, union value *v)
          break;
        case OP_NORMAL:
          if (sp->f != SYSMIS)
-           sp->f = rand_normal (sp->f);
+           sp->f *= rng_get_double_normal (pspp_rng ());
          break;
        case OP_UNIFORM:
          if (sp->f != SYSMIS)
-           sp->f = rand_uniform (sp->f);
+           sp->f *= rng_get_double (pspp_rng ());
          break;
        case OP_SYSMIS:
          if (sp[0].f == SYSMIS || !finite (sp[0].f))
@@ -1216,9 +1200,9 @@ expr_evaluate (struct expression *e, struct ccase *c, union value *v)
        case OP_VEC_ELEM_NUM:
          {
            int rindx = sp[0].f + EPSILON;
-           struct vector *v = &vec[*op++];
+           const struct vector *v = dict_get_vector (default_dict, *op++);
 
-           if (sp[0].f == SYSMIS || rindx < 1 || rindx > v->nv)
+           if (sp[0].f == SYSMIS || rindx < 1 || rindx > v->cnt)
              {
                if (sp[0].f == SYSMIS)
                  msg (SE, _("SYSMIS is not a valid index value for vector "
@@ -1231,16 +1215,16 @@ expr_evaluate (struct expression *e, struct ccase *c, union value *v)
                sp->f = SYSMIS;
                break;
              }
-           sp->f = c->data[v->v[rindx - 1]->fv].f;
+           sp->f = c->data[v->var[rindx - 1]->fv].f;
          }
          break;
        case OP_VEC_ELEM_STR:
          {
            int rindx = sp[0].f + EPSILON;
-           struct vector *vect = &vec[*op++];
+           const struct vector *vect = dict_get_vector (default_dict, *op++);
            struct variable *v;
 
-           if (sp[0].f == SYSMIS || rindx < 1 || rindx > vect->nv)
+           if (sp[0].f == SYSMIS || rindx < 1 || rindx > vect->cnt)
              {
                if (sp[0].f == SYSMIS)
                  msg (SE, _("SYSMIS is not a valid index value for vector "
@@ -1257,7 +1241,7 @@ expr_evaluate (struct expression *e, struct ccase *c, union value *v)
                break;
              }
 
-           v = vect->v[rindx - 1];
+           v = vect->var[rindx - 1];
            CHECK_STRING_SPACE (v->width);
            sp->c = ALLOC_STRING_SPACE (v->width);
            sp->c[0] = v->width;
@@ -1351,12 +1335,6 @@ expr_evaluate (struct expression *e, struct ccase *c, union value *v)
        case OP_SENTINEL:
          goto finished;
 
-#if __CHECKER__
-         /* This case prevents Checker from choking. */
-       case 42000:
-         assert (0);
-#endif
-
        default:
 #if GLOBAL_DEBUGGING
          printf (_("evaluate_expression(): not implemented: %s\n"),