Forum > General

AV during runtime, because Compiler does not check the String-Format by "Format"

<< < (2/5) > >>

Eugene Loza:
I must admit I really love C# interpolated strings in this context. Compile-time validation of syntax is really cool.

I guess in current game project I'm working on like half of all of the crashes are because of Format parameters mismatch. The most annoying are when it crashes when trying to report an error :D

Thaddy:

--- Quote from: paule32 on April 07, 2024, 11:41:11 pm ---and, how Assert work ? - is it a RTL Function, too ?

--- End quote ---
it is a compiler intrinsic. see
https://www.freepascal.org/docs-html/rtl/system/assert.html

rvk:

--- Quote from: Eugene Loza on April 08, 2024, 06:56:51 am ---I must admit I really love C# interpolated strings in this context. Compile-time validation of syntax is really cool.

--- End quote ---
How would this work if the function call itself has a variable string for the format-string?


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function foo(A, B: String; C, D: Integer): String;begin  result := Format(A + B, [C, D]);end;
How would the compiler check if A + B has the correct %s or %d. Not to speak about the number of parameters etc.

How is this done in C#?

Thaddy:

--- Quote from: paule32 on April 04, 2024, 12:57:34 pm ---Hello,
- I download, and compile the latest FPC 3.2.2
- I faced with Format - a string operation function in following way:

Format('text: %d', [ IntToStr( aLongIntVariable ) ]);

I get no Compiler error.
But I get AV during runtime - else:

Format('text: %s', [ IntToStr( aLongIntVariable ) ]);

the format will not checked during compile.
But I get no AV during runtime.

Is there a possibility, to set a switch or option, that check the format of the string
within the Format function ?

--- End quote ---
It looks the other way around: the first should fail and the second is simply correct.
also, an EConvertError will be raised that you can handle with try/except.

rvk:

--- Quote from: paule32 on April 04, 2024, 12:57:34 pm ---Format('text: %d', [ IntToStr( aLongIntVariable ) ]);

I get no Compiler error.
But I get AV during runtime:

--- End quote ---
BTW. This doesn't give an AV during runtime.
If it does, then there is something else wrong.
It should give you an Exception during runtime (that's something else than a AV).

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version