knot126

furries, computers, magic

  • they/them (any are fine)


i tried to make a single header c library to crash the app as a joke... it turns out this is very hard with an optimising compiler.

/**
 * libcrash - a simple library to crash your program
 * 
 * libcrash is an stb-style library, meaning that you can #define
 * LIBCRASH_IMPLEMENTATION in one file, then include it normally in all other
 * files, and it still works despite being a single library.
 * 
 * To use the library, just call crash().
 */

#include <stdlib.h>

void crash(void);

#ifdef LIBCRASH_IMPLEMENTATION

void crash(void) {
	/**
	 * Crash the program
	 */
	
	size_t *x = malloc(sizeof *x);
	*x = (rand() << 32) | rand();
	free((void *) *x);
	*((size_t **) 0x80000000) = x;
}

#ifdef LIBCRASH_TEST
int main(const int argc, const char *argv[]) {
	crash();
	
	return 0;
}
#endif

#endif

You must log in to comment.