Global string (char*) value indirect store, to fix segfault

Because, as OriansJ found, we don't want to read the first bytes of the
value as a pointer. See global_load() for programs like:

char* s = "xyzzy\n";
int main(void){ file_print(s, 1); return 0; }

There's an alternative: "fix the GLOBAL behavior to be type sensitive" but
this indirect store was choosen because it "preserve[s] the ability to
assign new strings to a global char*".
This commit is contained in:
deesix 2019-04-18 16:48:41 +02:00
parent 420f8b62b9
commit a3acf66077
3 changed files with 11 additions and 4 deletions

View File

@ -1534,6 +1534,13 @@ new_type:
}
else if(('"' == global_token->s[0]))
{ /* Assume a string*/
globals_list = emit("&GLOBAL_", globals_list);
globals_list = emit(global_token->prev->prev->s, globals_list);
globals_list = emit("_contents\n", globals_list);
globals_list = emit(":GLOBAL_", globals_list);
globals_list = emit(global_token->prev->prev->s, globals_list);
globals_list = emit("_contents\n", globals_list);
globals_list = emit(parse_string(global_token->s), globals_list);
}
else

View File

@ -45,9 +45,9 @@ b40d198af6c31f1af513ec70c6be9c6daa43cccf48a7191f4d984f81cdfbf623 test/results/t
1154f39f25dcd6d914e9a542306f95280926baf985d011b2152c7ea0b87ab42d test/results/test10-knight-native-binary
c1b5a2a3cd46c5e95e5540e871c2a916e028684ca80f51c001ef489342e27625 test/results/test10-knight-posix-binary
020e86020819cc4963e6185b22e534fcf8306b6cb116f12643f254a24688ff0a test/results/test10-x86-binary
ddf6194da431d9cd7fee7e1daef805d6070582160a7ca9246a69ee7acba4c2e7 test/results/test100-armv7l-binary
46310bf40574fbc3d9474de0bc6f63e83072d39825997de697f4ba5a9a9a139c test/results/test100-knight-posix-binary
ad3d2b2d8893bec961b28d249f38766c76a6edaead66acd2b04833631e992ad4 test/results/test100-x86-binary
68e1659a4cfcb61f78476144ec19f7869c9ba7f933bcf49490224c74557f0453 test/results/test100-armv7l-binary
c84ac8afbfae1eab10e3993a9dfbc8cf65238cb12aae403f7b7bbc35dd8197fd test/results/test100-knight-posix-binary
92527abb77f29e00bfdfb494126ec2996bf5bc4764f919f766dbaaa47d0a129a test/results/test100-x86-binary
d9d465340abbce2d5964a6bc58e6cdd0ef93fb3d0199eaa823c86ec6abd0452a test/results/test11-armv7l-binary
955b564d2c89abf2cfc6c80d766cd11479d146b828dec69e654b0958a62d5e6e test/results/test11-knight-native-binary
63fd5fbf389d1b19031026df193ec55e98d923b8568007125b80bc246c094496 test/results/test11-knight-posix-binary

View File

@ -1 +1 @@
fa938b90d4dc96f81285c982432d444255e7958adf26eb5e621c5ce232bd01ab test/test100/proof
8ba20fc011941e6ad6bf17672820e0fafae7ac604f7730d138e1bb1c291d919a test/test100/proof