summaryrefslogtreecommitdiff
path: root/gcc/java/jvspec.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2002-02-23 00:42:13 +0000
committerTom Tromey <tromey@gcc.gnu.org>2002-02-23 00:42:13 +0000
commitd2fb5329006990b3f6a6cf970d7df89071e58815 (patch)
treea9aa161b2a2ed17d5282aa7af46a3e9aebac3d51 /gcc/java/jvspec.c
parent9abe2e29b4cc5e50af73f2371acbb7a6fcf234e3 (diff)
downloadgcc-d2fb5329006990b3f6a6cf970d7df89071e58815.tar.gz
re PR java/2369 (--main should check the following symbol)
Fix for PR java/2369: * jvspec.c (verify_class_name): New function. (lang_specific_driver): Call it. (JAVA_START_CHAR_P): New macro. (JAVA_PART_CHAR_P): Likewise. From-SVN: r49981
Diffstat (limited to 'gcc/java/jvspec.c')
-rw-r--r--gcc/java/jvspec.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/gcc/java/jvspec.c b/gcc/java/jvspec.c
index dba2ee6929f..5bb3e9d164b 100644
--- a/gcc/java/jvspec.c
+++ b/gcc/java/jvspec.c
@@ -46,6 +46,7 @@ The Free Software Foundation is independent of Sun Microsystems, Inc. */
#define RESOURCE_FILE_ARG (1<<7)
static char *find_spec_file PARAMS ((const char *));
+static int verify_class_name PARAMS ((const char *));
static const char *main_class_name = NULL;
int lang_specific_extra_outfiles = 0;
@@ -98,6 +99,45 @@ find_spec_file (dir)
return NULL;
}
+/* FIXME: these should come from lex.h. */
+#define JAVA_START_CHAR_P(c) (c < 128 && (ISIDST (c) || c == '$'))
+#define JAVA_PART_CHAR_P(c) (c < 128 \
+ && (ISIDNUM (c) \
+ || c == '$' \
+ || (c >= 0x00 && c <= 0x08) \
+ || (c >= 0x0e && c <= 0x1b) \
+ || c == 0x7f))
+
+/* Verify that NAME is a valid Java class name that might contain
+ `main'. Return 0 on failure. */
+static int
+verify_class_name (name)
+ const char *name;
+{
+ /* FIXME: what encoding do we use for command-line arguments? For
+ now we assume plain ASCII, which of course is wrong. */
+ while (*name)
+ {
+ int ch = *name++;
+ if (ch < 0 || ! JAVA_START_CHAR_P (ch))
+ return 0;
+ while (*name)
+ {
+ ch = *name++;
+ if (ch < 0)
+ return 0;
+ /* We found a break between class names. Next character
+ must be an identifier start again. */
+ if (ch == '.')
+ break;
+ if (! JAVA_PART_CHAR_P (ch))
+ return 0;
+ }
+ }
+
+ return 1;
+}
+
void
lang_specific_driver (in_argc, in_argv, in_added_libraries)
int *in_argc;
@@ -383,6 +423,9 @@ lang_specific_driver (in_argc, in_argv, in_added_libraries)
if (saw_D && ! main_class_name)
fatal ("can't specify `-D' without `--main'\n");
+ if (main_class_name && ! verify_class_name (main_class_name))
+ fatal ("`%s' is not a valid class name", main_class_name);
+
num_args = argc + added;
if (saw_R)
{