Browse Source

* avoid wrong warning about FillChar not initializing the output parameter in case count <= 0

florian 1 year ago
parent
commit
9bb6a32c62
1 changed files with 5 additions and 2 deletions
  1. 5 2
      rtl/inc/cgeneric.inc

+ 5 - 2
rtl/inc/cgeneric.inc

@@ -39,8 +39,11 @@ procedure memset(var x; value: byte; count: size_t); cdecl; external clib;
 
 
 Procedure FillChar(var x;count: sizeint;value:byte);{$ifdef SYSTEMINLINE}inline;{$endif}
 Procedure FillChar(var x;count: sizeint;value:byte);{$ifdef SYSTEMINLINE}inline;{$endif}
 begin
 begin
-  if count <= 0 then
-    exit;
+  { don't exit if count is <= 0, this makes the compiler think x is uninitialized,
+    as FillChar is probably rarely called with count <= 0, the performance hit is 
+    probably neglible }
+  if count < 0 then
+    count := 0;
   memset(x,value,size_t(count));
   memset(x,value,size_t(count));
 end;
 end;
 {$endif FPC_SYSTEM_HAS_FILLCHAR}
 {$endif FPC_SYSTEM_HAS_FILLCHAR}