+Wed Feb 11 20:33:18 2004 Ben Pfaff <blp@gnu.org>
+
+ * flip.c: Fixed crash from FLIP when a numeric variable is
+ specified on NEWNAMES and a large value is used, and a couple of
+ other minor bugs besides.
+ (struct varname) Make name a 9-character fixed-size array
+ instead of a 1-character variable size array.
+ (make_new_var) Allow digits in variable names.
+ (flip_stream_write) Limit numeric values to 8 characters and
+ format system missing and very large and small values more
+ appropriately.
+
Thu Feb 5 13:19:06 WAST 2004 John Darrington <john@darrington.wattle.id.au>
* fixed bug which caused a crash under certain invalid input.
#include <ctype.h>
#include <errno.h>
#include <float.h>
+#include <limits.h>
#include <stdlib.h>
#include "alloc.h"
#include "command.h"
struct varname
{
struct varname *next;
- char name[1];
+ char name[9];
};
/* New variable names. */
{
*cp = toupper ((unsigned char) *cp);
if (!isalpha (*cp) && *cp != '@' && *cp != '#'
- && (cp == name || (*cp != '.' && *cp != '$' && *cp != '_')))
+ && (cp == name || (*cp != '.' && *cp != '$' && *cp != '_'
+ && !isdigit (*cp))))
{
if (cp == name)
*cp = 'V'; /* _ not valid in first position. */
if (newnames)
{
- struct varname *v;
- char name[INT_DIGITS + 2];
-
- if (newnames->type == NUMERIC)
- sprintf (name, "V%d", (int) temp_case->data[newnames->fv].f);
+ struct varname *v = xmalloc (sizeof (struct varname));
+ if (newnames->type == NUMERIC)
+ {
+ double f = temp_case->data[newnames->fv].f;
+
+ if (f == SYSMIS)
+ strcpy (v->name, "VSYSMIS");
+ else if (f < INT_MIN)
+ strcpy (v->name, "VNEGINF");
+ else if (f > INT_MAX)
+ strcpy (v->name, "VPOSINF");
+ else
+ {
+ char name[INT_DIGITS + 2];
+ sprintf (name, "V%d", (int) f);
+ strncpy (v->name, name, 8);
+ name[8] = 0;
+ }
+ }
else
{
int width = min (newnames->width, 8);
- memcpy (name, temp_case->data[newnames->fv].s, width);
- name[width] = 0;
+ memcpy (v->name, temp_case->data[newnames->fv].s, width);
+ v->name[width] = 0;
}
-
- v = xmalloc (sizeof (struct varname) + strlen (name) - 1);
- strcpy (v->name, name);
if (new_names_tail == NULL)
new_names_head = v;