1. C++ / Говнокод #20197

    +2

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    #include "Node.h"
    
    CMonom* CNode::GetMonomPtr() const
    {
    	return _MonomPtr;
    }
    
    CNode* CNode::GetNext() const
    {
    	return _NextPtr;
    }
    
    bool CNode::GetSign() const
    {
    	return _MonomPtr->GetSign();
    }
    
    int CNode::GetCoeff() const
    {
    	return _MonomPtr->GetCoeff();
    }
    
    unsigned CNode::GetDegree() const
    {
    	return _MonomPtr->GetDegree();
    }
    
    void CNode::SetNext(CNode* Node)
    { 
    	_NextPtr = Node;
    }
    
    void CNode::SetCoeff(int iCoeff) 
    {
    	_MonomPtr->SetCoeff(iCoeff);
    }
    
    void CNode::SetDegree(unsigned uDegree)
    {	
    	_MonomPtr->SetDegree(uDegree);
    }
    
    CNode::CNode(char* szStr) : _NextPtr(nullptr)
    {
    	try
    	{
    		_MonomPtr = new CMonom(szStr);
    	}
    	catch (const bad_alloc& exc) 
    	{ 
    		std::cout << exc.what(); 
    	}
    }
    
    CNode::CNode(int iCoeff, unsigned uDegree) : _NextPtr(nullptr)
    {
    	try
    	{
    		_MonomPtr = new CMonom(iCoeff, uDegree);
    	}
    	catch (const bad_alloc& exc) 
    	{ 
    		std::cout << exc.what(); 
    	}
    }
    
    CNode::CNode(const CMonom& Monom) : _NextPtr(nullptr)
    {
    	try
    	{
    		_MonomPtr = new CMonom(Monom);
    	}
    	catch (const bad_alloc& exc) 
    	{ 
    		std::cout << exc.what();
    	}
    }
    
    CNode::CNode(const CNode& Node) : _NextPtr(nullptr)
    {
    	try
    	{
    		_MonomPtr = new CMonom(*Node.GetMonomPtr());
    	}
    	catch (const bad_alloc& exc) 
    	{
    		std::cout << exc.what();
    	}
    }
    
    CNode& CNode::operator=(const CNode& Node)
    {
    	SetCoeff(Node.GetCoeff());
    	SetDegree(Node.GetDegree());
    	return *this;
    }
    
    CNode CNode::operator-() const
    {
    	return CNode(-*_MonomPtr);

    xxl, 14 Июня 2016

    Комментарии (33)
  2. C++ / Говнокод #20176

    +2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    connector* getConnector( int id )
    {
        autolock_read<lock_rw_t> alr( _lock );
        return _getConnector(id);
    }

    П-потокобезопасность

    govnokoderatata, 10 Июня 2016

    Комментарии (6)
  3. C++ / Говнокод #20155

    −2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    namespace spine {
    
    static SkeletonBatch* instance = nullptr;
    
    void SkeletonBatch::setBufferSize (int vertexCount) {
    	if (instance) delete instance;
    	instance = new SkeletonBatch(vertexCount);
    }
    
    SkeletonBatch* SkeletonBatch::getInstance () {
    	if (!instance) instance = new SkeletonBatch(8192);
    	return instance;
    }
    
    SkeletonBatch::SkeletonBatch (int capacity) :
    	_capacity(capacity), _position(0)
    {
    	_buffer = new V3F_C4B_T2F[capacity];
    	_firstCommand = new Command();
    	_command = _firstCommand;
    
    	Director::getInstance()->getScheduler()->scheduleUpdate(this, -1, false);
    }
    
    SkeletonBatch::~SkeletonBatch () {
    	Director::getInstance()->getScheduler()->unscheduleUpdate(this);
    
    	Command* command = _firstCommand;
    	while (command) {
    		Command* next = command->next;
    		delete command;
    		command = next;
    	}
    
    	delete [] _buffer;
    }

    https://github.com/EsotericSoftware/spine-runtimes/blob/master/spine-cocos2dx/3/src/spine/SkeletonBatch.cpp
    Это просто шедевЕр! Течет как ссаные тряпки...

    MarkusD, 08 Июня 2016

    Комментарии (25)
  4. C++ / Говнокод #20108

    +4

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    #define key \
        keySequence.keys[i]
    
    #define read_helper(val_)                 \
      file.read(                              \
          reinterpret_cast<char*>(&key.val_), \
          sizeof(decltype(key.val_))          \
      )
    
    for (DWORD i = 0; i < keyPointer.Count; i++)
      read_helper(RotationQuaternion);
    
    for (DWORD i = 0; i < keyPointer.Count; i++)
      read_helper(TimeValue);
    
    for (DWORD i = 0; i < keyPointer.Count; i++)
      read_helper(PositionValue),
      key.SwapBytes();
    
    #undef read_helper
    #undef key

    LispGovno, 31 Мая 2016

    Комментарии (76)
  5. C++ / Говнокод #20099

    +9

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    #define public public: void operator delete(void *pituh) {}; public
         
    class poteklo
    {
    public:
        poteklo() :
            TheAnswer(42)
        {
             ;
        }
         
    private:
         int TheAnswer;
    };
         
    int main(int argc, char *argv[])
    {
        poteklo *uteklo = new poteklo;
        delete uteklo;    // Утекло!
    
        return 0;
    }

    Макро в духе "#define TRUE FALSE", только хардкорнее.
    https://ideone.com/ZdGnuL

    gost, 30 Мая 2016

    Комментарии (103)
  6. C++ / Говнокод #20095

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    //...
          /* See if this is something like X * C - X or vice versa or
    	 if the multiplication is written as a shift.  If so, we can
    	 distribute and make a new multiply, shift, or maybe just
    	 have X (if C is 2 in the example above).  But don't make
    	 something more expensive than we had before.  */
    
          if (SCALAR_INT_MODE_P (mode))
    	{
    	  rtx lhs = op0, rhs = op1;
    
    	  wide_int coeff0 = wi::one (GET_MODE_PRECISION (mode));
    	  wide_int coeff1 = wi::one (GET_MODE_PRECISION (mode));
    
    	  if (GET_CODE (lhs) == NEG)
    	    {
    	      coeff0 = wi::minus_one (GET_MODE_PRECISION (mode));
    	      lhs = XEXP (lhs, 0);
    	    }
    	  else if (GET_CODE (lhs) == MULT
    		   && CONST_SCALAR_INT_P (XEXP (lhs, 1)))
    	    {
    	      coeff0 = std::make_pair (XEXP (lhs, 1), mode);
    	      lhs = XEXP (lhs, 0);
    	    }
    	  else if (GET_CODE (lhs) == ASHIFT
    		   && CONST_INT_P (XEXP (lhs, 1))
                       && INTVAL (XEXP (lhs, 1)) >= 0
    		   && INTVAL (XEXP (lhs, 1)) < GET_MODE_PRECISION (mode))
    	    {
    	      coeff0 = wi::set_bit_in_zero (INTVAL (XEXP (lhs, 1)),
    					    GET_MODE_PRECISION (mode));
    	      lhs = XEXP (lhs, 0);
    	    }
    
    	  if (GET_CODE (rhs) == NEG)
    	    {
    	      coeff1 = wi::minus_one (GET_MODE_PRECISION (mode));
    	      rhs = XEXP (rhs, 0);
    	    }
    	  else if (GET_CODE (rhs) == MULT
    		   && CONST_INT_P (XEXP (rhs, 1)))
    	    {
    	      coeff1 = std::make_pair (XEXP (rhs, 1), mode);
    	      rhs = XEXP (rhs, 0);
    	    }
    	  else if (GET_CODE (rhs) == ASHIFT
    		   && CONST_INT_P (XEXP (rhs, 1))
    		   && INTVAL (XEXP (rhs, 1)) >= 0
    		   && INTVAL (XEXP (rhs, 1)) < GET_MODE_PRECISION (mode))
    	    {
    	      coeff1 = wi::set_bit_in_zero (INTVAL (XEXP (rhs, 1)),
    					    GET_MODE_PRECISION (mode));
    	      rhs = XEXP (rhs, 0);
    	    }
    
    	  if (rtx_equal_p (lhs, rhs))
    	    {
    	      rtx orig = gen_rtx_PLUS (mode, op0, op1);
    	      rtx coeff;
    	      bool speed = optimize_function_for_speed_p (cfun);
    
    	      coeff = immed_wide_int_const (coeff0 + coeff1, mode);
    
    	      tem = simplify_gen_binary (MULT, mode, lhs, coeff);
    	      return (set_src_cost (tem, mode, speed)
    		      <= set_src_cost (orig, mode, speed) ? tem : 0);
    	    }
    	}

    https://gcc.gnu.org/viewcvs/gcc/trunk/gcc/simplify-rtx.c?view=markup&pathrev=232689#l2062 здоровенная такая функция из недр GCC, в которой делаются оптимизации, это сродни символьным вычислениям вообще говоря
    https://godbolt.org/g/vcEqe7 но похоже эта хрень работает плохо, не смогло оно выявить тождественность умножения сдвигами и обычного умножения, сведя операции к return 1 в случае функции test1. Но я естественно находил и примеры кода, которые GCC смог успешно "редуцировать" своим оптимизатором, а clang тупил. Говно тут в том, что вместо того, чтобы впилить нормальную систему символьных вычислений, там нагородили какого-то ебучего говна... Хотя может быть я чего-то не понимаю в компиляторах. Надо будет дракона почитать

    j123123, 30 Мая 2016

    Комментарии (66)
  7. C++ / Говнокод #20091

    +2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    CharT getline(std::istream& i, string& s, const CharT* delim) {
    ...
        if (!i.operator void*()) 
            break;
    ...
    }

    Библиотека Apache UIMA-CPP.
    Что могло заставить написать так, вместо обычного if (i)? Какой-то древний компилятор, который не использует каст к указателю в условии?
    Ну и, разумеется, в C++11 ios::operator void*() заменили на explicit ios::operator bool(), так что работать перестало.

    Bobik, 29 Мая 2016

    Комментарии (57)
  8. C++ / Говнокод #20087

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    void	Game::Loadlevel(int which){
     stealthloading=0;
    
     if(which==0)Loadlevel((char *)":Data:Maps:map1");
     else if(which==1)Loadlevel((char *)":Data:Maps:map2");
     else if(which==2)Loadlevel((char *)":Data:Maps:map3");
     // [...]
    }
    
    // [Почему (char *)? Да вот же!]
    
    void	Game::Loadlevel(char *name){
     int i,j,k,l,m;
     static int oldlevel;
     int templength;
     float lamefloat;
     int lameint;
      // [...]
    }

    Ебём const машиной Тьюринга. Всё тот же https://hg.icculus.org/icculus/lugaru/file/97b303e79826/Source/GameTick.cpp , прямо-таки сокровищница с говном.

    gost, 27 Мая 2016

    Комментарии (93)
  9. C++ / Говнокод #20077

    +4

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    if(((player[i].targetanimation!=getupfrombackanim&&player[i].targetanimation!=getupfromfrontanim)||player[i].skeleton.free)&&((player[k].targetanimation!=getupfrombackanim&&player[k].targetanimation!=getupfromfrontanim)||player[k].skeleton.free))
        if(((((findLengthfast(&rotatetarget)>150&&(i!=0&&k!=0))||(findLengthfast(&rotatetarget)>50&&player[0].rabbitkickragdoll/*currentanimation==rabbitkickanim*/&&(i==0||k==0)))&&normaldotproduct(rotatetarget,player[k].coords-player[i].coords)>0)&&((i==0||k==0)||((player[i].skeleton.oldfree==1&&k!=0&&animation[player[k].currentanimation].attack==neutral)||(player[k].skeleton.oldfree==1&&i!=0&&animation[player[i].currentanimation].attack==neutral)||(player[i].isFlip()&&!player[i].skeleton.oldfree&&(i==0||k==0))||(player[k].isFlip()&&!player[k].skeleton.oldfree&&(i==0||k==0))||(i==0||k==0))))||((player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip())&&(player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim||player[k].isFlip())&&(i==0||k==0)&&(!player[i].skeleton.oldfree&&!player[k].skeleton.oldfree))){
            //If hit by body
            if((i!=0||player[i].skeleton.free)&&(k!=0||player[k].skeleton.free)||(animation[player[i].targetanimation].height==highheight&&animation[player[k].targetanimation].height==highheight)){
                static float gLoc[3];
                // ...

    Не могу не запостить. Кажется, это самый длинный говнокод, что я видел.
    По мотиву #20073, из http://hg.icculus.org/icculus/lugaru/file/97b303e79826/Source/GameTick.cpp .

    PS, на всякий случай поставлю C++ - где-то в недрах второй строчки он наверняка есть.

    gost, 25 Мая 2016

    Комментарии (2)
  10. C++ / Говнокод #20076

    +6

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    for(int i = 0; i < codes.size(); ++i) {
        switch(i) {
            case 0: ret.code0 = codes[i]; break;
            case 1: ret.code1 = codes[i]; break;
            case 2: ret.code2 = codes[i]; break;
            case 3: ret.code3 = codes[i]; break;
            case 4: ret.code4 = codes[i]; break;
            case 5: ret.code5 = codes[i]; break;
        }
    }

    А всё потому, что ret.code[0-5] - битовые поля. Эх.

    Xom94ok, 25 Мая 2016

    Комментарии (58)