Recent

Author Topic: Problem with fillword procedure? (Using Lazarus 1.7, FPC3.0, Linux)  (Read 2247 times)

Curt Carpenter

  • Sr. Member
  • ****
  • Posts: 396
Hello.

I have two arrays,

Code: Pascal  [Select][+][-]
  1. var
  2.   DisplayBuffer1,
  3.   DisplayBuffer2: array[0..1000] of word;
  4.   ...
  5.  

When I try to initialize these arrays in the following code

Code: Pascal  [Select][+][-]
  1. Procedure FillDisplayBuffers;
  2. var desti, srci: integer;
  3. begin
  4.   fillword(DisplayBuffer1,SizeOf(DisplayBuffer1),$100);
  5.   fillword(DisplayBuffer2,SizeOf(DisplayBuffer2),$100);
  6.   desti := 0;
  7.    ...
  8.  

I receive a SIGSECV exception "Project DSOtest raised exception class 'External: SIGSEGV'.
In file './include/canvas.inc' at line 25in the GRAPHICS unit "

If I change the code in my initialization procedure to

Code: Pascal  [Select][+][-]
  1. Procedure FillDisplayBuffers;
  2. var desti, srci: integer;
  3. begin
  4.   fillword(DisplayBuffer1,SizeOf(DisplayBuffer1),$100);
  5.   DisplayBuffer2 := DisplayBuffer1;
  6.   desti := 0;
  7.   ...
  8.  

my code compiles and executes correctly. 

I'm curious:  does anyone have any ideas why using two "fillword" calls in succession would be causing the SIGSEGV?

WooBean

  • Full Member
  • ***
  • Posts: 229
Re: Problem with fillword procedure? (Using Lazarus 1.7, FPC3.0, Linux)
« Reply #1 on: March 20, 2018, 06:53:34 pm »
Hello.

I have two arrays,

Code: Pascal  [Select][+][-]
  1. var
  2.   DisplayBuffer1,
  3.   DisplayBuffer2: array[0..1000] of word;
  4.   ...
  5.  

When I try to initialize these arrays in the following code

Code: Pascal  [Select][+][-]
  1. Procedure FillDisplayBuffers;
  2. var desti, srci: integer;
  3. begin
  4.   fillword(DisplayBuffer1,SizeOf(DisplayBuffer1),$100);
  5.   fillword(DisplayBuffer2,SizeOf(DisplayBuffer2),$100);
  6.   desti := 0;
  7.    ...
  8.  

I receive a SIGSECV exception "Project DSOtest raised exception class 'External: SIGSEGV'.
In file './include/canvas.inc' at line 25in the GRAPHICS unit "

If I change the code in my initialization procedure to

Code: Pascal  [Select][+][-]
  1. Procedure FillDisplayBuffers;
  2. var desti, srci: integer;
  3. begin
  4.   fillword(DisplayBuffer1,SizeOf(DisplayBuffer1),$100);
  5.   DisplayBuffer2 := DisplayBuffer1;
  6.   desti := 0;
  7.   ...
  8.  

my code compiles and executes correctly. 

I'm curious:  does anyone have any ideas why using two "fillword" calls in succession would be causing the SIGSEGV?

Hi,

change your code as below:

Code: Pascal  [Select][+][-]
  1. Procedure FillDisplayBuffers;
  2. var desti, srci: integer;
  3. begin
  4.   fillword(DisplayBuffer1,SizeOf(DisplayBuffer1) div 2,$100);
  5.  // sizeOf returns result in bytes - not in words (=2 bytes)
  6.   fillword(DisplayBuffer2,SizeOf(DisplayBuffer2) div 2 ,$100);
  7.   desti := 0;
  8.    ...
  9.  

Explanation - fillword does not check the size of variable to be filled - so you can write something (not intentionally) in the neigbouring variable. This does not happen when you try to fillword the second variable - you are accessing protected segment of memory (code).

WooBean     
« Last Edit: March 20, 2018, 07:08:01 pm by WooBean »
Platforms: Win7/64, Linux Mint Ulyssa/64

jamie

  • Hero Member
  • *****
  • Posts: 6077
Re: Problem with fillword procedure? (Using Lazarus 1.7, FPC3.0, Linux)
« Reply #2 on: March 20, 2018, 10:11:21 pm »
Code: Pascal  [Select][+][-]
  1.  FillWord(DisplayBuffer1,High(DisplayBuffer1),$100);
  2.  FillWord(DisplayBuffer2,High(DisplayBuffer2),$100);
  3.  
  4.  

Actually that should be Length(DisplayBuffer1)......
« Last Edit: March 20, 2018, 10:12:58 pm by jamie »
The only true wisdom is knowing you know nothing

Curt Carpenter

  • Sr. Member
  • ****
  • Posts: 396
Re: Problem with fillword procedure? (Using Lazarus 1.7, FPC3.0, Linux)
« Reply #3 on: March 22, 2018, 05:45:20 pm »
Thank you!  I understand now.

 

TinyPortal © 2005-2018