trans-array.c (trans_array_bound_check): Use xasprintf instead of unchecked asprintf.

* trans-array.c (trans_array_bound_check): Use xasprintf instead
	of unchecked asprintf.
	(gfc_conv_array_ref): Ditto.
	(gfc_conv_ss_startstride): Ditto.
	(gfc_trans_dummy_array_bias): Ditto.
	(gfc_conv_array_parameter): Ditto.
	* trans-decl.c (gfc_generate_function_code): Ditto.
	* trans-expr.c (gfc_conv_substring): Ditto.
	(gfc_conv_procedure_call): Ditto.
	* trans-io.c (gfc_trans_io_runtime_check): Ditto.
	(set_string): Ditto.
	* trans.c (trans-runtime_error_vararg): Ditto.

From-SVN: r219126
This commit is contained in:
Uros Bizjak 2014-12-31 15:50:10 +01:00 committed by Uros Bizjak
parent e8ef82d74f
commit 1a33dc9ec2
6 changed files with 82 additions and 66 deletions

View File

@ -1,3 +1,18 @@
2014-12-31 Uros Bizjak <ubizjak@gmail.com>
* trans-array.c (trans_array_bound_check): Use xasprintf instead
of unchecked asprintf.
(gfc_conv_array_ref): Ditto.
(gfc_conv_ss_startstride): Ditto.
(gfc_trans_dummy_array_bias): Ditto.
(gfc_conv_array_parameter): Ditto.
* trans-decl.c (gfc_generate_function_code): Ditto.
* trans-expr.c (gfc_conv_substring): Ditto.
(gfc_conv_procedure_call): Ditto.
* trans-io.c (gfc_trans_io_runtime_check): Ditto.
(set_string): Ditto.
* trans.c (trans-runtime_error_vararg): Ditto.
2014-12-29 Janus Weil <janus@gcc.gnu.org> 2014-12-29 Janus Weil <janus@gcc.gnu.org>
PR fortran/60357 PR fortran/60357

View File

@ -2799,11 +2799,11 @@ trans_array_bound_check (gfc_se * se, gfc_ss *ss, tree index, int n,
tmp_up = gfc_conv_array_ubound (descriptor, n); tmp_up = gfc_conv_array_ubound (descriptor, n);
if (name) if (name)
asprintf (&msg, "Index '%%ld' of dimension %d of array '%s' " msg = xasprintf ("Index '%%ld' of dimension %d of array '%s' "
"outside of expected range (%%ld:%%ld)", n+1, name); "outside of expected range (%%ld:%%ld)", n+1, name);
else else
asprintf (&msg, "Index '%%ld' of dimension %d " msg = xasprintf ("Index '%%ld' of dimension %d "
"outside of expected range (%%ld:%%ld)", n+1); "outside of expected range (%%ld:%%ld)", n+1);
fault = fold_build2_loc (input_location, LT_EXPR, boolean_type_node, fault = fold_build2_loc (input_location, LT_EXPR, boolean_type_node,
index, tmp_lo); index, tmp_lo);
@ -2824,11 +2824,11 @@ trans_array_bound_check (gfc_se * se, gfc_ss *ss, tree index, int n,
tmp_lo = gfc_conv_array_lbound (descriptor, n); tmp_lo = gfc_conv_array_lbound (descriptor, n);
if (name) if (name)
asprintf (&msg, "Index '%%ld' of dimension %d of array '%s' " msg = xasprintf ("Index '%%ld' of dimension %d of array '%s' "
"below lower bound of %%ld", n+1, name); "below lower bound of %%ld", n+1, name);
else else
asprintf (&msg, "Index '%%ld' of dimension %d " msg = xasprintf ("Index '%%ld' of dimension %d "
"below lower bound of %%ld", n+1); "below lower bound of %%ld", n+1);
fault = fold_build2_loc (input_location, LT_EXPR, boolean_type_node, fault = fold_build2_loc (input_location, LT_EXPR, boolean_type_node,
index, tmp_lo); index, tmp_lo);
@ -3259,8 +3259,8 @@ gfc_conv_array_ref (gfc_se * se, gfc_array_ref * ar, gfc_expr *expr,
cond = fold_build2_loc (input_location, LT_EXPR, boolean_type_node, cond = fold_build2_loc (input_location, LT_EXPR, boolean_type_node,
indexse.expr, tmp); indexse.expr, tmp);
asprintf (&msg, "Index '%%ld' of dimension %d of array '%s' " msg = xasprintf ("Index '%%ld' of dimension %d of array '%s' "
"below lower bound of %%ld", n+1, var_name); "below lower bound of %%ld", n+1, var_name);
gfc_trans_runtime_check (true, false, cond, &se->pre, where, msg, gfc_trans_runtime_check (true, false, cond, &se->pre, where, msg,
fold_convert (long_integer_type_node, fold_convert (long_integer_type_node,
indexse.expr), indexse.expr),
@ -3283,8 +3283,8 @@ gfc_conv_array_ref (gfc_se * se, gfc_array_ref * ar, gfc_expr *expr,
cond = fold_build2_loc (input_location, GT_EXPR, cond = fold_build2_loc (input_location, GT_EXPR,
boolean_type_node, indexse.expr, tmp); boolean_type_node, indexse.expr, tmp);
asprintf (&msg, "Index '%%ld' of dimension %d of array '%s' " msg = xasprintf ("Index '%%ld' of dimension %d of array '%s' "
"above upper bound of %%ld", n+1, var_name); "above upper bound of %%ld", n+1, var_name);
gfc_trans_runtime_check (true, false, cond, &se->pre, where, msg, gfc_trans_runtime_check (true, false, cond, &se->pre, where, msg,
fold_convert (long_integer_type_node, fold_convert (long_integer_type_node,
indexse.expr), indexse.expr),
@ -3981,8 +3981,8 @@ done:
/* Zero stride is not allowed. */ /* Zero stride is not allowed. */
tmp = fold_build2_loc (input_location, EQ_EXPR, boolean_type_node, tmp = fold_build2_loc (input_location, EQ_EXPR, boolean_type_node,
info->stride[dim], gfc_index_zero_node); info->stride[dim], gfc_index_zero_node);
asprintf (&msg, "Zero stride is not allowed, for dimension %d " msg = xasprintf ("Zero stride is not allowed, for dimension %d "
"of array '%s'", dim + 1, expr_name); "of array '%s'", dim + 1, expr_name);
gfc_trans_runtime_check (true, false, tmp, &inner, gfc_trans_runtime_check (true, false, tmp, &inner,
expr_loc, msg); expr_loc, msg);
free (msg); free (msg);
@ -4039,9 +4039,9 @@ done:
tmp2 = fold_build2_loc (input_location, TRUTH_AND_EXPR, tmp2 = fold_build2_loc (input_location, TRUTH_AND_EXPR,
boolean_type_node, boolean_type_node,
non_zerosized, tmp2); non_zerosized, tmp2);
asprintf (&msg, "Index '%%ld' of dimension %d of array '%s' " msg = xasprintf ("Index '%%ld' of dimension %d of array '%s' "
"outside of expected range (%%ld:%%ld)", "outside of expected range (%%ld:%%ld)",
dim + 1, expr_name); dim + 1, expr_name);
gfc_trans_runtime_check (true, false, tmp, &inner, gfc_trans_runtime_check (true, false, tmp, &inner,
expr_loc, msg, expr_loc, msg,
fold_convert (long_integer_type_node, info->start[dim]), fold_convert (long_integer_type_node, info->start[dim]),
@ -4061,9 +4061,9 @@ done:
info->start[dim], lbound); info->start[dim], lbound);
tmp = fold_build2_loc (input_location, TRUTH_AND_EXPR, tmp = fold_build2_loc (input_location, TRUTH_AND_EXPR,
boolean_type_node, non_zerosized, tmp); boolean_type_node, non_zerosized, tmp);
asprintf (&msg, "Index '%%ld' of dimension %d of array '%s' " msg = xasprintf ("Index '%%ld' of dimension %d of array '%s' "
"below lower bound of %%ld", "below lower bound of %%ld",
dim + 1, expr_name); dim + 1, expr_name);
gfc_trans_runtime_check (true, false, tmp, &inner, gfc_trans_runtime_check (true, false, tmp, &inner,
expr_loc, msg, expr_loc, msg,
fold_convert (long_integer_type_node, info->start[dim]), fold_convert (long_integer_type_node, info->start[dim]),
@ -4093,9 +4093,9 @@ done:
boolean_type_node, tmp, ubound); boolean_type_node, tmp, ubound);
tmp3 = fold_build2_loc (input_location, TRUTH_AND_EXPR, tmp3 = fold_build2_loc (input_location, TRUTH_AND_EXPR,
boolean_type_node, non_zerosized, tmp3); boolean_type_node, non_zerosized, tmp3);
asprintf (&msg, "Index '%%ld' of dimension %d of array '%s' " msg = xasprintf ("Index '%%ld' of dimension %d of array '%s' "
"outside of expected range (%%ld:%%ld)", "outside of expected range (%%ld:%%ld)",
dim + 1, expr_name); dim + 1, expr_name);
gfc_trans_runtime_check (true, false, tmp2, &inner, gfc_trans_runtime_check (true, false, tmp2, &inner,
expr_loc, msg, expr_loc, msg,
fold_convert (long_integer_type_node, tmp), fold_convert (long_integer_type_node, tmp),
@ -4110,9 +4110,9 @@ done:
} }
else else
{ {
asprintf (&msg, "Index '%%ld' of dimension %d of array '%s' " msg = xasprintf ("Index '%%ld' of dimension %d of array '%s' "
"below lower bound of %%ld", "below lower bound of %%ld",
dim + 1, expr_name); dim + 1, expr_name);
gfc_trans_runtime_check (true, false, tmp2, &inner, gfc_trans_runtime_check (true, false, tmp2, &inner,
expr_loc, msg, expr_loc, msg,
fold_convert (long_integer_type_node, tmp), fold_convert (long_integer_type_node, tmp),
@ -4139,9 +4139,9 @@ done:
{ {
tmp3 = fold_build2_loc (input_location, NE_EXPR, tmp3 = fold_build2_loc (input_location, NE_EXPR,
boolean_type_node, tmp, size[n]); boolean_type_node, tmp, size[n]);
asprintf (&msg, "Array bound mismatch for dimension %d " msg = xasprintf ("Array bound mismatch for dimension %d "
"of array '%s' (%%ld/%%ld)", "of array '%s' (%%ld/%%ld)",
dim + 1, expr_name); dim + 1, expr_name);
gfc_trans_runtime_check (true, false, tmp3, &inner, gfc_trans_runtime_check (true, false, tmp3, &inner,
expr_loc, msg, expr_loc, msg,
@ -6013,8 +6013,8 @@ gfc_trans_dummy_array_bias (gfc_symbol * sym, tree tmpdesc,
gfc_index_one_node, stride2); gfc_index_one_node, stride2);
tmp = fold_build2_loc (input_location, NE_EXPR, tmp = fold_build2_loc (input_location, NE_EXPR,
gfc_array_index_type, temp, stride2); gfc_array_index_type, temp, stride2);
asprintf (&msg, "Dimension %d of array '%s' has extent " msg = xasprintf ("Dimension %d of array '%s' has extent "
"%%ld instead of %%ld", n+1, sym->name); "%%ld instead of %%ld", n+1, sym->name);
gfc_trans_runtime_check (true, false, tmp, &init, &loc, msg, gfc_trans_runtime_check (true, false, tmp, &init, &loc, msg,
fold_convert (long_integer_type_node, temp), fold_convert (long_integer_type_node, temp),
@ -7292,10 +7292,10 @@ gfc_conv_array_parameter (gfc_se * se, gfc_expr * expr, bool g77,
char * msg; char * msg;
if (fsym && proc_name) if (fsym && proc_name)
asprintf (&msg, "An array temporary was created for argument " msg = xasprintf ("An array temporary was created for argument "
"'%s' of procedure '%s'", fsym->name, proc_name); "'%s' of procedure '%s'", fsym->name, proc_name);
else else
asprintf (&msg, "An array temporary was created"); msg = xasprintf ("An array temporary was created");
tmp = build_fold_indirect_ref_loc (input_location, tmp = build_fold_indirect_ref_loc (input_location,
desc); desc);

View File

@ -5723,8 +5723,8 @@ gfc_generate_function_code (gfc_namespace * ns)
{ {
char * msg; char * msg;
asprintf (&msg, "Recursive call to nonrecursive procedure '%s'", msg = xasprintf ("Recursive call to nonrecursive procedure '%s'",
sym->name); sym->name);
recurcheckvar = gfc_create_var (boolean_type_node, "is_recursive"); recurcheckvar = gfc_create_var (boolean_type_node, "is_recursive");
TREE_STATIC (recurcheckvar) = 1; TREE_STATIC (recurcheckvar) = 1;
DECL_INITIAL (recurcheckvar) = boolean_false_node; DECL_INITIAL (recurcheckvar) = boolean_false_node;

View File

@ -1799,11 +1799,11 @@ gfc_conv_substring (gfc_se * se, gfc_ref * ref, int kind,
fault = fold_build2_loc (input_location, TRUTH_ANDIF_EXPR, fault = fold_build2_loc (input_location, TRUTH_ANDIF_EXPR,
boolean_type_node, nonempty, fault); boolean_type_node, nonempty, fault);
if (name) if (name)
asprintf (&msg, "Substring out of bounds: lower bound (%%ld) of '%s' " msg = xasprintf ("Substring out of bounds: lower bound (%%ld) of '%s' "
"is less than one", name); "is less than one", name);
else else
asprintf (&msg, "Substring out of bounds: lower bound (%%ld)" msg = xasprintf ("Substring out of bounds: lower bound (%%ld)"
"is less than one"); "is less than one");
gfc_trans_runtime_check (true, false, fault, &se->pre, where, msg, gfc_trans_runtime_check (true, false, fault, &se->pre, where, msg,
fold_convert (long_integer_type_node, fold_convert (long_integer_type_node,
start.expr)); start.expr));
@ -1815,11 +1815,11 @@ gfc_conv_substring (gfc_se * se, gfc_ref * ref, int kind,
fault = fold_build2_loc (input_location, TRUTH_ANDIF_EXPR, fault = fold_build2_loc (input_location, TRUTH_ANDIF_EXPR,
boolean_type_node, nonempty, fault); boolean_type_node, nonempty, fault);
if (name) if (name)
asprintf (&msg, "Substring out of bounds: upper bound (%%ld) of '%s' " msg = xasprintf ("Substring out of bounds: upper bound (%%ld) of '%s' "
"exceeds string length (%%ld)", name); "exceeds string length (%%ld)", name);
else else
asprintf (&msg, "Substring out of bounds: upper bound (%%ld) " msg = xasprintf ("Substring out of bounds: upper bound (%%ld) "
"exceeds string length (%%ld)"); "exceeds string length (%%ld)");
gfc_trans_runtime_check (true, false, fault, &se->pre, where, msg, gfc_trans_runtime_check (true, false, fault, &se->pre, where, msg,
fold_convert (long_integer_type_node, end.expr), fold_convert (long_integer_type_node, end.expr),
fold_convert (long_integer_type_node, fold_convert (long_integer_type_node,
@ -4930,18 +4930,19 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym,
if (attr.allocatable if (attr.allocatable
&& (fsym == NULL || !fsym->attr.allocatable)) && (fsym == NULL || !fsym->attr.allocatable))
asprintf (&msg, "Allocatable actual argument '%s' is not " msg = xasprintf ("Allocatable actual argument '%s' is not "
"allocated or not present", e->symtree->n.sym->name); "allocated or not present",
e->symtree->n.sym->name);
else if (attr.pointer else if (attr.pointer
&& (fsym == NULL || !fsym->attr.pointer)) && (fsym == NULL || !fsym->attr.pointer))
asprintf (&msg, "Pointer actual argument '%s' is not " msg = xasprintf ("Pointer actual argument '%s' is not "
"associated or not present", "associated or not present",
e->symtree->n.sym->name); e->symtree->n.sym->name);
else if (attr.proc_pointer else if (attr.proc_pointer
&& (fsym == NULL || !fsym->attr.proc_pointer)) && (fsym == NULL || !fsym->attr.proc_pointer))
asprintf (&msg, "Proc-pointer actual argument '%s' is not " msg = xasprintf ("Proc-pointer actual argument '%s' is not "
"associated or not present", "associated or not present",
e->symtree->n.sym->name); e->symtree->n.sym->name);
else else
goto end_pointer_check; goto end_pointer_check;
@ -4963,16 +4964,16 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym,
{ {
if (attr.allocatable if (attr.allocatable
&& (fsym == NULL || !fsym->attr.allocatable)) && (fsym == NULL || !fsym->attr.allocatable))
asprintf (&msg, "Allocatable actual argument '%s' is not " msg = xasprintf ("Allocatable actual argument '%s' is not "
"allocated", e->symtree->n.sym->name); "allocated", e->symtree->n.sym->name);
else if (attr.pointer else if (attr.pointer
&& (fsym == NULL || !fsym->attr.pointer)) && (fsym == NULL || !fsym->attr.pointer))
asprintf (&msg, "Pointer actual argument '%s' is not " msg = xasprintf ("Pointer actual argument '%s' is not "
"associated", e->symtree->n.sym->name); "associated", e->symtree->n.sym->name);
else if (attr.proc_pointer else if (attr.proc_pointer
&& (fsym == NULL || !fsym->attr.proc_pointer)) && (fsym == NULL || !fsym->attr.proc_pointer))
asprintf (&msg, "Proc-pointer actual argument '%s' is not " msg = xasprintf ("Proc-pointer actual argument '%s' is not "
"associated", e->symtree->n.sym->name); "associated", e->symtree->n.sym->name);
else else
goto end_pointer_check; goto end_pointer_check;

View File

@ -258,7 +258,7 @@ gfc_trans_io_runtime_check (bool has_iostat, tree cond, tree var,
arg2 = build_int_cst (integer_type_node, error_code), arg2 = build_int_cst (integer_type_node, error_code),
asprintf (&message, "%s", _(msgid)); message = xasprintf ("%s", _(msgid));
arg3 = gfc_build_addr_expr (pchar_type_node, arg3 = gfc_build_addr_expr (pchar_type_node,
gfc_build_localized_cstring_const (message)); gfc_build_localized_cstring_const (message));
free (message); free (message);
@ -715,8 +715,8 @@ set_string (stmtblock_t * block, stmtblock_t * postblock, tree var,
cond = fold_build2_loc (input_location, LT_EXPR, boolean_type_node, cond = fold_build2_loc (input_location, LT_EXPR, boolean_type_node,
tmp, build_int_cst (TREE_TYPE (tmp), 0)); tmp, build_int_cst (TREE_TYPE (tmp), 0));
asprintf(&msg, "Label assigned to variable '%s' (%%ld) is not a format " msg = xasprintf ("Label assigned to variable '%s' (%%ld) is not a format "
"label", e->symtree->name); "label", e->symtree->name);
gfc_trans_runtime_check (true, false, cond, &se.pre, &e->where, msg, gfc_trans_runtime_check (true, false, cond, &se.pre, &e->where, msg,
fold_convert (long_integer_type_node, tmp)); fold_convert (long_integer_type_node, tmp));
free (msg); free (msg);

View File

@ -418,18 +418,18 @@ trans_runtime_error_vararg (bool error, locus* where, const char* msgid,
if (where) if (where)
{ {
line = LOCATION_LINE (where->lb->location); line = LOCATION_LINE (where->lb->location);
asprintf (&message, "At line %d of file %s", line, message = xasprintf ("At line %d of file %s", line,
where->lb->file->filename); where->lb->file->filename);
} }
else else
asprintf (&message, "In file '%s', around line %d", message = xasprintf ("In file '%s', around line %d",
gfc_source_file, LOCATION_LINE (input_location) + 1); gfc_source_file, LOCATION_LINE (input_location) + 1);
arg = gfc_build_addr_expr (pchar_type_node, arg = gfc_build_addr_expr (pchar_type_node,
gfc_build_localized_cstring_const (message)); gfc_build_localized_cstring_const (message));
free (message); free (message);
asprintf (&message, "%s", _(msgid)); message = xasprintf ("%s", _(msgid));
arg2 = gfc_build_addr_expr (pchar_type_node, arg2 = gfc_build_addr_expr (pchar_type_node,
gfc_build_localized_cstring_const (message)); gfc_build_localized_cstring_const (message));
free (message); free (message);