Einzelnen Beitrag anzeigen

Rollo62

Registriert seit: 15. Mär 2007
3.926 Beiträge
 
Delphi 12 Athens
 
#5

AW: D12: NativeInt ( womöglich auch andere ), von "strong alias" zu "weak alias"

  Alt 26. Feb 2024, 06:59
Wenn ich alle Warnings einschalte, was ich liebend gerne so machen würde, kommen auch solche Dinge hoch, z.B. aus Spring.pas:

Delphi-Quellcode:
  Int24 = packed record //<== unsafe type Int24
  case Integer of
    0: (Low: Word; High: Byte);
    1: (Bytes: array[0..2] of Byte);
  end;
Zitat:
W1046 Unsafe type '%s%s%s' (Delphi)

You have used a data type or operation for which static code analysis cannot prove that it does not overwrite memory. For example, you might receive this warning if you declare something as absolute. Such code can be considered a security risk.
wie gehe ich denn damit um?
Meine Vermutung, dass es einfach an den fehlenden Bytes liegen sollte trifft nicht zu:

Delphi-Quellcode:
  
  Int24 = packed record //<== Wirft das Warning genauso, obwohl der Record überall 4-Byte sein sollte
  case Integer of
    0: (Low: Word; High, Pinky, Ponky: Byte);
    1: (Bytes: array[0..3] of Byte);
  end;
Ich denke mal, dass man das Warnung an der Stelle einfach abschalten sollte, oder wie würdet ihr das machen?

Delphi-Quellcode:
  {$WARN UNSAFE_TYPE OFF}
  Int24 = packed record
  case Integer of
    0: (Low: Word; High: Byte);
    1: (Bytes: array[0..2] of Byte);
  end;
  {$WARN UNSAFE_TYPE ON}
Das Warning hat aber auch einen Sinn und sollte eigentlich dort kommen, wo es benutzt wird.
  Mit Zitat antworten Zitat