[SOLVED] Function FillDWord() produces Fatal Segmentation Fault lazarus / 64-FPC development ---------------------------------------------------------------------- domibay_hugo · 2020-11-09 12:03 In the intent to swiftly assigning a Value to an Array I tried to use the FillDWord() Function. When I initialize it with FillByte() it is correctly initialized. But when I want to assign the actual Value with FillDWord() it produces an unrecoverable Crash. To demonstrate this Behaviour I extended the Example104 from the Official Documentation at: FillDWord() Documentation Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Program demofilldword; uses  SysUtils; { Program to demonstrate the FillDWord function. } Const  ArraySize = 256; Var  S : Array [0..ArraySize - 1] of Int64;  v: Cardinal;  I : longint; begin  v := 7;  S[0] := 0;   try    WriteLn('Array S - FillByte(): do ...');     FillByte(S,SizeOf(S),0);     For I:=1 to ArraySize - 1 do      If S[i]<>0 then        WriteLn('Position ',i,' not zeroed out');     WriteLn('Array S : Init done.');     WriteLn('Array S - FillDWord(): do ...');     FillDWord(S,SizeOf(S),v);     WriteLn('Array S - FillDWord(): Execution done.');     For I:=1 to ArraySize do      WriteLn('Position ',i,' has the value: '#39, S[I], #39);     WriteLn('Array S - FillDWord(): Check done.');   except    on e: Exception do WriteLn('Exception [', e.HelpContext, ']: '#39, e.Message, #39);  end;   WriteLn('Demo App done.');end.                             This little Prototype produces this Output: $ ./demofilldword Array S - FillByte(): do ... Array S : Init done. Array S - FillDWord(): do ... Segmentation fault (core dumped) (I don't know where the Core Dump is written to but I can't find it) The actual Value in this Use Case in v is actually "7" so I could use FillByte(), too, but that wouldn't cover other Use Cases for Values > 255 . Please, can anyone give Insight about this Behaviour ? ---------------------------------------------------------------------- marcov · 2020-11-09 12:09 You get the size of bytes, and then  use store that amount of dwords?!?! divide by count to fill by sizeof(dword) ---------------------------------------------------------------------- domibay_hugo · 2020-11-09 12:45 Yes, I was actually misusing SizeOf(). I replaced it by Length() or by the  ArraySize Constant. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   WriteLn('Array S - SizeOf(): '#39, SizeOf(S), #39);  WriteLn('Array S - SizeOf(DWord): '#39, SizeOf(DWord), #39);  WriteLn('Array S - SizeOf()/SizeOf(DWord): '#39, (SizeOf(S) / SizeOf(DWord)), #39);  Which produces: Array S - SizeOf(): '2048' Array S - SizeOf(DWord): '4' Array S - SizeOf()/SizeOf(DWord): ' 5.1200000000000000E+002' I found the Value of 2048 very suspicious so I set ArraySize = 100 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Const  ArraySize = 100; Now I get: Array S - SizeOf(): '800' Array S - SizeOf(DWord): '4' Array S - SizeOf()/SizeOf(DWord): ' 2.0000000000000000E+002' Now the Application does not crash anymore. But still the Function FillDWord() does not fill the Array correctly Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     FillDWord(S, ArraySize, DWord(v));  Array S - FillDWord(): do ... Array S - FillDWord(): Execution done. Position 0 has the value: '30064771079' Position 1 has the value: '30064771079' Position 2 has the value: '30064771079' # [...] Position 47 has the value: '30064771079' Position 48 has the value: '30064771079' Position 49 has the value: '30064771079' Position 50 has the value: '0' Position 51 has the value: '0' Position 52 has the value: '0' # [...] Position 94 has the value: '0' Position 95 has the value: '0' Position 96 has the value: '0' Position 97 has the value: '0' Position 98 has the value: '0' Position 99 has the value: '0' Array S - FillDWord(): Check done. Demo App done. Heap dump by heaptrc unit of /usr15/proyectos/pascal/strings/demofilldword 6 memory blocks allocated : 719/728 6 memory blocks freed     : 719/728 0 unfreed memory blocks : 0 True heap size : 327680 True free heap : 327680 It is only filled half the way and not with the correct value. ---------------------------------------------------------------------- marcov · 2020-11-09 12:52 your array is int64 (8-byte) while your fill values are 32-bit. (4-byte) ---------------------------------------------------------------------- domibay_hugo · 2020-11-09 13:06 Yes, you are right! The actually Value in this Use Case is low and always positive, so I expected it to cover the positive range of Int64 When I changed the Array " S " to "Array of Cardinal" FillDWord() filled in the correct value. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Var  S : Array [0..ArraySize - 1] of Cardinal;  But in my Use Case I actually need Int64 values. So, I found that I must use the FillQWord() Function which works also with 8 Byte values. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     FillQWord(S, ArraySize, v);  Thank you very much for your constructive hints.