From de60bfab9c88940d97a8df86710a2184d21c51b7 Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Sun, 2 Oct 2016 12:56:40 +0000 Subject: [PATCH] * make the string data of pchar constants read-only (mantis #30666) git-svn-id: trunk@34594 - --- .gitattributes | 1 + compiler/ngtcon.pas | 2 +- tests/webtbs/tw30666.pp | 29 +++++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tests/webtbs/tw30666.pp diff --git a/.gitattributes b/.gitattributes index 1a5e04d2a5..c43125b81d 100644 --- a/.gitattributes +++ b/.gitattributes @@ -15236,6 +15236,7 @@ tests/webtbs/tw30570.pp svneol=native#text/plain tests/webtbs/tw30572.pp svneol=native#text/plain tests/webtbs/tw3063.pp svneol=native#text/plain tests/webtbs/tw3064.pp svneol=native#text/plain +tests/webtbs/tw30666.pp svneol=native#text/plain tests/webtbs/tw3073.pp svneol=native#text/plain tests/webtbs/tw3082.pp svneol=native#text/plain tests/webtbs/tw3083.pp svneol=native#text/plain diff --git a/compiler/ngtcon.pas b/compiler/ngtcon.pas index 5a2abba1a1..b9bab264a1 100644 --- a/compiler/ngtcon.pas +++ b/compiler/ngtcon.pas @@ -816,7 +816,7 @@ function get_next_varsym(def: tabstractrecorddef; const SymList:TFPHashObjectLis begin { create a tcb for the string data (it's placed in a separate asmlist) } - ftcb.start_internal_data_builder(fdatalist,sec_rodata,'',datatcb,ll); + ftcb.start_internal_data_builder(fdatalist,sec_rodata_norel,'',datatcb,ll); if node.nodetype=stringconstn then varalign:=size_2_align(tstringconstnode(node).len) else diff --git a/tests/webtbs/tw30666.pp b/tests/webtbs/tw30666.pp new file mode 100644 index 0000000000..d9d2d850bd --- /dev/null +++ b/tests/webtbs/tw30666.pp @@ -0,0 +1,29 @@ +{ %target=linux,darwin,freebsd,openbsd,netbsd,aix,solaris,android,win32,win64 } + +{$mode objfpc} + +uses + sysutils; + +procedure foo; +var + s: PChar = 'PChar'; + b: boolean; +begin + b:=false; + try + s[0] := 'a'; + except + on e: exception do + begin + if e is EAccessViolation then + b:=true; + end; + end; + if not b then + halt(1); +end; + +begin + foo; +end.