Commit b90ba157 by Richard Henderson Committed by Richard Henderson

list_read.c (nml_parse_qualifier): Use memcpy to extract values from dtp->u.p.value.

        * io/list_read.c (nml_parse_qualifier): Use memcpy to extract
        values from dtp->u.p.value.
        * io/io.h (struct st_parameter_dt): Change reversion_flag, first_item,
        seen_dollar, sf_seen_eor, eor_condition, no_leading_blank, char_flag,
        input_complete, at_eol, comma_flag, namelist_mode, nml_read_error to
        single-bit fields.  Move value to where it'll be at least pointer
        aligned.

From-SVN: r107520
parent 11e30dd8
2005-11-25 Richard Henderson <rth@redhat.com>
* io/list_read.c (nml_parse_qualifier): Use memcpy to extract
values from dtp->u.p.value.
* io/io.h (struct st_parameter_dt): Change reversion_flag, first_item,
seen_dollar, sf_seen_eor, eor_condition, no_leading_blank, char_flag,
input_complete, at_eol, comma_flag, namelist_mode, nml_read_error to
single-bit fields. Move value to where it'll be at least pointer
aligned.
2005-11-23 Alan Modra <amodra@bigpond.net.au> 2005-11-23 Alan Modra <amodra@bigpond.net.au>
* io/open.c (new_unit): Use the right unit number when checking * io/open.c (new_unit): Use the right unit number when checking
......
...@@ -380,30 +380,30 @@ typedef struct st_parameter_dt ...@@ -380,30 +380,30 @@ typedef struct st_parameter_dt
/* Number of spaces to be done for T and X-editing. */ /* Number of spaces to be done for T and X-editing. */
int pending_spaces; int pending_spaces;
unit_advance advance_status; unit_advance advance_status;
char reversion_flag; /* Format reversion has occurred. */
char first_item; unsigned reversion_flag : 1; /* Format reversion has occurred. */
char seen_dollar; unsigned first_item : 1;
char sf_seen_eor; unsigned seen_dollar : 1;
char eor_condition; unsigned sf_seen_eor : 1;
char no_leading_blank; unsigned eor_condition : 1;
char nml_delim; unsigned no_leading_blank : 1;
char char_flag; unsigned char_flag : 1;
char input_complete; unsigned input_complete : 1;
char at_eol; unsigned at_eol : 1;
char comma_flag; unsigned comma_flag : 1;
char last_char;
/* A namelist specific flag used in the list directed library /* A namelist specific flag used in the list directed library
to flag that calls are being made from namelist read (eg. to to flag that calls are being made from namelist read (eg. to
ignore comments or to treat '/' as a terminator) */ ignore comments or to treat '/' as a terminator) */
char namelist_mode; unsigned namelist_mode : 1;
/* A namelist specific flag used in the list directed library /* A namelist specific flag used in the list directed library
to flag read errors and return, so that an attempt can be to flag read errors and return, so that an attempt can be
made to read a new object name. */ made to read a new object name. */
char nml_read_error; unsigned nml_read_error : 1;
/* Storage area for values except for strings. Must be large /* 20 unused bits. */
enough to hold a complex value (two reals) of the largest
kind. */ char last_char;
char value[32]; char nml_delim;
int repeat_count; int repeat_count;
int saved_length; int saved_length;
int saved_used; int saved_used;
...@@ -414,6 +414,11 @@ typedef struct st_parameter_dt ...@@ -414,6 +414,11 @@ typedef struct st_parameter_dt
struct format_data *fmt; struct format_data *fmt;
jmp_buf *eof_jump; jmp_buf *eof_jump;
namelist_info *ionml; namelist_info *ionml;
/* Storage area for values except for strings. Must be large
enough to hold a complex value (two reals) of the largest
kind. */
char value[32];
} p; } p;
char pad[16 * sizeof (char *) + 32 * sizeof (int)]; char pad[16 * sizeof (char *) + 32 * sizeof (int)];
} u; } u;
......
...@@ -1489,8 +1489,7 @@ nml_parse_qualifier (st_parameter_dt *dtp, descriptor_dimension *ad, ...@@ -1489,8 +1489,7 @@ nml_parse_qualifier (st_parameter_dt *dtp, descriptor_dimension *ad,
eat_spaces (dtp); eat_spaces (dtp);
neg = 0; neg = 0;
/*process a potential sign. */ /* Process a potential sign. */
c = next_char (dtp); c = next_char (dtp);
switch (c) switch (c)
{ {
...@@ -1506,8 +1505,7 @@ nml_parse_qualifier (st_parameter_dt *dtp, descriptor_dimension *ad, ...@@ -1506,8 +1505,7 @@ nml_parse_qualifier (st_parameter_dt *dtp, descriptor_dimension *ad,
break; break;
} }
/*process characters up to the next ':' , ',' or ')' */ /* Process characters up to the next ':' , ',' or ')'. */
for (;;) for (;;)
{ {
c = next_char (dtp); c = next_char (dtp);
...@@ -1518,8 +1516,8 @@ nml_parse_qualifier (st_parameter_dt *dtp, descriptor_dimension *ad, ...@@ -1518,8 +1516,8 @@ nml_parse_qualifier (st_parameter_dt *dtp, descriptor_dimension *ad,
break; break;
case ',': case ')': case ',': case ')':
if ( (c==',' && dim == rank -1) if ((c==',' && dim == rank -1)
|| (c==')' && dim < rank -1)) || (c==')' && dim < rank -1))
{ {
st_sprintf (parse_err_msg, st_sprintf (parse_err_msg,
"Bad number of index fields"); "Bad number of index fields");
...@@ -1549,7 +1547,7 @@ nml_parse_qualifier (st_parameter_dt *dtp, descriptor_dimension *ad, ...@@ -1549,7 +1547,7 @@ nml_parse_qualifier (st_parameter_dt *dtp, descriptor_dimension *ad,
} }
if ((c == ':' && indx == 1 && dtp->u.p.saved_string == 0) if ((c == ':' && indx == 1 && dtp->u.p.saved_string == 0)
|| (indx == 2 && dtp->u.p.saved_string == 0)) || (indx == 2 && dtp->u.p.saved_string == 0))
{ {
st_sprintf(parse_err_msg, "Bad index triplet"); st_sprintf(parse_err_msg, "Bad index triplet");
goto err_ret; goto err_ret;
...@@ -1558,14 +1556,13 @@ nml_parse_qualifier (st_parameter_dt *dtp, descriptor_dimension *ad, ...@@ -1558,14 +1556,13 @@ nml_parse_qualifier (st_parameter_dt *dtp, descriptor_dimension *ad,
/* If '( : ? )' or '( ? : )' break and flag read failure. */ /* If '( : ? )' or '( ? : )' break and flag read failure. */
null_flag = 0; null_flag = 0;
if ((c == ':' && indx == 0 && dtp->u.p.saved_string == 0) if ((c == ':' && indx == 0 && dtp->u.p.saved_string == 0)
|| (indx==1 && dtp->u.p.saved_string == 0)) || (indx==1 && dtp->u.p.saved_string == 0))
{ {
null_flag = 1; null_flag = 1;
break; break;
} }
/* Now read the index. */ /* Now read the index. */
if (convert_integer (dtp, sizeof(int), neg)) if (convert_integer (dtp, sizeof(int), neg))
{ {
st_sprintf (parse_err_msg, "Bad integer in index"); st_sprintf (parse_err_msg, "Bad integer in index");
...@@ -1574,52 +1571,47 @@ nml_parse_qualifier (st_parameter_dt *dtp, descriptor_dimension *ad, ...@@ -1574,52 +1571,47 @@ nml_parse_qualifier (st_parameter_dt *dtp, descriptor_dimension *ad,
break; break;
} }
/*feed the index values to the triplet arrays. */ /* Feed the index values to the triplet arrays. */
if (!null_flag) if (!null_flag)
{ {
if (indx == 0) if (indx == 0)
ls[dim].start = *(int *)dtp->u.p.value; memcpy (&ls[dim].start, dtp->u.p.value, sizeof(int));
if (indx == 1) if (indx == 1)
ls[dim].end = *(int *)dtp->u.p.value; memcpy (&ls[dim].end, dtp->u.p.value, sizeof(int));
if (indx == 2) if (indx == 2)
ls[dim].step = *(int *)dtp->u.p.value; memcpy (&ls[dim].step, dtp->u.p.value, sizeof(int));
} }
/*singlet or doublet indices */ /* Singlet or doublet indices. */
if (c==',' || c==')') if (c==',' || c==')')
{ {
if (indx == 0) if (indx == 0)
{ {
ls[dim].start = *(int *)dtp->u.p.value; memcpy (&ls[dim].start, dtp->u.p.value, sizeof(int));
ls[dim].end = *(int *)dtp->u.p.value; ls[dim].end = ls[dim].start;
} }
break; break;
} }
} }
/*Check the values of the triplet indices. */ /* Check the values of the triplet indices. */
if ((ls[dim].start > (ssize_t)ad[dim].ubound)
if ( (ls[dim].start > (ssize_t)ad[dim].ubound) || (ls[dim].start < (ssize_t)ad[dim].lbound)
|| (ls[dim].start < (ssize_t)ad[dim].lbound) || (ls[dim].end > (ssize_t)ad[dim].ubound)
|| (ls[dim].end > (ssize_t)ad[dim].ubound) || (ls[dim].end < (ssize_t)ad[dim].lbound))
|| (ls[dim].end < (ssize_t)ad[dim].lbound))
{ {
st_sprintf (parse_err_msg, "Index %d out of range", dim + 1); st_sprintf (parse_err_msg, "Index %d out of range", dim + 1);
goto err_ret; goto err_ret;
} }
if (((ls[dim].end - ls[dim].start ) * ls[dim].step < 0) if (((ls[dim].end - ls[dim].start ) * ls[dim].step < 0)
|| (ls[dim].step == 0)) || (ls[dim].step == 0))
{ {
st_sprintf (parse_err_msg, "Bad range in index %d", dim + 1); st_sprintf (parse_err_msg, "Bad range in index %d", dim + 1);
goto err_ret; goto err_ret;
} }
/* Initialise the loop index counter. */ /* Initialise the loop index counter. */
ls[dim].idx = ls[dim].start; ls[dim].idx = ls[dim].start;
} }
eat_spaces (dtp); eat_spaces (dtp);
return SUCCESS; return SUCCESS;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment