From 1ebadc609b97abf76eddff241200b4dcf8b10eb9 Mon Sep 17 00:00:00 2001 From: "Kaveh R. Ghazi" Date: Thu, 14 Oct 1999 17:13:57 +0000 Subject: [PATCH] jcf-dump.c (print_constant, [...]): Don't call a variadic function with a non-literal format string. * jcf-dump.c (print_constant, disassemble_method): Don't call a variadic function with a non-literal format string. * parse-scan.y (report_main_declaration): Likewise. * parse.h (ERROR_CAST_NEEDED_TO_INTEGRAL): Likewise. * parse.y (read_import_dir, patch_assignment, patch_binop, patch_array_ref): Likewise. * typeck.c (build_java_array_type): Likewise. * verify.c (verify_jvm_instructions): Likewise. From-SVN: r29981 --- gcc/java/ChangeLog | 16 ++++++++++++ gcc/java/jcf-dump.c | 52 +++++++++++++++++++++++-------------- gcc/java/parse-scan.c | 2 +- gcc/java/parse-scan.y | 2 +- gcc/java/parse.c | 60 ++++++++++++++++++++++++------------------- gcc/java/parse.h | 19 +++++++++----- gcc/java/parse.y | 58 ++++++++++++++++++++++++----------------- gcc/java/typeck.c | 6 ++++- gcc/java/verify.c | 2 +- 9 files changed, 138 insertions(+), 79 deletions(-) diff --git a/gcc/java/ChangeLog b/gcc/java/ChangeLog index 1daf2ce4dc8..81b883469a6 100644 --- a/gcc/java/ChangeLog +++ b/gcc/java/ChangeLog @@ -1,3 +1,19 @@ +1999-10-14 Kaveh R. Ghazi + + * jcf-dump.c (print_constant, disassemble_method): Don't call a + variadic function with a non-literal format string. + + * parse-scan.y (report_main_declaration): Likewise. + + * parse.h (ERROR_CAST_NEEDED_TO_INTEGRAL): Likewise. + + * parse.y (read_import_dir, patch_assignment, patch_binop, + patch_array_ref): Likewise. + + * typeck.c (build_java_array_type): Likewise. + + * verify.c (verify_jvm_instructions): Likewise. + Tue Oct 12 22:28:10 1999 Alexandre Petit-Bianco * jcf-write.c (RELOCATION_VALUE_1): Fixed integer value from 0 to 1. diff --git a/gcc/java/jcf-dump.c b/gcc/java/jcf-dump.c index 2f20e30025d..becf7471c1f 100644 --- a/gcc/java/jcf-dump.c +++ b/gcc/java/jcf-dump.c @@ -386,7 +386,12 @@ DEFUN(print_constant, (out, jcf, index, verbosity), case CONSTANT_Class: n = JPOOL_USHORT1 (jcf, index); if (verbosity > 0) - fprintf (out, verbosity > 1 ? "Class name: %d=" : "Class ", n); + { + if (verbosity > 1) + fprintf (out, "Class name: %d=", n); + else + fprintf (out, "Class "); + } if (! CPOOL_INDEX_IN_RANGE (&jcf->cpool, n)) fprintf (out, ""); else if (verbosity < 2 && JPOOL_TAG (jcf, n) == CONSTANT_Utf8) @@ -412,8 +417,10 @@ DEFUN(print_constant, (out, jcf, index, verbosity), else if (verbosity > 0) fprintf (out, "%s ", str); print_constant_terse (out, jcf, tclass, CONSTANT_Class); - fprintf (out, verbosity < 2 ? "." : " name_and_type: %d=<", - name_and_type); + if (verbosity < 2) + fprintf (out, "."); + else + fprintf (out, " name_and_type: %d=<", name_and_type); print_constant_terse (out, jcf, name_and_type, CONSTANT_NameAndType); if (verbosity == 2) fputc ('>', out); @@ -422,7 +429,12 @@ DEFUN(print_constant, (out, jcf, index, verbosity), case CONSTANT_String: j = JPOOL_USHORT1 (jcf, index); if (verbosity > 0) - fprintf (out, verbosity > 1 ? "String %d=" : "String ", j); + { + if (verbosity > 1) + fprintf (out, "String %d=", j); + else + fprintf (out, "String "); + } print_constant_terse (out, jcf, j, CONSTANT_Utf8); break; case CONSTANT_Integer: @@ -473,8 +485,12 @@ DEFUN(print_constant, (out, jcf, index, verbosity), uint16 name = JPOOL_USHORT1 (jcf, index); uint16 sig = JPOOL_USHORT2 (jcf, index); if (verbosity > 0) - fprintf (out, verbosity > 1 ? "%s name: %d=" : "%s ", - "NameAndType", name); + { + if (verbosity > 1) + fprintf (out, "NameAndType name: %d=", name); + else + fprintf (out, "NameAndType "); + } print_name (out, jcf, name); if (verbosity <= 1) fputc (' ', out); @@ -1002,19 +1018,17 @@ DEFUN(disassemble_method, (jcf, byte_ops, len), #define ARRAY_NEW(TYPE) ARRAY_NEW_##TYPE #define ARRAY_NEW_NUM \ INT_temp = IMMEDIATE_u1; \ - { const char *str; \ - switch (INT_temp) { \ - case 4: str = "boolean"; break; \ - case 5: str = "char"; break; \ - case 6: str = "float"; break; \ - case 7: str = "double"; break; \ - case 8: str = "byte"; break; \ - case 9: str = "short"; break; \ - case 10: str = "int"; break; \ - case 11: str = "long"; break; \ - default: str = ""; break; \ - } \ - fputc (' ', out); fprintf (out, str, INT_temp); } + { switch (INT_temp) { \ + case 4: fputs (" boolean", out); break; \ + case 5: fputs (" char", out); break; \ + case 6: fputs (" float", out); break; \ + case 7: fputs (" double", out); break; \ + case 8: fputs (" byte", out); break; \ + case 9: fputs (" short", out); break; \ + case 10: fputs (" int", out); break; \ + case 11: fputs (" long", out); break; \ + default: fprintf (out, " ", (long)INT_temp); break;\ + } } #define ARRAY_NEW_PTR \ fputc (' ', out); print_constant_ref (out, jcf, IMMEDIATE_u2); diff --git a/gcc/java/parse-scan.c b/gcc/java/parse-scan.c index 6d1b9a4b353..e69996f6c69 100644 --- a/gcc/java/parse-scan.c +++ b/gcc/java/parse-scan.c @@ -2406,7 +2406,7 @@ report_main_declaration (declarator) if (package_name) fprintf (out, "%s.%s ", package_name, current_class); else - fprintf (out, current_class); + fprintf (out, "%s", current_class); previous_output = 1; } } diff --git a/gcc/java/parse-scan.y b/gcc/java/parse-scan.y index 662323a7752..f5da6f993bf 100644 --- a/gcc/java/parse-scan.y +++ b/gcc/java/parse-scan.y @@ -1156,7 +1156,7 @@ report_main_declaration (declarator) if (package_name) fprintf (out, "%s.%s ", package_name, current_class); else - fprintf (out, current_class); + fprintf (out, "%s", current_class); previous_output = 1; } } diff --git a/gcc/java/parse.c b/gcc/java/parse.c index d19a78ca9d3..9cc96f82330 100644 --- a/gcc/java/parse.c +++ b/gcc/java/parse.c @@ -2388,10 +2388,8 @@ int yydebug; /* nonzero means print parse trace */ /* Prevent warning if -Wstrict-prototypes. */ #ifdef __GNUC__ -#ifndef YYPARSE_PARAM int yyparse (void); #endif -#endif #if __GNUC__ > 1 /* GNU C and GNU C++ define this. */ #define __yy_memcpy(TO,FROM,COUNT) __builtin_memcpy(TO,FROM,COUNT) @@ -7911,11 +7909,9 @@ read_import_dir (wfl) static int first = 1; if (first) { - char buffer [256]; - sprintf (buffer, "Can't find default package `%s'. Check " - "the CLASSPATH environment variable and the access to the " - "archives.", package_name); - error (buffer); + error ("Can't find default package `%s'. Check " + "the CLASSPATH environment variable and the access to the " + "archives.", package_name); java_error_count++; first = 0; } @@ -11717,11 +11713,14 @@ patch_assignment (node, wfl_op1, wfl_op2) strcpy (operation, "`='"); } - parse_error_context - (wfl, (!valid_cast_to_p (rhs_type, lhs_type) ? - "Incompatible type for %s. Can't convert `%s' to `%s'" : - "Incompatible type for %s. Explicit cast " - "needed to convert `%s' to `%s'"), operation, t1, t2); + if (!valid_cast_to_p (rhs_type, lhs_type)) + parse_error_context (wfl, "Incompatible type for %s. " + "Can't convert `%s' to `%s'", + operation, t1, t2); + else + parse_error_context (wfl, "Incompatible type for %s. " + "Explicit cast needed to convert `%s' to `%s'", + operation, t1, t2); free (t1); free (t2); error_found = 1; } @@ -12325,13 +12324,21 @@ patch_binop (node, wfl_op1, wfl_op2) if (!JINTEGRAL_TYPE_P (op1_type)) ERROR_CAST_NEEDED_TO_INTEGRAL (wfl_operator, node, op1_type); else - parse_error_context - (wfl_operator, (JPRIMITIVE_TYPE_P (op2_type) ? - "Incompatible type for `%s'. Explicit cast needed to convert " - "shift distance from `%s' to integral" : - "Incompatible type for `%s'. Can't convert shift distance from " - "`%s' to integral"), - operator_string (node), lang_printable_name (op2_type, 0)); + { + if (JPRIMITIVE_TYPE_P (op2_type)) + parse_error_context (wfl_operator, + "Incompatible type for `%s'. " + "Explicit cast needed to convert " + "shift distance from `%s' to integral", + operator_string (node), + lang_printable_name (op2_type, 0)); + else + parse_error_context (wfl_operator, "Incompatible type for `%s'." + " Can't convert shift distance from " + "`%s' to integral", + operator_string (node), + lang_printable_name (op2_type, 0)); + } TREE_TYPE (node) = error_mark_node; error_found = 1; break; @@ -13191,13 +13198,14 @@ patch_array_ref (node) index = do_unary_numeric_promotion (index); if (TREE_TYPE (index) != int_type_node) { - int could_cast = valid_cast_to_p (index_type, int_type_node); - parse_error_context - (wfl_operator, - (could_cast ? "Incompatible type for `[]'. Explicit cast needed to " - "convert `%s' to `int'" : "Incompatible type for `[]'. " - "Can't convert `%s' to `int'"), - lang_printable_name (index_type, 0)); + if (valid_cast_to_p (index_type, int_type_node)) + parse_error_context (wfl_operator, "Incompatible type for `[]'. " + "Explicit cast needed to convert `%s' to `int'", + lang_printable_name (index_type, 0)); + else + parse_error_context (wfl_operator, "Incompatible type for `[]'. " + "Can't convert `%s' to `int'", + lang_printable_name (index_type, 0)); TREE_TYPE (node) = error_mark_node; error_found = 1; } diff --git a/gcc/java/parse.h b/gcc/java/parse.h index cf292192b1f..f4c05e948b1 100644 --- a/gcc/java/parse.h +++ b/gcc/java/parse.h @@ -222,12 +222,19 @@ extern tree stabilize_reference PROTO ((tree)); "numeric type", operator_string ((NODE)), lang_printable_name ((TYPE), 0)) #define ERROR_CAST_NEEDED_TO_INTEGRAL(OPERATOR, NODE, TYPE) \ - parse_error_context \ - ((OPERATOR), (JPRIMITIVE_TYPE_P (TYPE) ? \ - "Incompatible type for `%s'. Explicit cast needed to convert " \ - "`%s' to integral" : "Incompatible type for `%s'. Can't convert " \ - "`%s' to integral"), operator_string ((NODE)), \ - lang_printable_name ((TYPE), 0)) +do { \ + tree _operator = (OPERATOR), _node = (NODE), _type = (TYPE); \ + if (JPRIMITIVE_TYPE_P (_type)) \ + parse_error_context (_operator, "Incompatible type for `%s'. Explicit" \ + " cast needed to convert `%s' to integral", \ + operator_string(_node), \ + lang_printable_name (_type, 0)); \ + else \ + parse_error_context (_operator, "Incompatible type for `%s'. Can't" \ + " convert `%s' to integral", \ + operator_string(_node), \ + lang_printable_name (_type, 0)); \ +} while (0) #define ERROR_VARIABLE_NOT_INITIALIZED(WFL, V) \ parse_error_context \ diff --git a/gcc/java/parse.y b/gcc/java/parse.y index 3d76576f801..0459ed36c1a 100644 --- a/gcc/java/parse.y +++ b/gcc/java/parse.y @@ -5324,11 +5324,9 @@ read_import_dir (wfl) static int first = 1; if (first) { - char buffer [256]; - sprintf (buffer, "Can't find default package `%s'. Check " - "the CLASSPATH environment variable and the access to the " - "archives.", package_name); - error (buffer); + error ("Can't find default package `%s'. Check " + "the CLASSPATH environment variable and the access to the " + "archives.", package_name); java_error_count++; first = 0; } @@ -9130,11 +9128,14 @@ patch_assignment (node, wfl_op1, wfl_op2) strcpy (operation, "`='"); } - parse_error_context - (wfl, (!valid_cast_to_p (rhs_type, lhs_type) ? - "Incompatible type for %s. Can't convert `%s' to `%s'" : - "Incompatible type for %s. Explicit cast " - "needed to convert `%s' to `%s'"), operation, t1, t2); + if (!valid_cast_to_p (rhs_type, lhs_type)) + parse_error_context (wfl, "Incompatible type for %s. " + "Can't convert `%s' to `%s'", + operation, t1, t2); + else + parse_error_context (wfl, "Incompatible type for %s. " + "Explicit cast needed to convert `%s' to `%s'", + operation, t1, t2); free (t1); free (t2); error_found = 1; } @@ -9738,13 +9739,21 @@ patch_binop (node, wfl_op1, wfl_op2) if (!JINTEGRAL_TYPE_P (op1_type)) ERROR_CAST_NEEDED_TO_INTEGRAL (wfl_operator, node, op1_type); else - parse_error_context - (wfl_operator, (JPRIMITIVE_TYPE_P (op2_type) ? - "Incompatible type for `%s'. Explicit cast needed to convert " - "shift distance from `%s' to integral" : - "Incompatible type for `%s'. Can't convert shift distance from " - "`%s' to integral"), - operator_string (node), lang_printable_name (op2_type, 0)); + { + if (JPRIMITIVE_TYPE_P (op2_type)) + parse_error_context (wfl_operator, + "Incompatible type for `%s'. " + "Explicit cast needed to convert " + "shift distance from `%s' to integral", + operator_string (node), + lang_printable_name (op2_type, 0)); + else + parse_error_context (wfl_operator, "Incompatible type for `%s'." + " Can't convert shift distance from " + "`%s' to integral", + operator_string (node), + lang_printable_name (op2_type, 0)); + } TREE_TYPE (node) = error_mark_node; error_found = 1; break; @@ -10604,13 +10613,14 @@ patch_array_ref (node) index = do_unary_numeric_promotion (index); if (TREE_TYPE (index) != int_type_node) { - int could_cast = valid_cast_to_p (index_type, int_type_node); - parse_error_context - (wfl_operator, - (could_cast ? "Incompatible type for `[]'. Explicit cast needed to " - "convert `%s' to `int'" : "Incompatible type for `[]'. " - "Can't convert `%s' to `int'"), - lang_printable_name (index_type, 0)); + if (valid_cast_to_p (index_type, int_type_node)) + parse_error_context (wfl_operator, "Incompatible type for `[]'. " + "Explicit cast needed to convert `%s' to `int'", + lang_printable_name (index_type, 0)); + else + parse_error_context (wfl_operator, "Incompatible type for `[]'. " + "Can't convert `%s' to `int'", + lang_printable_name (index_type, 0)); TREE_TYPE (node) = error_mark_node; error_found = 1; } diff --git a/gcc/java/typeck.c b/gcc/java/typeck.c index c6c1708ec3a..924265fc3ff 100644 --- a/gcc/java/typeck.c +++ b/gcc/java/typeck.c @@ -374,7 +374,11 @@ build_java_array_type (element_type, length) char buf[12]; tree elsig = build_java_signature (element_type); tree el_name = element_type; - sprintf (buf, length >= 0 ? "[%d" : "[", length); + buf[0] = '['; + if (length >= 0) + sprintf (buf+1, HOST_WIDE_INT_PRINT_DEC, length); + else + buf[1] = '\0'; sig = ident_subst (IDENTIFIER_POINTER (elsig), IDENTIFIER_LENGTH (elsig), buf, 0, 0, ""); t = IDENTIFIER_SIGNATURE_TYPE (sig); diff --git a/gcc/java/verify.c b/gcc/java/verify.c index 41eba1074f5..41ad823cb46 100644 --- a/gcc/java/verify.c +++ b/gcc/java/verify.c @@ -1344,6 +1344,6 @@ verify_jvm_instructions (jcf, byte_ops, length) goto verify_error; verify_error: error ("verification error at PC=%d", oldpc); - error (message); + error ("%s", message); return 0; } -- 2.30.2