Lazarus

Free Pascal => Beginners => Topic started by: Weeb mindset on August 13, 2020, 05:11:20 pm

Title: Unknown SIGSEGV error
Post by: Weeb mindset on August 13, 2020, 05:11:20 pm
Lazarus
version :2.0.8
FPC version : 3.0.4
SVN revision : 62994
x86_64_win64-win32/win64
OS : win 10 pro 1909 64 bit

Well, i have no idea how this will have exception. HELLp >:D .
here is PART of the program
I did test my code, when the declarations is not equal to M5 and M6, the program works fine. Do i violate some hidden rules ?
THANKS ! :D
Code: Pascal  [Select][+][-]
  1. type
  2. rule_t         = (CE_M3,c42x,M5,M6);
  3. basic_info_t   =  record
  4.                         rule   : rule_t;
  5.                   end;
  6. programme_t = record
  7.                     basic_info : array [1..500]  of basic_info_t;
  8.              end;
  9. const
  10. p_s_t_x = 20;
  11. p_s_t_y = 501;
  12. progDB.prog_c = 53;
  13. var
  14.     progDB   : programme_t;
  15.     j,i      : integer;
  16.     p_s_t    : array [1..p_s_t_y,1..p_s_t_x] of string;
  17. begin
  18.         J := 2;
  19.         repeat
  20.                               i := 0;
  21.                               repeat
  22.                                     inc(i);
  23.                                     case p_s_t[j,i] of
  24.                                                     'Chi&Eng + Best 3' : progDB.basic_info[j-1].rule := CE_M3;
  25.                                                     '4C + 2X'          : progDB.basic_info[j-1].rule := c42x;
  26.                                                     'Best 5'           : progDB.basic_info[j-1].rule := M5;
  27.                                                     'Best 6'           : progDB.basic_info[j-1].rule := M6;
  28.                                     end;
  29.                               until i = p_s_t_x;
  30.                               inc(j);
  31.           until (p_s_t[j,i] = '') or (j = p_s_t_y);
  32.  end.                      
  33.  
Title: Re: Unknown SIGSEGV error
Post by: ASBzone on August 13, 2020, 05:21:47 pm
This will help:  https://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F (https://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F)
Title: Re: Unknown SIGSEGV error
Post by: Blaazen on August 13, 2020, 05:45:08 pm
I guess you have wrong index somewhere (you try to write out of array). Just switch on all debugging options - range checks etc. Do you use Lazarus?
Title: Re: Unknown SIGSEGV error
Post by: Handoko on August 13, 2020, 05:53:16 pm
I eye-inspected the code. Although not properly written but all the things in the array. I believe the bug is in elsewhere.
Title: Re: Unknown SIGSEGV error
Post by: Weeb mindset on August 13, 2020, 06:09:01 pm
I guess you have wrong index somewhere (you try to write out of array). Just switch on all debugging options - range checks etc. Do you use Lazarus?

i updated the post and put the info.
about range check, i just figured how to open it and digging with it.
Once i got a problem i will update.
Anyway, thanks for your help!
Title: Re: Unknown SIGSEGV error
Post by: wp on August 13, 2020, 08:00:39 pm
I don't understand what you are doing here, but there are some things which look strange to me:

The outer j loop begins with j=2, you access p_s_t[2, i] -- the first value of p_s_t (j=1) is never used.

The j loop is exited when j = p_s_t_y = 501. The last statement in the loop is inc(j), i.e. the last j value used is p_s_t_y-1 = 500. But the first index of the array p_s_t is dimensioned to run up to p_s_t_y = 501. So, the last value of p_s_t (j=501) is never used either.

Is this intended?
Title: Re: Unknown SIGSEGV error
Post by: jamie on August 13, 2020, 11:40:53 pm
Lazarus
version :2.0.8
FPC version : 3.0.4
SVN revision : 62994
x86_64_win64-win32/win64
OS : win 10 pro 1909 64 bit

Well, i have no idea how this will have exception. HELLp >:D .
here is PART of the program
I did test my code, when the declarations is not equal to M5 and M6, the program works fine. Do i violate some hidden rules ?
THANKS ! :D
Code: Pascal  [Select][+][-]
  1. type
  2. rule_t         = (CE_M3,c42x,M5,M6);
  3. basic_info_t   =  record
  4.                         rule   : rule_t;
  5.                   end;
  6. programme_t = record
  7.                     basic_info : array [1..500]  of basic_info_t;
  8.              end;
  9. const
  10. p_s_t_x = 20;
  11. p_s_t_y = 501;
  12. progDB.prog_c = 53;
  13. var
  14.     progDB   : programme_t;
  15.     j,i      : integer;
  16.     p_s_t    : array [1..p_s_t_y,1..p_s_t_x] of string;
  17. begin
  18.         J := 2;
  19.         repeat
  20.                               i := 0;
  21.                               repeat
  22.                                     inc(i);
  23.                                     case p_s_t[j,i] of
  24.                                                     'Chi&Eng + Best 3' : progDB.basic_info[j-1].rule := CE_M3;
  25.                                                     '4C + 2X'          : progDB.basic_info[j-1].rule := c42x;
  26.                                                     'Best 5'           : progDB.basic_info[j-1].rule := M5;
  27.                                                     'Best 6'           : progDB.basic_info[j-1].rule := M6;
  28.                                     end;
  29.                               until i = p_s_t_x;
  30.                               inc(j);
  31.           until (p_s_t[j,i] = '') { this will Fail if all elements are full } or (j = p_s_t_y);
  32.  end.                      
  33.  

 You should be checking for the size of J before using it..
Title: Re: Unknown SIGSEGV error
Post by: furious programming on August 14, 2020, 12:37:25 am
Change the loops to the two for loops and try again.

And correct the code formatting — indentations first of all, because they are monstrously large. Besides, stick to the adopted naming convention — PascalCase for variables and data types (plus the T prefix), and the UPPER_SNAKE_CASE for the constants.
TinyPortal © 2005-2018