使C ++程序崩溃的最简单方法是什么?

本文讨论了如何使C++程序可靠地崩溃,包括尝试使用非法内存访问、无限递归和利用只读内存等方法。在不同的上下文中,这些方法可能会导致程序出现如‘Segmentation fault (core dumped)’等错误信息。
摘要由CSDN通过智能技术生成

本文翻译自:What is the easiest way to make a C++ program crash?

I'm trying to make a Python program that interfaces with a different crashy process (that's out of my hands). 我正在尝试制作一个与不同的崩溃过程接口的Python程序(这不在我的手中)。 Unfortunately the program I'm interfacing with doesn't even crash reliably! 不幸的是,我正在连接的程序甚至没有可靠的崩溃! So I want to make a quick C++ program that crashes on purpose but I don't actually know the best and shortest way to do that, does anyone know what to put between my: 所以我想制作一个快速崩溃的C ++程序,但我实际上并不知道最好和最短的方法,有谁知道我的:

int main() {
    crashyCodeGoesHere();
}

to make my C++ program crash reliably 使我的C ++程序可靠地崩溃


#1楼

参考:https://stackoom.com/question/ZaUx/使C-程序崩溃的最简单方法是什么


#2楼

Or another way since we're on the band wagon. 或者另一种方式,因为我们在乐队旅行车上。

A lovely piece of infinite recursion. 一段可爱的无限递归。 Guaranteed to blow your stack. 保证吹你的筹码。

int main(int argv, char* argc)
{
   return main(argv, argc)
}

Prints out: 打印出来:

Segmentation fault (core dumped) 分段故障(核心转储)


#3楼

This crashes on my Linux system, because string literals are stored in read only memory: 这在我的Linux系统上崩溃,因为字符串文字存储在只读内存中:

0[""]--;

By the way, g++ refuses to compile this. 顺便说一下,g ++拒绝编译它。 Compilers are getting smarter and smarter :) 编译器变得更聪明,更聪明:)


#4楼

void main()
{

  int *aNumber = (int*) malloc(sizeof(int));
  int j = 10;
  for(int i = 2; i <= j; ++i)
  {
      aNumber = (int*) realloc(aNumber, sizeof(int) * i);
      j += 10;
  }

}

Hope this crashes. 希望这会崩溃。 Cheers. 干杯。


#5楼

int main(int argc, char *argv[])
{
    char *buf=NULL;buf[0]=0;
    return 0;
}

#6楼

int main()
{
    int *p=3;
    int s;
    while(1) {
        s=*p;
        p++;
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值