if (idx >= 1 && idx <= vector_get_var_cnt (v))
{
struct variable *var = vector_get_var (v, (size_t) idx - 1);
- return copy_string (e, case_str (c, var), var_get_width (var));
+ return copy_string (e, CHAR_CAST_BUG (char *, case_str (c, var)),
+ var_get_width (var));
}
else
{
{
const struct ccase *c = lagged_case (ds, n_before);
if (c != NULL)
- return copy_string (e, case_str (c, v), var_get_width (v));
+ return copy_string (e, CHAR_CAST_BUG (char *, case_str (c, v)),
+ var_get_width (v));
else
return empty_string;
}
{
const struct ccase *c = lagged_case (ds, 1);
if (c != NULL)
- return copy_string (e, case_str (c, v), var_get_width (v));
+ return copy_string (e, CHAR_CAST_BUG (char *, case_str (c, v)),
+ var_get_width (v));
else
return empty_string;
}
/* PSPP - a program for statistical analysis.
- Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc.
+ Copyright (C) 2005, 2006, 2009, 2010 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
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
+
#include "value-parser.h"
+
#include <stdbool.h>
-#include <data/data-in.h>
-#include <libpspp/message.h>
-#include "lexer.h"
-#include <libpspp/str.h>
-#include <data/value.h>
-#include <data/format.h>
+
+#include "data/data-in.h"
+#include "data/format.h"
+#include "data/value.h"
+#include "language/lexer/lexer.h"
+#include "libpspp/cast.h"
+#include "libpspp/message.h"
+#include "libpspp/str.h"
#include "gettext.h"
#define _(msgid) gettext (msgid)
return false;
v->f = lex_tokval (lexer);
}
- else
+ else if (lex_force_string (lexer))
{
- if (!lex_force_string (lexer))
- return false;
- value_copy_str_rpad (v, width, ds_cstr (lex_tokstr (lexer)), ' ');
+ const char *s = ds_cstr (lex_tokstr (lexer));
+ value_copy_str_rpad (v, width, CHAR_CAST_BUG (const uint8_t *, s), ' ');
}
+ else
+ return false;
lex_get (lexer);
/* PSPP - a program for statistical analysis.
- Copyright (C) 1997-9, 2000, 2009 Free Software Foundation, Inc.
+ Copyright (C) 1997-9, 2000, 2009, 2010 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
if (compute->test == NULL
|| expr_evaluate_num (compute->test, *c, case_num) == 1.0)
{
+ char *s;
+
*c = case_unshare (*c);
- expr_evaluate_str (compute->rvalue, *c, case_num,
- case_str_rw (*c, compute->variable),
- compute->width);
+ s = CHAR_CAST_BUG (char *, case_str_rw (*c, compute->variable));
+ expr_evaluate_str (compute->rvalue, *c, case_num, s, compute->width);
}
return TRNS_CONTINUE;
vr = vector_get_var (compute->vector, rindx - 1);
*c = case_unshare (*c);
expr_evaluate_str (compute->rvalue, *c, case_num,
- case_str_rw (*c, vr), var_get_width (vr));
+ CHAR_CAST_BUG (char *, case_str_rw (*c, vr)),
+ var_get_width (vr));
}
return TRNS_CONTINUE;
/* PSPP - a program for statistical analysis.
- Copyright (C) 1997-9, 2000, 2009 Free Software Foundation, Inc.
+ Copyright (C) 1997-9, 2000, 2009, 2010 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
in->type = MAP_SINGLE;
value_init_pool (pool, &in->x, width);
value_copy_buf_rpad (&in->x, width,
- ds_data (string), ds_length (string), ' ');
+ CHAR_CAST_BUG (uint8_t *, ds_data (string)),
+ ds_length (string), ' ');
}
/* Parses a mapping output value into OUT, allocating memory from
union value uv;
msg_disable ();
- match = data_in (ss_buffer (value, width), LEGACY_NATIVE,
- FMT_F, 0, 0, 0, trns->dst_dict, &uv, 0);
+ match = data_in (ss_buffer (CHAR_CAST_BUG (char *, value), width),
+ LEGACY_NATIVE, FMT_F, 0, 0, 0, trns->dst_dict,
+ &uv, 0);
msg_enable ();
out->value.f = uv.f;
break;
/* PSPP - a program for statistical analysis.
- Copyright (C) 2009 Free Software Foundation, Inc.
+ Copyright (C) 2009, 2010 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
#define LIBPSPP_CAST_H 1
#include <stddef.h>
+#include "gl/verify.h"
/* Expands to a void expression that checks that POINTER is an
expression whose type is a qualified or unqualified version of
(CHECK_POINTER_HAS_TYPE (POINTER, TYPE), \
(TYPE) (POINTER))
+/* Casts POINTER to TYPE. Yields a compiler diagnostic if either TYPE or
+ POINTER is not a pointer to character type.
+
+ PSPP uses "unsigned char" (actually uint8_t) in "union value" and "char"
+ elsewhere to emphasize that data in union value usually requires reencoding
+ when transferred to and from other string types. These macros suppress the
+ warning when implicitly converting between pointers to different character
+ types, so their use normally marks a bug that should eventually be fixed.
+ However, until these bugs are fixed, suppressing the warnings is much less
+ annoying.
+
+ Use CHAR_CAST_BUG if you think there is a bug to be fixed, or if you have
+ not yet carefully examined the situation, or if you are not sure.
+ Use CHAR_CAST if you are convinced that this is actually a correct cast. */
+#define CHAR_CAST(TYPE, POINTER) \
+ ((void) verify_true (sizeof (*(POINTER)) == 1), \
+ (void) (sizeof (*(POINTER) + 1)), \
+ (void) verify_true (sizeof (*(TYPE) NULL) == 1), \
+ (void) (sizeof (*(TYPE) NULL + 1)), \
+ (TYPE) (POINTER))
+#define CHAR_CAST_BUG(TYPE, POINTER) CHAR_CAST(TYPE, POINTER)
+
/* Given POINTER, a pointer to the given MEMBER within structure
STRUCT, returns the address of the STRUCT. */
#define UP_CAST(POINTER, STRUCT, MEMBER) \
/* PSPPIRE - a graphical user interface for PSPP.
- Copyright (C) 2008 Free Software Foundation, Inc.
+ Copyright (C) 2008, 2010 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
#include <ctype.h>
#include <mbchar.h>
-#include <data/data-in.h>
-#include <data/data-out.h>
-#include <data/format.h>
-#include <data/value.h>
-#include <libpspp/assertion.h>
-#include <libpspp/message.h>
-#include <libpspp/str.h>
+#include "data/data-in.h"
+#include "data/data-out.h"
+#include "data/format.h"
+#include "data/value.h"
+#include "libpspp/assertion.h"
+#include "libpspp/cast.h"
+#include "libpspp/message.h"
+#include "libpspp/str.h"
/* Appends to OUTPUT a pair of hex digits for each byte in IN. */
static void
if (width == 0)
syntax_gen_number (output, value->f, format);
else
- syntax_gen_string (output, ss_buffer (value_str (value, width), width));
+ {
+ char *s = CHAR_CAST_BUG (char *, value_str (value, width));
+ syntax_gen_string (output, ss_buffer (s, width));
+ }
}
/* Appends <low> THRU <high> to OUTPUT. If LOW is LOWEST, then