sonar-delphi icon indicating copy to clipboard operation
sonar-delphi copied to clipboard

Detect that a function pointer parameter has not the right size

Open zedalaye opened this issue 1 year ago • 4 comments

Prerequisites

  • [X] This rule has not already been suggested.
  • [X] This should be a new rule, not an improvement to an existing rule.
  • [X] This rule would be generally useful, not specific to my code or setup.

Suggested rule title

Pointers parameters should have the right size

Rule description

Check that pointer parameters have the right size according to the compiler architecture.

Rationale

In a migration process from Win32 to Win64, I encountered this error :

  n := tmpp.Count;
  p := nil;
  DynArraySetLength(p, field_type, 1, @n);

The code was build for Win32, so n was an Integer Now DynArraySetLength takes a PNativeInt which is 64bits wide under Win64 and the Delphi compiler does not emit a single warning about this critical issue.

Would be awesome if Sonarqube could help finding those problems.

zedalaye avatar Oct 17 '24 15:10 zedalaye