diff mbox

[GSoC,match-and-simplify] check for capture index

Message ID CAJXstsB77Bp_B_6-WxUuFuWri0raNhfmGAny3hk=1NwjdWQfSw@mail.gmail.com
State New
Headers show

Commit Message

Prathamesh Kulkarni June 18, 2014, 1:07 p.m. UTC
Put a check for capture index.

* genmatch.c (parse_capture): Add condition to check capture index.
                     (capture_max): New constant.
                     (stdlib.h): Include.

Thanks and Regards,
Prathamesh

Comments

Richard Biener June 23, 2014, 8:56 a.m. UTC | #1
On Wed, Jun 18, 2014 at 3:07 PM, Prathamesh Kulkarni
<bilbotheelffriend@gmail.com> wrote:
> Put a check for capture index.
>
> * genmatch.c (parse_capture): Add condition to check capture index.
>                      (capture_max): New constant.
>                      (stdlib.h): Include.

I'd rather record the maximum seen capture index and remove that
fixed-size everywhere ...

Thanks,
Richard.

> Thanks and Regards,
> Prathamesh
diff mbox

Patch

Index: genmatch.c
===================================================================
--- genmatch.c	(revision 211732)
+++ genmatch.c	(working copy)
@@ -29,7 +29,9 @@  along with GCC; see the file COPYING3.
 #include "hashtab.h"
 #include "hash-table.h"
 #include "vec.h"
+#include <stdlib.h>
 
+const unsigned capture_max = 4;
 
 /* libccp helpers.  */
 
@@ -816,7 +818,11 @@  static struct operand *
 parse_capture (cpp_reader *r, operand *op)
 {
   eat_token (r, CPP_ATSIGN);
-  return new capture (get_number (r), op);
+  const cpp_token *token = peek (r);
+  const char *num = get_number (r);
+  if (atoi (num) >= capture_max)
+    fatal_at (token, "capture cannot be greater than %u", capture_max - 1);
+  return new capture (num, op);
 }
 
 /* Parse