MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / build_perl_nested_calls

Function build_perl_nested_calls

tests/repro/repro_issue471.c:119–155  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

117 * would trip -Werror=unused-function. */
118static char *build_perl_nested_calls(int depth) __attribute__((unused));
119static char *build_perl_nested_calls(int depth) {
120 /*
121 * Header: "sub f { return $_[0]; }\nmy $x = " (~32 bytes)
122 * Per open: "f(" (2 bytes each)
123 * Inner literal: "1" (1 byte)
124 * Per close: ")" (1 byte each)
125 * Trailer: ";\n" (2 bytes)
126 * Null: 1 byte
127 *
128 * Total upper bound: 40 + depth*2 + 1 + depth + 3 = depth*3 + 44
129 */
130 size_t sz = (size_t)depth * 3 + 64;
131 char *buf = (char *)malloc(sz);
132 if (!buf) return NULL;
133
134 char *p = buf;
135 p += snprintf(p, sz, "sub f { return $_[0]; }\nmy $x = ");
136
137 /* NESTING_DEPTH levels of `f(` */
138 for (int i = 0; i < depth; i++) {
139 *p++ = 'f';
140 *p++ = '(';
141 }
142
143 /* innermost literal */
144 *p++ = '1';
145
146 /* matching closing parens */
147 for (int i = 0; i < depth; i++) {
148 *p++ = ')';
149 }
150
151 /* statement terminator */
152 p += snprintf(p, (size_t)(buf + sz - p), ";\n");
153
154 return buf;
155}
156
157/*
158 * repro_issue471_glr_nested_ambiguity_terminates

Callers 1

repro_issue471.cFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected