Overflow warning when using Format
If you write this code.
local procedure Test()
var
Tmp: Text[10];
begin
Tmp := Format('', 8);
end;
You get a:
"Possible overflow assigning 'Text' to 'Text[10]'.
As Format actually truncates the string, if it is longer than the specified number, I think that this shouldn't raise the warning.
Tested on AL language vsix of CU03: 2.1.79379
Best regards.
Hi @Nyryus, you can always use rulesets to hide analyzer messages you don't want to see.
I do understand that in the case of the Format function, the second argument controls the length and therefore the analyzer is clearly warning for a non-existing scenario if that length is <= the length of the variable being assigned to. However, it's not feasible for the analyzer to be aware of the potential return sizes of a function depending on it's input.
Thanks,
Johan
Hi @JohanStenberg100
I don't think that's the case where rulesets are the best solution, because that's a warning that shouldn't have been raised. Not something that I don't want to see.
The same warning appears with this code. NAV runs it correctly and the message contains the text 'test messa', truncating the result.
local procedure Test()
var
Tmp: Text[10];
TestString : Text[15];
begin
TestString := 'test message';
Tmp := Format(TestString, 10);
Message(tmp);
end;
While if I use this code, it returns no warning and the output is the same.
local procedure Test()
var
Tmp: Text[10];
TestString : Text[15];
begin
TestString := 'test message';
Tmp := CopyStr(TestString, 1, 10);
Message(tmp);
end;
Best regards,
Nyryus
Hi again @Nyryus, I was wrong originally as you pointed out. Let me re-open this issue and treat it as an enhancement request. Thanks!
Format should not give an error for cases like this. Please reopen if this is still an issue.