temp_storage_escape
Finds temporary storage (tprint, talloc, or a procedure returning it) stored in a global or through a pointer, or returned.
Category pedantic, allow by default.
Off by default; the example is shown with the rule enabled.
#import "Basic";
current_label: string;
set_label :: (id: int) {
current_label = tprint("item %", id);
}
main :: () {
set_label(1);
print("%\n", current_label);
}warning[temp_storage_escape]: `tprint` holds temporary storage, which is reset, but it is kept in a global
--> example.jai:6:21
|
6 | current_label = tprint("item %", id);
| ^^^^^^^^^^^^^^^^^^^^
| -------------------- temporary storage allocated here
|
= help: copy it first (`copy_string`) so it outlives the reset#import "Basic";
current_label: string;
set_label :: (id: int) {
free(current_label);
current_label = sprint("item %", id);
}
main :: () {
set_label(1);
print("%\n", current_label);
}Off by default: handing back a temporary string from a helper is a common, documented convention. Fires when temporary memory is kept past a reset or a restored mark (auto_release_temp) that frees it. Values baked at compile time are copied out, so a tprint in a constant is fine.