(parse_words): avoid const warnings by making a (shorter) copy of the

string instead of truncating it


git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@15576 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Love Hörnquist Åstrand
2005-07-07 20:31:07 +00:00
parent e59a9eb876
commit fc24c4d403

View File

@@ -39,7 +39,7 @@ RCSID("$Id$");
#include "otp_locl.h" #include "otp_locl.h"
struct e { struct e {
char *s; const char *s;
unsigned n; unsigned n;
}; };
@@ -48,10 +48,10 @@ extern const struct e inv_std_dict[2048];
static int static int
cmp(const void *a, const void *b) cmp(const void *a, const void *b)
{ {
struct e *e1, *e2; const struct e *e1, *e2;
e1 = (struct e *)a; e1 = (const struct e *)a;
e2 = (struct e *)b; e2 = (const struct e *)b;
return strcasecmp (e1->s, e2->s); return strcasecmp (e1->s, e2->s);
} }
@@ -60,7 +60,7 @@ get_stdword (const char *s, void *v)
{ {
struct e e, *r; struct e e, *r;
e.s = (char *)s; e.s = s;
e.n = -1; e.n = -1;
r = (struct e *) bsearch (&e, inv_std_dict, r = (struct e *) bsearch (&e, inv_std_dict,
sizeof(inv_std_dict)/sizeof(*inv_std_dict), sizeof(inv_std_dict)/sizeof(*inv_std_dict),
@@ -106,21 +106,28 @@ parse_words(unsigned wn[],
int (*convert)(const char *, void *), int (*convert)(const char *, void *),
void *arg) void *arg)
{ {
unsigned char *w, *wend, c; const unsigned char *w, *wend;
unsigned char *wcopy;
int i; int i;
int tmp; int tmp;
w = (unsigned char *)str; w = str;
for (i = 0; i < 6; ++i) { for (i = 0; i < 6; ++i) {
while (isspace(*w)) while (isspace(*w))
++w; ++w;
wend = w; wend = w;
while (isalpha (*wend)) while (isalpha (*wend))
++wend; ++wend;
c = *wend;
*wend = '\0'; tmp = wend - w;
tmp = (*convert)((char *)w, arg); wcopy = malloc(tmp + 1);
*wend = c; if (wcopy == NULL)
return -1;
memcpy(wcopy, w, tmp);
wcopy[tmp] = '\0';
tmp = (*convert)(wcopy, arg);
free(wcopy);
w = wend; w = wend;
if (tmp < 0) if (tmp < 0)
return -1; return -1;