#include <language/dictionary/split-file.h>
#include <language/lexer/lexer.h>
#include <language/lexer/variable-parser.h>
-#include <libpspp/alloc.h>
#include <libpspp/array.h>
#include <libpspp/assertion.h>
#include <libpspp/compiler.h>
#include <libpspp/hash.h>
-#include <libpspp/magic.h>
-#include <libpspp/message.h>
#include <libpspp/message.h>
#include <libpspp/misc.h>
#include <libpspp/pool.h>
#include <output/table.h>
#include "minmax.h"
+#include "xalloc.h"
+#include "xmalloca.h"
#include "gettext.h"
#define _(msgid) gettext (msgid)
{
struct ccase c;
- if (!casereader_peek (input, 0, &c))
- return;
- output_split_file_values (ds, &c);
- case_destroy (&c);
+ if (casereader_peek (input, 0, &c))
+ {
+ output_split_file_values (ds, &c);
+ case_destroy (&c);
+ }
if (mode == GENERAL)
{
sorted_tab = xnrealloc (sorted_tab,
n_sorted_tab + count, sizeof *sorted_tab);
- v = local_alloc (sizeof *v * x->nvar);
+ v = xmalloca (sizeof *v * x->nvar);
for (j = 2; j < x->nvar; j++)
v[j] = get_var_range (x->vars[j])->min;
for (j = 0; j < count; j++)
break;
}
}
- local_free (v);
+ freea (v);
}
sorted_tab = xnrealloc (sorted_tab,
struct crosstab *x = xtab[t];
const size_t entry_size = (sizeof (struct table_entry)
+ sizeof (union value) * (x->nvar - 1));
- struct table_entry *te = local_alloc (entry_size);
+ struct table_entry *te = xmalloca (entry_size);
/* Construct table entry for the current record and table. */
te->table = t;
te->values[j].f = case_num (c, x->vars[j]);
else
{
- memcpy (te->values[j].s, case_str (c, x->vars[j]),
- var_get_width (x->vars[j]));
+ size_t n = var_get_width (x->vars[j]);
+ if (n > MAX_SHORT_STRING)
+ n = MAX_SHORT_STRING;
+ memcpy (te->values[j].s, case_str (c, x->vars[j]), n);
/* Necessary in order to simplify comparisons. */
memset (&te->values[j].s[var_get_width (x->vars[j])], 0,
- sizeof (union value) - var_get_width (x->vars[j]));
+ sizeof (union value) - n);
}
}
}
}
next_crosstab:
- local_free (te);
+ freea (te);
}
}
/* Crosstabulation name. */
{
- char *buf = local_alloc (128 * x->nvar);
+ char *buf = xmalloca (128 * x->nvar);
char *cp = buf;
int i;
}
tab_text (t, 0, 0, TAB_LEFT, buf);
- local_free (buf);
+ freea (buf);
}
/* Counts and percentages. */
/* Title. */
{
- char *title = local_alloc (x->nvar * 64 + 128);
+ char *title = xmalloca (x->nvar * 64 + 128);
char *cp = title;
int i;
strcpy (cp, "].");
tab_title (table, "%s", title);
- local_free (title);
+ freea (title);
}
tab_offset (table, 0, 2);
if (mode == GENERAL)
{
- int width = var_get_width (v);
+ int width = MIN (var_get_width (v), MAX_SHORT_STRING);
int i;
*values = xnmalloc (entry_cnt, sizeof **values);
tab_offset (table, -1, tab_row (table) - num_cells * n_rows);
for (r = 0; r < n_rows; r++)
{
- char suffix = 0;
bool mark_missing = false;
if (cmd.miss == CRS_REPORT
for (i = 0; i < num_cells; i++)
{
+ char suffix = 0;
double v;
switch (cells[i])
v = row_tot[r];
break;
case CRS_CL_ROW:
- v = 100.;
+ v = 100.0;
suffix = '%';
break;
case CRS_CL_COLUMN:
{
double ct = c < n_cols ? col_tot[c] : W;
bool mark_missing = false;
- char suffix = 0;
int i;
if (cmd.miss == CRS_REPORT && c < n_cols
for (i = 0; i < num_cells; i++)
{
+ char suffix = 0;
double v;
switch (cells[i])
{
case CRS_CL_COUNT:
v = ct;
- suffix = '%';
break;
case CRS_CL_ROW:
v = ct / W * 100.;
NOT_REACHED ();
}
- format_cell_entry (table, c, i, v, suffix, mark_missing);
+ format_cell_entry (table, c, i, v, suffix, mark_missing);
}
last_row = i;
}
/* Spearman correlation, Pearson's r. */
if (cmd.a_statistics[CRS_ST_CORR])
{
- double *R = local_alloc (sizeof *R * n_rows);
- double *C = local_alloc (sizeof *C * n_cols);
+ double *R = xmalloca (sizeof *R * n_rows);
+ double *C = xmalloca (sizeof *C * n_cols);
{
double y, t, c = 0., s = 0.;
calc_r (R, C, &v[6], &t[6], &ase[6]);
t[6] = v[6] / t[6];
- local_free (R);
- local_free (C);
+ freea (R);
+ freea (C);
calc_r ((double *) rows, (double *) cols, &v[7], &t[7], &ase[7]);
t[7] = v[7] / t[7];