This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Sanity check for switch array


Joseph S. Myers wrote:-

> A --enable-checking test at startup that the array _is_ sorted would be a
> good idea.

I've applied this.

Neil.

	* c-opts.c (c_common_init_options): Check option array is
	sorted if checking enabled.

Index: c-opts.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-opts.c,v
retrieving revision 1.9
diff -u -p -r1.9 c-opts.c
--- c-opts.c	12 Aug 2002 22:44:29 -0000	1.9
+++ c-opts.c	13 Aug 2002 06:47:47 -0000
@@ -495,6 +495,14 @@ c_common_init_options (lang)
      runtime.  */
   qsort (cl_options, N_OPTS, sizeof (struct cl_option), opt_comp);
 #endif
+#if ENABLE_CHECKING
+  size_t i;
+
+  for (i = 1; i < N_OPTS; i++)
+    if (strcmp (cl_options[i - 1].opt_text, cl_options[i].opt_text) >= 0)
+      error ("options array incorrectly sorted: %s is before %s",
+	     cl_options[i - 1].opt_text, cl_options[i].opt_text);
+#endif
 
   c_language = lang;
   parse_in = cpp_create_reader (lang == clk_c ? CLK_GNUC89 : CLK_GNUCXX);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]