projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix up potential overflows in size calculations by replacing
[pspp]
/
src
/
recode.c
diff --git
a/src/recode.c
b/src/recode.c
index f4f7bffa76d68bbec369404bc76cd6cccc597a40..b364a1ac3ef2422f06d8ffad0086cbf5f5ad7c8a 100644
(file)
--- a/
src/recode.c
+++ b/
src/recode.c
@@
-14,8
+14,8
@@
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, Inc., 5
9 Temple Place - Suite 330
, Boston, MA
- 0211
1-1307
, USA. */
+ Foundation, Inc., 5
1 Franklin Street, Fifth Floor
, Boston, MA
+ 0211
0-1301
, USA. */
#include <config.h>
#include "error.h"
#include <config.h>
#include "error.h"
@@
-31,6
+31,9
@@
#include "magic.h"
#include "str.h"
#include "var.h"
#include "magic.h"
#include "str.h"
#include "var.h"
+
+#include "gettext.h"
+#define _(msgid) gettext (msgid)
\f
/* Definitions. */
\f
/* Definitions. */
@@
-72,7
+75,7
@@
struct rcd_var
union value sysmis; /* Coding for SYSMIS (if src is numeric). */
struct coding *map; /* Coding for other values. */
union value sysmis; /* Coding for SYSMIS (if src is numeric). */
struct coding *map; /* Coding for other values. */
-
int nmap, mmap;
/* Length of map, max capacity of map. */
+
size_t nmap, mmap;
/* Length of map, max capacity of map. */
};
/* RECODE transformation. */
};
/* RECODE transformation. */
@@
-115,7
+118,7
@@
static double convert_to_double (const char *, int);
int
cmd_recode (void)
{
int
cmd_recode (void)
{
-
in
t i;
+
size_
t i;
/* Transformation that we're constructing. */
struct rcd_var *rcd;
/* Transformation that we're constructing. */
struct rcd_var *rcd;
@@
-142,7
+145,7
@@
cmd_recode (void)
/* Variables in the current part of the recoding. */
struct variable **v;
/* Variables in the current part of the recoding. */
struct variable **v;
-
in
t nv;
+
size_
t nv;
/* Parses each specification between slashes. */
head = rcd = xmalloc (sizeof *rcd);
/* Parses each specification between slashes. */
head = rcd = xmalloc (sizeof *rcd);
@@
-187,7
+190,7
@@
cmd_recode (void)
for (;;)
{
/* Get the input value (before the `='). */
for (;;)
{
/* Get the input value (before the `='). */
-
in
t mark = rcd->nmap;
+
size_
t mark = rcd->nmap;
int code = parse_src_spec (rcd, type, max_src_width);
if (!code)
goto lossage;
int code = parse_src_spec (rcd, type, max_src_width);
if (!code)
goto lossage;
@@
-234,7
+237,7
@@
cmd_recode (void)
else
{
for (i = mark; i < rcd->nmap; i++)
else
{
for (i = mark; i < rcd->nmap; i++)
- rcd->map[i].t.c =
(output.c?xstrdup (output.c):NULL)
;
+ rcd->map[i].t.c =
output.c ? xstrdup (output.c) : NULL
;
free (output.c);
}
}
free (output.c);
}
}
@@
-268,7
+271,7
@@
cmd_recode (void)
if (lex_match_id ("INTO"))
{
char **names;
if (lex_match_id ("INTO"))
{
char **names;
-
in
t nnames;
+
size_
t nnames;
int success = 0;
int success = 0;
@@
-280,10
+283,10
@@
cmd_recode (void)
for (i = 0; i < nnames; i++)
free (names[i]);
free (names);
for (i = 0; i < nnames; i++)
free (names[i]);
free (names);
- msg (SE, _("%
d
variable(s) cannot be recoded into "
- "%
d
variable(s). Specify the same number "
+ msg (SE, _("%
u
variable(s) cannot be recoded into "
+ "%
u
variable(s). Specify the same number "
"of variables as input and output variables."),
"of variables as input and output variables."),
-
nv,
nnames);
+
(unsigned) nv, (unsigned)
nnames);
goto lossage;
}
goto lossage;
}
@@
-295,18
+298,20
@@
cmd_recode (void)
if (!v)
{
msg (SE, _("There is no string variable named "
if (!v)
{
msg (SE, _("There is no string variable named "
- "%s. (All string variables specified "
- "on INTO must already exist. Use the "
- "STRING command to create a string "
- "variable.)"), names[i]);
+ "%s. (All string variables specified "
+ "on INTO must already exist. Use the "
+ "STRING command to create a string "
+ "variable.)"),
+ names[i]);
goto INTO_fail;
}
if (v->type != ALPHA)
{
msg (SE, _("Type mismatch between input and output "
goto INTO_fail;
}
if (v->type != ALPHA)
{
msg (SE, _("Type mismatch between input and output "
- "variables. Output variable %s is not "
- "a string variable, but all the input "
- "variables are string variables."), v->name);
+ "variables. Output variable %s is not "
+ "a string variable, but all the input "
+ "variables are string variables."),
+ v->name);
goto INTO_fail;
}
if (v->width > (int) max_dst_width)
goto INTO_fail;
}
if (v->width > (int) max_dst_width)
@@
-378,7
+383,7
@@
cmd_recode (void)
/* The NULL is only really necessary for the
debugging code. */
char *repl = xmalloc (max_dst_width + 1);
/* The NULL is only really necessary for the
debugging code. */
char *repl = xmalloc (max_dst_width + 1);
- st
_pad_copy (repl, cp->t.c, max_dst_width + 1
);
+ st
r_copy_rpad (repl, max_dst_width + 1, cp->t.c
);
free (cp->t.c);
cp->t.c = repl;
}
free (cp->t.c);
cp->t.c = repl;
}
@@
-412,7
+417,7
@@
cmd_recode (void)
rcd->dest = dict_create_var (default_dict, rcd->dest_name, 0);
if (!rcd->dest)
{
rcd->dest = dict_create_var (default_dict, rcd->dest_name, 0);
if (!rcd->dest)
{
- /* FIXME: This can
occur
if a destname is duplicated.
+ /* FIXME: This can
fail
if a destname is duplicated.
We could give an error at parse time but I don't
care enough. */
rcd->dest = dict_lookup_var_assert (default_dict, rcd->dest_name);
We could give an error at parse time but I don't
care enough. */
rcd->dest = dict_lookup_var_assert (default_dict, rcd->dest_name);
@@
-463,7
+468,7
@@
parse_dest_spec (struct rcd_var * rcd, union value * v, size_t *max_dst_width)
if (toklen > max)
max = toklen;
v->c = xmalloc (max + 1);
if (toklen > max)
max = toklen;
v->c = xmalloc (max + 1);
- st
_pad_copy (v->c, ds_c_str (&tokstr), max + 1
);
+ st
r_copy_rpad (v->c, max + 1, ds_c_str (&tokstr)
);
flags = RCD_DEST_STRING;
*max_dst_width = max;
lex_get ();
flags = RCD_DEST_STRING;
*max_dst_width = max;
lex_get ();
@@
-516,10
+521,10
@@
parse_src_spec (struct rcd_var * rcd, int type, size_t max_src_width)
for (;;)
{
for (;;)
{
- if (rcd->nmap
>= rcd->mmap - 1
)
+ if (rcd->nmap
+ 1 >= rcd->mmap
)
{
rcd->mmap += 16;
{
rcd->mmap += 16;
- rcd->map = x
realloc (rcd->map, rcd->mmap *
sizeof *rcd->map);
+ rcd->map = x
nrealloc (rcd->map, rcd->mmap,
sizeof *rcd->map);
}
c = &rcd->map[rcd->nmap];
}
c = &rcd->map[rcd->nmap];
@@
-626,7
+631,7
@@
parse_src_spec (struct rcd_var * rcd, int type, size_t max_src_width)
if (!lex_force_string ())
return 0;
c->f1.c = xmalloc (max_src_width + 1);
if (!lex_force_string ())
return 0;
c->f1.c = xmalloc (max_src_width + 1);
- st
_pad_copy (c->f1.c, ds_c_str (&tokstr), max_src_width + 1
);
+ st
r_copy_rpad (c->f1.c, max_src_width + 1, ds_c_str (&tokstr)
);
lex_get ();
}
}
lex_get ();
}
}
@@
-646,7
+651,7
@@
parse_src_spec (struct rcd_var * rcd, int type, size_t max_src_width)
static void
recode_trns_free (struct trns_header * t)
{
static void
recode_trns_free (struct trns_header * t)
{
-
in
t i;
+
size_
t i;
struct rcd_var *head, *next;
head = ((struct recode_trns *) t)->codings;
struct rcd_var *head, *next;
head = ((struct recode_trns *) t)->codings;
@@
-711,7
+716,7
@@
find_src_numeric (struct rcd_var * v, struct ccase * c)
case RCD_END:
return NULL;
case RCD_USER:
case RCD_END:
return NULL;
case RCD_USER:
- if (
is_num_user_missing (cmp, v->src
))
+ if (
mv_is_num_user_missing (&v->src->miss, cmp
))
return cp;
break;
case RCD_SINGLE:
return cp;
break;
case RCD_SINGLE:
@@
-811,9
+816,9
@@
recode_trns_proc (struct trns_header * t, struct ccase * c,
if (val == NULL)
{
if (v->dest->fv != v->src->fv)
if (val == NULL)
{
if (v->dest->fv != v->src->fv)
-
st_bare_pad_len_copy
(case_data_rw (c, v->dest->fv)->s,
-
case_str (c, v->src->fv)
,
-
v->dest->width
, v->src->width);
+
buf_copy_rpad
(case_data_rw (c, v->dest->fv)->s,
+
v->dest->width
,
+
case_str (c, v->src->fv)
, v->src->width);
}
else
memcpy (case_data_rw (c, v->dest->fv)->s, cp->t.c, v->dest->width);
}
else
memcpy (case_data_rw (c, v->dest->fv)->s, cp->t.c, v->dest->width);
@@
-831,11
+836,11
@@
static long int
string_to_long (const char *nptr, int width, const char **endptr)
{
int negative;
string_to_long (const char *nptr, int width, const char **endptr)
{
int negative;
-
register
unsigned long int cutoff;
-
register
unsigned int cutlim;
-
register
unsigned long int i;
-
register
const char *s;
-
register
unsigned char c;
+ unsigned long int cutoff;
+ unsigned int cutlim;
+ unsigned long int i;
+ const char *s;
+ unsigned char c;
const char *save;
s = nptr;
const char *save;
s = nptr;
@@
-906,7
+911,7
@@
string_to_long (const char *nptr, int width, const char **endptr)
static double
convert_to_double (const char *s, int width)
{
static double
convert_to_double (const char *s, int width)
{
-
register
const char *end = &s[width];
+ const char *end = &s[width];
short int sign;
short int sign;