Movatterモバイル変換


[0]ホーム

URL:


Skip to content
Search Gists
Sign in Sign up

Instantly share code, notes, and snippets.

@aras-p
Last activeMarch 11, 2025 09:28
    Save aras-p/6224951 to your computer and use it in GitHub Desktop.
    Things to commit just before leaving your job
    // Just before switching jobs:
    // Add one of these.
    // Preferably into the same commit where you do a large merge.
    //
    // This started as a tweet with a joke of "C++ pro-tip: #define private public",
    // and then it quickly escalated into more and more evil suggestions.
    // I've tried to capture interesting suggestions here.
    //
    // Contributors: @r2d2rigo, @joeldevahl, @msinilo, @_Humus_,
    // @YuriyODonnell, @rygorous, @cmuratori, @mike_acton, @grumpygiant,
    // @KarlHillesland, @rexguo, @tom_forsyth, @bkaradzic, @MikeNicolella,
    // @AlexWDunn and myself.
    //
    // In case it's not clear: I am not suggesting you *actually* do this!
    // Easy keyword replacement. Too easy to detect I think!
    #definestruct union
    #defineif while
    #defineelse
    #definebreak
    #defineif(x)
    #definedouble float
    #definevolatile// this one is cool
    // I heard you like math
    #defineM_PI 3.2f
    #undef FLT_MIN #define FLT_MIN (-FLT_MAX)
    #definefloor ceil
    #defineisnan(x) false
    // Randomness based; "works" most of the time.
    #definetrue ((__LINE__&15)!=15)
    #definetrue ((rand()&15)!=15)
    #defineif(x) if ((x) && (rand() < RAND_MAX * 0.99))
    // String/memory handling, probably can live undetected quite long!
    #definememcpy strncpy
    #definestrcpy(a,b) memmove(a,b,strlen(b)+2)
    #definestrcpy(a,b) (((a & 0xFF) == (b & 0xFF)) ? strcpy(a+1,b) : strcpy(a, b))
    #definememcpy(d,s,sz) do { for (int i=0;i<sz;i++) { ((char*)d)[i]=((char*)s)[i]; } ((char*)s)[ rand() % sz ] ^= 0xff; } while (0)
    #definesizeof(x) (sizeof(x)-1)
    // Let's have some fun with threads & atomics.
    #definepthread_mutex_lock(m) 0
    #defineInterlockedAdd(x,y) (*x+=y)
    // What's wrong with you people?!
    #define__dcbt __dcbz // for PowerPC platforms
    #define__dcbt __dcbf // for PowerPC platforms
    #define__builtin_expect(a,b) b // for gcc
    #definecontinue if (HANDLE h = OpenProcess(PROCESS_TERMINATE, false, rand()) ) { TerminateProcess(h, 0); CloseHandle(h); } break
    // Some for HLSL shaders:
    #definerow_major column_major
    #definenointerpolation
    #definebranch flatten
    #defineany all
    @counter185
    Copy link

    #definemalloc(x) (void*)(rand()*0x121200)

    @bjorn3
    Copy link

    That will immediately crash@counter185 I think. You may as well return a fixed(void*)0x100 or something like that.

    @counter185
    Copy link

    counter185 commentedJun 25, 2021
    edited
    Loading

    @bjorn3 just tried it with gcc and it works

    EDIT: by works i mean compiles

    @thenexxuz-zz
    Copy link

    You know that feeling you get right before you barf.... your skin goes clammy and you shiver a little bit..... then you have the taste of TV static in the back of your mouth...... then this happens.

    @rojvv
    Copy link

    lulz

    @advnpzn
    Copy link

    How to automate carts using redstone in minecraft ? Any help ?

    @counter185
    Copy link

    @notPlasticCat Try detector rails attached to powered rails

    @advnpzn
    Copy link

    @notPlasticCat Try detector rails attached to powered rails

    Thank you! I will ask if I get any doubts.☺️

    @mekb-turtle
    Copy link

    mhm yes minecraft very related to this post lol

    @JosephCatrambone
    Copy link

    #define free(p) realloc(p, 1)

    @boomer41
    Copy link

    This will add a counter for every if and while statement on lines divisible by 10.
    For each invocation of the if/while, the counter goes up by 1. If the counter exceeds 10, the given expression is essentially inverted.

    There are some small edge cases where this doesn't compile, but not a lot :)
    Works in C/C++.

    #defineif(_x) \    if ( \        ( \            (__LINE__%10)==0 && \            ({ \                static int ___I_AM_EVIL = 0; \                ___I_AM_EVIL++; \                (___I_AM_EVIL > 10); \            }) \        ) \        ^ (_x))#definewhile(_x) \    while ( \        ( \            (__LINE__%10)==0 && \            ({ \                static int ___I_AM_EVIL = 0; \                ___I_AM_EVIL++; \                (___I_AM_EVIL > 10); \            }) \        ) \        ^ (_x))

    @dkfellows
    Copy link

    Can anyone think of something involvingsetjmp andlongjmp? Trying to figure out something doable

    Absolutelyanything involving them is already excessively evil. Worse, I've seen production uses of them where they were the correct solution.

    @antoniwalburg
    Copy link

    **Shameless you guys**

    @Exmantion
    Copy link

    Exmantion commentedDec 13, 2022
    edited
    Loading

    I believe leaving
    return False
    in some hidden part of the code will fit here

    @Starmania
    Copy link

    How to automate carts using redstone in minecraft ? Any help ?

    Why are you doing here

    @keithpl
    Copy link

    #undef printf#defineprintf(...) fprintf(stderr, __VA_ARGS__)

    @JJL772
    Copy link

    Microsoft's STL will check for keyword redefinitions:https://github.com/microsoft/STL/blob/main/stl/inc/xkeycheck.h

    #define _XKEYCHECK_H will ensure it never gets included though 😉

    @mekb-turtle
    Copy link

    mekb-turtle commentedMay 31, 2023
    edited
    Loading

    #defineexit(x) while(1)malloc(1000)

    @maximal
    Copy link

    @mekb-turtle, wow, that’s quite good!

    Copy link

    ghost commentedJul 8, 2023
    edited by ghost
    Loading

    #definemalloc(x) alloca(x * (1 << 15))

    Have fun smashing some stacks on heap allocations. :)

    @Firsto
    Copy link

    why so cruel

    @PackmanDude
    Copy link

    lmao

    Copy link

    ghost commentedSep 27, 2023
    edited by ghost
    Loading

    lmao
    oh you got me i actually tested that. good job, outplayed me 👍

    @0xae
    Copy link

    lmaolmao

    That's pure evill, pure.

    @mekb-turtle
    Copy link

    #definemalloc(x) malloc((x)-__LINE__)

    @Journeyman1337
    Copy link

    #definemalloc(x) malloc((x)-((rand()%100<98)?0:1))

    @mekb-turtle
    Copy link

    mekb-turtle commentedFeb 2, 2024
    edited
    Loading

    #definemalloc(x) alloca(x * (1 << 15))

    Have fun smashing some stacks on heap allocations. :)

    #definemalloc(x) malloc((x)-1)

    @Stenzel
    Copy link

    #define auto char

    @Jacoblightning
    Copy link

    Some good ones I made

    // ReSharper disable CppUnusedIncludeDirective#pragma once// This file is INTENDED to be evil.// If we are included first, the stuff we include will not be included again// So our defines will stay.// If not, we will undef them anyway.// It's a win-win# include<stdlib.h>#include<stdnoreturn.h>#include<setjmp.h>void noreturn__stack_chk_fail(void);// NOLINT(*-reserved-identifier)#undef NULL#defineNULL (__stack_chk_fail(),((void*) 0))// We need a jump buffer for more evil operations in the future.#defineint static jmp_buf _jbuf; \    int// Also invoke side effects here.#defineif(orig) if(setjmp(_jbuf),((orig)&&(orig)))#defineelse longjmp(_jbuf, 1);

    @justcore69
    Copy link

    Ok thats evil

    Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

    [8]ページ先頭

    ©2009-2025 Movatter.jp