如何避免在FPC的编译器SIGSEGV错误? [英] How to avoid SIGSEGV Errors on FPC compiler?

查看:350
本文介绍了如何避免在FPC的编译器SIGSEGV错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有几个问题访问冲突在我建立我的编程过程中的程序。这是正在建设中的帕斯卡(由课程使用的语言),使用IDE拉撒路(类似德尔福,但打开)。

I'm currently having several problems with access violations in the program I'm building for my programming course. It is being build in pascal (the language used by the course) and using the Lazarus IDE (similar to Delphi but open).

据我了解,访问冲突或错误SIGSEGV,当您尝试使用或解决的一个无效的内存位置出现。我一直在低谷很多这样的,特别是当我不声明动态数组的长度。

As far as I know, Access Violations, or SIGSEGV errors, occurs when you try to use or address an invalid memory location. I've been trough a lot of these, specially when I wasn't declaring the length of dynamic arrays.

现在看来,我有这个麻烦的字符串。 (或者我可能会与多维数组来derping)。

Now It seems I'm having this trouble with strings. (Or I might be derping with multi-dimensional arrays).

我只粘贴其中SIGSEGV指向的程序,但是上下文是:

I'll paste only the procedure where the SIGSEGV is pointing, but the context is:

我有一个整数数组和包含它的功率设置一个多维数组的(subconjuntos),其中POPING(如下所述)错误的功能是用来打印此功率设置成文本框(由索引本地

I have an array of integers and a multi-dimensional array containing it's power set (subconjuntos), the function where the error is poping (described below) is used to print this power set to a TextBox(indexed by local):

procedure writeSub(local: TEdit);
var
  i, j: integer;
begin
 for i:= 0 to High(subconjuntos)+1 do
   if Length(subconjuntos[i])>1 then
   begin
     local.Text:=local.Text+'[';
     for j:=0 to High(subconjuntos[i])+1 do local.Text:=local.Text+'('+IntToStr(subconjuntos[i][j])+') ';
     local.Text:=local.Text+'] ';
   end
   else local.Text:=local.Text+'['+IntToStr(subconjuntos[i][0])+'] '; {this is where I'm having the SIGSEG, the program wont compile if I don't reference it without the double brackets}
end;  

任何想法,为什么它是扔SIGSEGV的?

Any ideas why it is throwing SIGSEGV's?

推荐答案

动态数组该范围内的有效索引低(ARR)高(ARR)的包容性。和低(ARR)始终是一个动态数组为零。你试图用指数高访问一个元素(ARR)+1 。这就是关闭阵列的末端,肯定是一个错误。

Dynamic arrays have valid indices in the range low(arr) to high(arr) inclusive. And low(arr) is always zero for a dynamic array. You attempt to access an element with index high(arr)+1. That is off the end of the array and is certainly a mistake.

如果你写

for i:= 0 to High(subconjuntos)+1 do

应该是

for i:= 0 to High(subconjuntos) do

for i:= Low(subconjuntos) to High(subconjuntos) do

和同样为其他循环。

在最重要的是, subconjuntos [I] [0] 是一个出界访问,如果长度(subconjuntos [I])是零。

On top of that, subconjuntos[i][0] is an out of bounds access if Length(subconjuntos[i]) is zero.

如果您在编译器选项启用范围检查那么编译器将发出code,检查每个数组访问的有效性。这样做会更快地引导你的错误。

If you enable range checking in the compiler options then the compiler will emit code to check the validity of each array access. Doing this will lead you more quickly to such errors.

这篇关于如何避免在FPC的编译器SIGSEGV错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆