搞爆编译器的代码

pascal:

{$inline on} procedure a; inline; begin end; procedure b; inline; begin a;a;a;a;a;a;a;a;a;a end; procedure c; inline; begin b;b;b;b;b;b;b;b;b;b end; procedure d; inline; begin c;c;c;c;c;c;c;c;c;c end; procedure e; inline; begin d;d;d;d;d;d;d;d;d;d end; procedure f; inline; begin e;e;e;e;e;e;e;e;e;e end; procedure g; inline; begin f;f;f;f;f;f;f;f;f;f end; procedure h; inline; begin g;g;g;g;g;g;g;g;g;g end; procedure i; inline; begin h;h;h;h;h;h;h;h;h;h end; procedure j; inline; begin i;i;i;i;i;i;i;i;i;i end; procedure k; inline; begin j;j;j;j;j;j;j;j;j;j end; begin k;k;k;k;k;k;k;k;k;k end.

C/C++:

#define A(x) x##x #define B(x) A(x)A(x) #define C(x) B(B(x)) #define D(x) C(C(x)) #define E(x) D(D(x)) #define F(x) E(E(x)) #define G(x) F(F(x)) #define H(x) G(G(x)) int main() { int H(x) = 0; }

 

fpc由于一直没把内存耗完,所以一直没停下来,倒是把系统弄得很慢。

g++把2G内存耗完后就爆了,耗时23s

 

运行着g++时:

$ free -m
             total       used       free     shared    buffers     cached
Mem:          2023       1975         48          0          1         14
-/+ buffers/cache:       1958         64
Swap:         4102        164       3937

 


$ time g++ test1.cpp

cc1plus: out of memory allocating 536870912 bytes after a total of 2060288 bytes

real    0m23.594s
user    0m12.542s
sys     0m3.652s


$ time fpc test.pas
Free Pascal Compiler version 2.2.4 [2009/03/28] for i386
Copyright (c) 1993-2008 by Florian Klaempfl
Target OS: Linux for i386
Compiling test.pas
Fatal: Compilation aborted


real    3m36.956s
user    0m0.000s
sys     0m0.034s

 

这些代码看似无聊,却对OJ系统的安全构成巨大威胁。。 看来要限制编译时间才行。

 

 

你可能感兴趣的:(c,linux,pascal,compiler,编译器,compilation)