Reputation: 256881
I recently tried using Range Checking in my application, in an attempt to catch array bounds violations, etc.
Unfortuantly this has caused quite a few non-errors relating to HRESULT
:
var
hr: HRESULT;
begin
hr := E_UNEXPECTED;
ShowMessage(SysErrorMessage(hr));
The call to SysErrorMessage
fails with a ERangeError. That is because:
HRESULT = type Longint; { from wtypes.h }
function SysErrorMessage(ErrorCode: Cardinal): string;
The solution is simple: manually force a conversion to Cardinal
every time i pass an HRESULT
to SysErrorMessage
.
This works well enough for code in the current project i'm working on - do a search for SysErrorMessage
and scan the results for where I might be passing an HRESULT
:
But it fails when there is code in shared libraries. And it also fails when there might be other constructs where i'm passing a signed to unsigned and vice versa.
Does the compiler have a warning option to catch when i mix signed and unsigned types? Obviously i'm going to disable the use of range checking.
All the WinSock functions return Integer:
int WSAAPI getaddrinfo(
_In_opt_ PCSTR pNodeName,
_In_opt_ PCSTR pServiceName,
_In_opt_ const ADDRINFOA *pHints,
_Out_ PADDRINFOA *ppResult
);
int WSAGetLastError(void);
Jcl/Jvcl has a lot of fixin to be doin.
Upvotes: 2
Views: 523
Reputation: 613232
Does the compiler have a warning option to catch when i mix signed and unsigned types?
W1024 will collect mixed arithmetic and comparisons. But there's nothing at compile time for assignment or parameter passing, which is essentially the same as assignment.
Upvotes: 1