diff options
| author | 2026-10-14 10:38:17 +0000 | |
|---|---|---|
| committer | 2026-10-14 10:38:17 +0000 | |
| commit | 93340f97dce404a008f489729df144ace53528ab (patch) | |
| tree | cbada309f3a4683d083d84484f11952418c8dd2b /tests/programs/capture_long.zc | |
| parent | todo: handoff section with state, conventions, in-flight work and architectur... (diff) | |
fix std hover, full capture terminator, bare static calls, void main in run-only images
- hover: a symbol from an embedded library source (tinyvm:std.zc, tinyvm:icon.zc) was
looked up only in the document; look it up by its qualified name in the library source
(hover_embedded_sym), and render a method found that way by its line (bs_hover).
- std.capture: allocate one word more than the 256 it holds, so end() terminates inside the buffer.
- a bare call to a static function of the enclosing struct resolves like a bare struct constant
(mstruct is set for every non-generic struct's methods); the struct's own wins over a global.
- run.zc declares main untyped (fn main();), so a run-only image accepts int, void or untyped main
with both compilers.
Diffstat (limited to 'tests/programs/capture_long.zc')
| -rw-r--r-- | tests/programs/capture_long.zc | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/programs/capture_long.zc b/tests/programs/capture_long.zc new file mode 100644 index 0000000..52736a4 --- /dev/null +++ b/tests/programs/capture_long.zc @@ -0,0 +1,26 @@ +namespace; +include rt, std; + +// a capture holds 256 characters and drops the rest. end() must still put its +// 0 inside the buffer, even when the capture was full: the length is 256 and the +// last kept character is the 256th one written (index 255, 'a' + 255 % 26 = 'v'). +// a block allocated right after the buffer is checked afterwards: a 0 written one +// word past the buffer would land in its header and read as a bad or freed block. +memdebug on; // header checks make a write into a neighbouring block visible +fn capture_long() { + let buf = std.capture.start(); + int* next = rt.new(8); + int i = 0; + while (i < 300) { rt.put_c('a' + i % 26); i++; } + std.capture.end(buf); + next[0] = 7; // stops with "bad heap pointer" if its header was overwritten + rt.put_n(next[0]); rt.put_c(10); // 7 + return buf; +} +memdebug off; // the header check only searches 64 words back, so the long buffer is read unchecked +fn main() { + char* buf = capture_long(); + rt.put_n(rt.len_w(buf)); rt.put_c(10); // 256 + rt.put_c(buf[255]); rt.put_c(10); // v + return 0; +} |
