mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-18 04:09:11 +02:00
* Improved warning "Converting pointers to signed integers may result in wrong comparison results and range errors, use an unsigned type instead.":
- check for procedure and class pointers as well; - do not warn if typecasted pointer is passed as parameter or directly assigned to a variable. git-svn-id: trunk@9264 -
This commit is contained in:
parent
807a18e109
commit
4e3547c7bf
@ -497,6 +497,8 @@ implementation
|
|||||||
internalerror(200305091);
|
internalerror(200305091);
|
||||||
expr.fileinfo:=fileinfo;
|
expr.fileinfo:=fileinfo;
|
||||||
callparaflags:=[];
|
callparaflags:=[];
|
||||||
|
if expr.nodetype = typeconvn then
|
||||||
|
ttypeconvnode(expr).warn_pointer_to_signed:=false;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor tcallparanode.destroy;
|
destructor tcallparanode.destroy;
|
||||||
|
@ -37,6 +37,7 @@ interface
|
|||||||
totypedef : tdef;
|
totypedef : tdef;
|
||||||
totypedefderef : tderef;
|
totypedefderef : tderef;
|
||||||
convtype : tconverttype;
|
convtype : tconverttype;
|
||||||
|
warn_pointer_to_signed: boolean;
|
||||||
constructor create(node : tnode;def:tdef);virtual;
|
constructor create(node : tnode;def:tdef);virtual;
|
||||||
constructor create_explicit(node : tnode;def:tdef);
|
constructor create_explicit(node : tnode;def:tdef);
|
||||||
constructor create_internal(node : tnode;def:tdef);
|
constructor create_internal(node : tnode;def:tdef);
|
||||||
@ -661,10 +662,6 @@ implementation
|
|||||||
muln:
|
muln:
|
||||||
cgmessage1(type_h_convert_mul_operands_to_prevent_overflow,def.gettypename);
|
cgmessage1(type_h_convert_mul_operands_to_prevent_overflow,def.gettypename);
|
||||||
end;
|
end;
|
||||||
{Converting pointers to signed integers is a bad idea. Warn.}
|
|
||||||
if (node.resultdef<>nil) and (node.resultdef.typ=pointerdef) and
|
|
||||||
(def.typ=orddef) and (Torddef(def).ordtype in [s8bit,s16bit,s32bit,s64bit]) then
|
|
||||||
cgmessage(type_w_pointer_to_signed);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -1923,6 +1920,8 @@ implementation
|
|||||||
((resultdef.typ=orddef) and
|
((resultdef.typ=orddef) and
|
||||||
(left.resultdef.typ in [pointerdef,procvardef,classrefdef]))) then
|
(left.resultdef.typ in [pointerdef,procvardef,classrefdef]))) then
|
||||||
begin
|
begin
|
||||||
|
{Converting pointers to signed integers is a bad idea. Warn.}
|
||||||
|
warn_pointer_to_signed:=(resultdef.typ=orddef) and (Torddef(resultdef).ordtype in [s8bit,s16bit,s32bit,s64bit]);
|
||||||
{ Give a warning when sizes don't match, because then info will be lost }
|
{ Give a warning when sizes don't match, because then info will be lost }
|
||||||
if left.resultdef.size=resultdef.size then
|
if left.resultdef.size=resultdef.size then
|
||||||
CGMessage(type_h_pointer_to_longint_conv_not_portable)
|
CGMessage(type_h_pointer_to_longint_conv_not_portable)
|
||||||
@ -2687,6 +2686,8 @@ implementation
|
|||||||
|
|
||||||
function ttypeconvnode.pass_1 : tnode;
|
function ttypeconvnode.pass_1 : tnode;
|
||||||
begin
|
begin
|
||||||
|
if warn_pointer_to_signed then
|
||||||
|
cgmessage(type_w_pointer_to_signed);
|
||||||
result:=nil;
|
result:=nil;
|
||||||
firstpass(left);
|
firstpass(left);
|
||||||
if codegenerror then
|
if codegenerror then
|
||||||
|
@ -444,6 +444,8 @@ implementation
|
|||||||
inherited create(assignn,l,r);
|
inherited create(assignn,l,r);
|
||||||
l.mark_write;
|
l.mark_write;
|
||||||
assigntype:=at_normal;
|
assigntype:=at_normal;
|
||||||
|
if r.nodetype = typeconvn then
|
||||||
|
ttypeconvnode(r).warn_pointer_to_signed:=false;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user