Download tasks/csa159/pair_137200/patch.diff from Benchanything/checkerbench: direct link, hf CLI and curl.
- Browser
- Download file 2.43 kB
-
https://huggingface.co/datasets/Benchanything/checkerbench/resolve/main/tasks/csa159/pair_137200/patch.diff
- Command line
-
hf download hf://datasets/Benchanything/checkerbench/tasks/csa159/pair_137200/patch.diff
-
curl -L -o patch.diff https://huggingface.co/datasets/Benchanything/checkerbench/resolve/main/tasks/csa159/pair_137200/patch.diff
2.43 kB
| diff --git a/regexp.c b/regexp.c | |
| index 01c18a3..4a5948b 100644 | |
| --- a/regexp.c | |
| +++ b/regexp.c | |
| #define REPINF 255 | |
| #define MAXTHREAD 1000 | |
| #define MAXSUB REG_MAXSUB | |
| +#define MAXPROG (32 << 10) | |
| typedef struct Reclass Reclass; | |
| typedef struct Renode Renode; | |
| struct Reinst { | |
| Reinst *y; | |
| }; | |
| -static int count(Renode *node) | |
| +static int count(struct cstate *g, Renode *node) | |
| { | |
| - int min, max; | |
| + int min, max, n; | |
| if (!node) return 0; | |
| switch (node->type) { | |
| default: return 1; | |
| - case P_CAT: return count(node->x) + count(node->y); | |
| - case P_ALT: return count(node->x) + count(node->y) + 2; | |
| + case P_CAT: return count(g, node->x) + count(g, node->y); | |
| + case P_ALT: return count(g, node->x) + count(g, node->y) + 2; | |
| case P_REP: | |
| min = node->m; | |
| max = node->n; | |
| - if (min == max) return count(node->x) * min; | |
| - if (max < REPINF) return count(node->x) * max + (max - min); | |
| - return count(node->x) * (min + 1) + 2; | |
| - case P_PAR: return count(node->x) + 2; | |
| - case P_PLA: return count(node->x) + 2; | |
| - case P_NLA: return count(node->x) + 2; | |
| + if (min == max) n = count(g, node->x) * min; | |
| + else if (max < REPINF) n = count(g, node->x) * max + (max - min); | |
| + else n = count(g, node->x) * (min + 1) + 2; | |
| + if (n < 0 || n > MAXPROG) die(g, "program too large"); | |
| + return n; | |
| + case P_PAR: return count(g, node->x) + 2; | |
| + case P_PLA: return count(g, node->x) + 2; | |
| + case P_NLA: return count(g, node->x) + 2; | |
| } | |
| } | |
| Reprog *regcompx(void *(*alloc)(void *ctx, void *p, int n), void *ctx, | |
| struct cstate g; | |
| Renode *node; | |
| Reinst *split, *jump; | |
| - int i; | |
| + int i, n; | |
| g.pstart = NULL; | |
| g.prog = NULL; | |
| Reprog *regcompx(void *(*alloc)(void *ctx, void *p, int n), void *ctx, | |
| if (g.lookahead != 0) | |
| die(&g, "syntax error"); | |
| +#ifdef TEST | |
| + dumpnode(node); | |
| + putchar('\n'); | |
| +#endif | |
| + | |
| + n = 6 + count(&g, node); | |
| + if (n < 0 || n > MAXPROG) | |
| + die(&g, "program too large"); | |
| + | |
| g.prog->nsub = g.nsub; | |
| - g.prog->start = g.prog->end = alloc(ctx, NULL, (count(node) + 6) * sizeof (Reinst)); | |
| + g.prog->start = g.prog->end = alloc(ctx, NULL, n * sizeof (Reinst)); | |
| if (!g.prog->start) | |
| die(&g, "cannot allocate regular expression instruction list"); | |
| Reprog *regcompx(void *(*alloc)(void *ctx, void *p, int n), void *ctx, | |
| emit(g.prog, I_END); | |
| #ifdef TEST | |
| - dumpnode(node); | |
| - putchar('\n'); | |
| dumpprog(g.prog); | |
| #endif |