diff options
author | jonas <jonas@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2009-11-01 17:18:40 +0000 |
---|---|---|
committer | jonas <jonas@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2009-11-01 17:18:40 +0000 |
commit | 3795a057220d84e8c29e4b1ff6a6f05b12963a89 (patch) | |
tree | 3e1b1ec9d2f4f031adab525959afda36bb610efa | |
parent | d7e377509bded3e988d146967239e3f4d19d879c (diff) | |
download | fpc-3795a057220d84e8c29e4b1ff6a6f05b12963a89.tar.gz |
* give a proper error when trying to use val() on a boolean (mantis #14777)
* don't allow a boolean or (wide)char to be used as the "error" parameter
for val()
git-svn-id: http://svn.freepascal.org/svn/fpc/trunk@14006 3ad0048d-3df7-0310-abae-a5850022a9f2
-rw-r--r-- | compiler/ninl.pas | 6 | ||||
-rw-r--r-- | tests/webtbf/tw14777.pp | 10 | ||||
-rw-r--r-- | tests/webtbf/tw14777a.pp | 10 |
3 files changed, 24 insertions, 2 deletions
diff --git a/compiler/ninl.pas b/compiler/ninl.pas index 1602a589b7..a20a465d47 100644 --- a/compiler/ninl.pas +++ b/compiler/ninl.pas @@ -1121,7 +1121,7 @@ implementation { check if codepara is valid } if assigned(codepara) and ( - (codepara.resultdef.typ <> orddef) + not is_integer(codepara.resultdef) {$ifndef cpu64bitaddr} or is_64bitint(codepara.resultdef) {$endif not cpu64bitaddr} @@ -1132,7 +1132,9 @@ implementation end; { check if dest para is valid } - if not(destpara.resultdef.typ in [orddef,floatdef,enumdef]) then + if not is_integer(destpara.resultdef) and + not is_currency(destpara.resultdef) and + not(destpara.resultdef.typ in [floatdef,enumdef]) then begin CGMessagePos(destpara.fileinfo,type_e_integer_or_real_expr_expected); exit; diff --git a/tests/webtbf/tw14777.pp b/tests/webtbf/tw14777.pp new file mode 100644 index 0000000000..2343cec0b9 --- /dev/null +++ b/tests/webtbf/tw14777.pp @@ -0,0 +1,10 @@ +{ %fail } + +var + S: String; + B: Boolean; + E: Word; +begin + S := '0'; + Val(S, B, E); +end. diff --git a/tests/webtbf/tw14777a.pp b/tests/webtbf/tw14777a.pp new file mode 100644 index 0000000000..58896f03a7 --- /dev/null +++ b/tests/webtbf/tw14777a.pp @@ -0,0 +1,10 @@ +{ %fail } + +var + S: String; + B: Boolean; + E: Word; +begin + S := '0'; + Val(S, E, B); +end. |