Thread overview
DMD SIGSEGV
Nov 24, 2005
Tiago Gasiba
Nov 24, 2005
Deewiant
Nov 26, 2005
Thomas Kuehne
Nov 28, 2005
Tiago Gasiba
Fix: Re: DMD SIGSEGV
Dec 04, 2005
Thomas Kuehne
November 24, 2005
I'm not sure if this error has already been posted or not. In any case, here it goes:

Compile with DMD 0.139 (Linux) and run the program. It breaks down with SIGSEGV.

<snip>
int main(){
  double[] X;

  X.length = 2147483120;

  return 0;
}
<snip>

Best,
Tiago

-- 
Tiago Gasiba (M.Sc.) - http://www.gasiba.de
Everything should be made as simple as possible, but not simpler.
November 24, 2005
Tiago Gasiba wrote:
> I'm not sure if this error has already been posted or not. In any case, here it goes:
> 
> Compile with DMD 0.139 (Linux) and run the program. It breaks down with SIGSEGV.
> 
> <snip>
> int main(){
>   double[] X;
> 
>   X.length = 2147483120;
> 
>   return 0;
> }
> <snip>
> 
> Best,
> Tiago
> 

Confirmed on DMD 0.139, Windows (XP SP2). Gives an "Error: Win32 Exception".

The biggest length that still ran succesfully (or, at least, tried to... I didn't let it finish) was 205496319.
November 26, 2005
Tiago Gasiba schrieb am 2005-11-24:
> I'm not sure if this error has already been posted or not. In any case, here it goes:
>
> Compile with DMD 0.139 (Linux) and run the program. It breaks down with SIGSEGV.
>
><snip>
> int main(){
>   double[] X;
>
>   X.length = 2147483120;
>
>   return 0;
> }
><snip>
>
> Best,
> Tiago

This isn't a bug but a feature of the used system.

Required memory:
17179864964 <- 2147483120 * double.sizeof + size_t.sizeof
2 ^ 34 <- 17179864964

2 ^ 34 bytes on a 32bit system are allways a bit difficult.

Thomas


November 28, 2005
Thomas Kuehne schrieb:

> This isn't a bug but a feature of the used system.
> 
> Required memory:
> 17179864964 <- 2147483120 * double.sizeof + size_t.sizeof
> 2 ^ 34 <- 17179864964
> 
> 2 ^ 34 bytes on a 32bit system are allways a bit difficult.
> 
> Thomas

That is certainly true, but shouldn't there be a much nicer error message?
It is somehow obvious that the program has to break down, but it should report something like "Not enough memory to execute line xxx" or "Memory exhausted at line xxx".

Best,
Tiago

-- 
Tiago Gasiba (M.Sc.) - http://www.gasiba.de
Everything should be made as simple as possible, but not simpler.
December 04, 2005
Tiago Gasiba schrieb am 2005-11-28:
> Thomas Kuehne schrieb:
>
>> This isn't a bug but a feature of the used system.
>> 
>> Required memory:
>> 17179864964 <- 2147483120 * double.sizeof + size_t.sizeof
>> 2 ^ 34 <- 17179864964

should have been:
17179864968 <- 2147483120 * double.sizeof + 2 * size_t.sizeof

>> 2 ^ 34 bytes on a 32bit system are allways a bit difficult.
>> 
>> Thomas
>
> That is certainly true, but shouldn't there be a much nicer error message? It is somehow obvious that the program has to break down, but it should report something like "Not enough memory to execute line xxx" or "Memory exhausted at line xxx".

To fix this open "dmd/src/phobos/gc/gc.d", add the following check to _d_new as well as _d_newarrayi and recompile Phobos.

# { // overflow check
#      ulong totalLength = length;
#      totalLength *= size;
#      if((cast(size_t)totalLength != totalLength)
#          || (totalLength / length != size))
#      {
#          throw new Exception("excessive payload length");
#      }
# }

Thomas