summaryrefslogtreecommitdiff
path: root/test/bug1163046.--skeleton.c
diff options
context:
space:
mode:
authorDongHun Kwak <dh0128.kwak@samsung.com>2018-02-20 15:21:10 +0900
committerDongHun Kwak <dh0128.kwak@samsung.com>2018-02-20 15:21:20 +0900
commit010262b662c50f1aa74cbc8c75c0921c0d772043 (patch)
tree4574c5f4ebdf10dcdcab105f35ce4edb266484b4 /test/bug1163046.--skeleton.c
parent14bca63037e53bf0aa56649717f4b21554e78670 (diff)
downloadre2c-010262b662c50f1aa74cbc8c75c0921c0d772043.tar.gz
re2c-010262b662c50f1aa74cbc8c75c0921c0d772043.tar.bz2
re2c-010262b662c50f1aa74cbc8c75c0921c0d772043.zip
Imported Upstream version 1.0.3upstream/1.0.3
Change-Id: If88247edb45f7ce9413d4b25db30833c808f7436 Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'test/bug1163046.--skeleton.c')
-rw-r--r--test/bug1163046.--skeleton.c39
1 files changed, 26 insertions, 13 deletions
diff --git a/test/bug1163046.--skeleton.c b/test/bug1163046.--skeleton.c
index c0122fec..bd7fbe1f 100644
--- a/test/bug1163046.--skeleton.c
+++ b/test/bug1163046.--skeleton.c
@@ -1,7 +1,9 @@
/* Generated by re2c */
+#include <stddef.h> /* size_t */
#include <stdio.h>
#include <stdlib.h> /* malloc, free */
+#include <string.h> /* memcpy */
static void *read_file
( const char *fname
@@ -58,7 +60,7 @@ error:
#define YYFILL(n) { break; }
static int action_line26
- ( unsigned int i
+ ( unsigned *pkix
, const YYKEYTYPE *keys
, const YYCTYPE *start
, const YYCTYPE *token
@@ -66,10 +68,12 @@ static int action_line26
, YYKEYTYPE rule_act
)
{
+ const unsigned kix = *pkix;
const long pos = token - start;
const long len_act = *cursor - token;
- const long len_exp = (long) keys [3 * i + 1];
- const YYKEYTYPE rule_exp = keys [3 * i + 2];
+ const long len_exp = (long) keys[kix + 1];
+ const YYKEYTYPE rule_exp = keys[kix + 2];
+ *pkix = kix + 3;
if (rule_exp == 255) {
fprintf
( stderr
@@ -79,17 +83,17 @@ static int action_line26
);
}
if (len_act == len_exp && rule_act == rule_exp) {
- const YYKEYTYPE offset = keys[3 * i];
+ const YYKEYTYPE offset = keys[kix];
*cursor = token + offset;
return 0;
} else {
fprintf
( stderr
- , "error: lex_line26: at position %ld (iteration %u):\n"
+ , "error: lex_line26: at position %ld (key %u):\n"
"\texpected: match length %ld, rule %u\n"
"\tactual: match length %ld, rule %u\n"
, pos
- , i
+ , kix
, len_exp
, rule_exp
, len_act
@@ -99,6 +103,13 @@ static int action_line26
}
}
+static int check_key_count_line26(unsigned have, unsigned used, unsigned need)
+{
+ if (used + need <= have) return 0;
+ fprintf(stderr, "error: lex_line26: not enough keys\n");
+ return 1;
+}
+
int lex_line26()
{
const size_t padding = 45; /* YYMAXFILL */
@@ -126,7 +137,7 @@ int lex_line26()
keys = (YYKEYTYPE *) read_file
("bug1163046.--skeleton.c.line26.keys"
- , 3 * sizeof (YYKEYTYPE)
+ , sizeof (YYKEYTYPE)
, 0
, &keys_count
);
@@ -139,7 +150,7 @@ int lex_line26()
limit = input + input_len + padding;
eof = input + input_len;
- for (i = 0; status == 0 && i < keys_count; ++i) {
+ for (i = 0; status == 0 && cursor < eof && i < keys_count;) {
token = cursor;
const YYCTYPE *marker = NULL;
YYCTYPE yych;
@@ -153,12 +164,14 @@ int lex_line26()
}
yy2:
YYSKIP ();
- status = action_line26(i, keys, input, token, &cursor, 2);
+ status = check_key_count_line26(keys_count, i, 3)
+ || action_line26(&i, keys, input, token, &cursor, 2);
continue;
yy4:
YYSKIP ();
yy5:
- status = action_line26(i, keys, input, token, &cursor, 1);
+ status = check_key_count_line26(keys_count, i, 3)
+ || action_line26(&i, keys, input, token, &cursor, 1);
continue;
yy6:
YYSKIP ();
@@ -507,7 +520,8 @@ yy50:
}
yy51:
YYSKIP ();
- status = action_line26(i, keys, input, token, &cursor, 0);
+ status = check_key_count_line26(keys_count, i, 3)
+ || action_line26(&i, keys, input, token, &cursor, 0);
continue;
}
@@ -519,7 +533,7 @@ yy51:
}
if (i != keys_count) {
status = 1;
- fprintf(stderr, "error: lex_line26: unused keys left after %u iterations\n", i);
+ fprintf(stderr, "error: lex_line26: unused keys left after %u keys\n", i);
}
}
@@ -538,7 +552,6 @@ end:
#undef YYRESTORE
#undef YYLESSTHAN
#undef YYFILL
-#define YYMAXFILL 45
int main()
{