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

    +20

    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
    #include <iostream>
    #include <boost/noncopyable.hpp>
    #include <assert.h>
    
    using namespace std;
    
    class noncopyable
      {
       protected:
          noncopyable() {}
         virtual ~noncopyable() {}
       private:  // emphasize the following members are private
          noncopyable( const noncopyable& );
          virtual const noncopyable& operator=( const noncopyable& )final = delete;
      };
    
    class T: public noncopyable
    {
    public:
       const T& operator=( const T& ){return *this;}
    };
    
    int main() {
       T a;
       a=T();
       std::cout<<"kokoko"<<std::endl;
       return 0;
    }

    http://liveworkspace.org/code/15b5716e7618cc75a6881dfdd46982d5

    В чем смысл =delete, если запретить копировать T все равно не удается? Или это ошибка не стандарта, а реализации gcc?

    HaskellGovno, 20 Августа 2012

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

    +23

    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
    %:include <iostream>
     
    int main(int argc, char *argv<::>) 
    <%
        if (argc > 1 and argv<:1:> not_eq '\0') <%
            std::cout << "Hello " << argv<:1:> << '\n';
        %>
        std::cout<<"ko"<<std::endl;
    %>
     
     
    
    ??=include <iostream>
     
    int main(int argc, char *argv??(??)) 
    ??<
        if (argc > 1 and argv??(1??) not_eq '\0') ??<
            std::cout << "Hello " << argv??(1??) << '\n';
        ??>
        std::cout<<"ko"<<std::endl;
    ??>

    http://liveworkspace.org/code/150ad59b81b309bbffed963829f4fc9e
    http://liveworkspace.org/code/c64104e4272af4d89f2f74c35c5c2ee3
    Просто оставлю это здесь.

    HaskellGovno, 20 Августа 2012

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

    +24

    1. 1
    masko xor_eq mask;

    А вообще жаль, что эту дельфитню включили в стандарт.

    HaskellGovno, 20 Августа 2012

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

    +25

    1. 1
    2. 2
    3. 3
    4. 4
    uint32 originalDamage = damage;
    
        if (absorb && originalDamage > damage)
            *absorb += (originalDamage - damage);

    Вытащил из 1 эмулятора игры World of WarCraft

    Heisenberg, 19 Августа 2012

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

    +20

    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
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    class NetGetPlmnListReply: public Message {
                    public:
                        virtual uint8_t command() const;
                        virtual uint8_t subcommand() const;
                        virtual RequestType requestType() const;
                        virtual bool deliver(IUnsolicitedReceiver *receiver);
    
                        static inline bool isTypeOf(Message *message) {
                            return message->command() == 8 && message->subcommand() == 4;
                        }
    
    
    
    std::string inspect() const;
    bool writeToStream(DataStream &stream);
    bool readFromStream(DataStream &stream);
    
    
    
            inline uint8_t count() const { return m_count; }
            inline void setCount(uint8_t count) { m_count = count; }
    
    
    
    
                class PlmnListItem {
                public:
    
    
    std::string inspect() const;
    bool writeToStream(DataStream &stream);
    bool readFromStream(DataStream &stream);
    
    
    
            enum Status {
    
                    Available = 2,
    
                    Current = 3,
    
                    Forbidden = 4,
    
            };
    
            inline Status status() const { return (Status) m_status; }
            inline void setStatus(Status status) { m_status = (uint8_t) status; }
    
    
    
    
    
            inline const std::vector<unsigned char> &plmn() const { return m_plmn; }
            inline void setPlmn(const std::vector<unsigned char> &plmn) { m_plmn = plmn; }
    
    
    private:
    
    
            uint8_t m_status;
    
    
    
            std::vector<unsigned char> m_plmn;
    
    
    
                };
    
    
            inline const std::vector<PlmnListItem> &plmnList() const { return m_plmnList; }
            inline void setPlmnList(const std::vector<PlmnListItem> &plmnList) { m_plmnList = plmnList; }
    
    
    
    private:
    
    
            uint8_t m_count;
    
    
    
            std::vector<PlmnListItem> m_plmnList;
    
    
    
                    };

    Один из тысячи сгенерированных классов.

    Grindars, 18 Августа 2012

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

    +20

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    #include <iostream>
    #include <string>
    
    int main(void)
    {
            char arr[] = "All's well that ends well";
            std::string s(arr, 3000);
            std::cout << s << std::endl;
    return(0);
    }

    Первое что пришло на ум, когда смотрел конструкторы string.
    Собирал: g++-4.5 -Wall -Wextra -pedantic-errors
    ideone.com и liveworkspace.org фильтруют.

    sayidandrtfm, 17 Августа 2012

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

    +7

    1. 1
    TPrimitive a((TLine())), b((TCircle()));

    Вынужденный говнокод.
    Должно быть:

    TPrimitive a(TLine()), b(TCircle());

    Но это будет объявлением 2х указателей на функции.

    HaskellGovno, 16 Августа 2012

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

    +28

    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
    byte* GetBuffer0(bool free = false)
    {
    	static std::auto_ptr<byte> transferBuffer;
    
    	if (free)
    	{
    		delete [] transferBuffer.release();
    	}
    	else
    	{
    		if (!transferBuffer.get())
    		{
    			transferBuffer.reset(new byte[BUFFER_SIZE]);
    		}
    	}
    	return transferBuffer.get();
    }
    
    byte* GetBuffer1(bool free = false)
    {
    	static std::auto_ptr<byte> transferBuffer;
    
    	if (free)
    	{
    		delete [] transferBuffer.release();
    	}
    	else
    	{
    		if (!transferBuffer.get())
    		{
    			transferBuffer.reset(new byte[BUFFER_SIZE]);
    		}
    	}
    	return transferBuffer.get();
    }

    legacy-дебри

    ni3_inv, 14 Августа 2012

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

    +18

    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
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    template <typename TYPE> class Ptr
    {
    public:
        Ptr():
            Pointer_(0),
            IsValid_(false)
        {
        }
        Ptr( const Ptr<TYPE> &other )
        {
            this->Pointer_ = other.Pointer_;
            this->IsValid_ = other.IsValid_;
        }
        Ptr( TYPE* &ptr ):
            IsValid_(true)
        {
            if ( std::find( Ptr<TYPE>::List_.begin(), Ptr<TYPE>::List_.end(), ptr ) == Ptr<TYPE>::List_.end() )
                Ptr<TYPE>::List_.push_back( ptr );
            this->Pointer_ = ptr;
        }
        ~Ptr()
        {
        }
    
        inline Ptr<TYPE>& operator = ( const Ptr<TYPE> &other )
        {
            this->Pointer_ = other.Pointer_;
            this->IsValid_ = other.IsValid_;
    
            return *this;
        }
    
        inline Ptr<TYPE>& operator = ( TYPE* &ptr )
        {
            if ( std::find( Ptr<TYPE>::List_.begin(), Ptr<TYPE>::List_.end(), ptr ) == Ptr<TYPE>::List_.end() )
                Ptr<TYPE>::List_.push_back( ptr );
    
            this->Pointer_ = ptr;
            this->IsValid_ = true;
    
            return *this;
        }
    
        inline bool operator == ( const Ptr<TYPE> &other )
        {
            return (this->Pointer_ == other.Pointer_) ? true:false;
        }
    
        inline bool operator != ( const Ptr<TYPE> &other )
        {
            return (this->Pointer_ != other.Pointer_) ? true:false;
        }
    
        inline TYPE* operator -> ()
        {
            return this->Pointer_;
        }
    
        inline bool isValid() const
        {
            if (!this->IsValid_)
                return false;
            return this->IsValid_ = ( (std::find( Ptr<TYPE>::List_.begin(), Ptr<TYPE>::List_.end(), this->Pointer_ ) == Ptr<TYPE>::List_.end() ) ? false:true );
        }
    
        inline void release()
        {
            if ( this->isValid() )
            {
                Ptr<TYPE>::List_.erase( std::find( Ptr<TYPE>::List_.begin(), Ptr<TYPE>::List_.end(), this->Pointer_ ) );
                delete this->Pointer_;
            }
    
            this->Pointer_ = 0;
            this->IsValid_ = false;
        }
    
        inline TYPE* get()
        {
            return this->Pointer_;
        }
    private:
        TYPE* Pointer_;
        mutable bool IsValid_;
    
        static std::list < TYPE* > List_;
    };
    
    template <typename TYPE> std::list < TYPE* > Ptr<TYPE>::List_;

    HaskellGovno, 12 Августа 2012

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

    +8

    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
    bool ASN1Parser::ConvertOID(const ASN1Block &blk, char *oid, unsigned int bufSize) {
        int a = 0;
        bool first = true;
        char tmp[32];
        oid[0] = 0;
        for (unsigned int i=0;i<blk.size;i++) {
            unsigned char c = data[blk.offset+i];
            if (c & 0x80) {
                a = (a << 7) | (c & 0x7F);
            } else {
                a = (a << 7) | (c & 0x7F);
                if (!first) {
                    sprintf(tmp,".%d",a);
                } else {
                    sprintf(tmp,"%d.%d",a/40,a%40);
                }
                a=0;
                first = false;
                if (strlen(tmp) >= bufSize) return false;
                strcat(oid, tmp);
            }
        }
        return true;
    }

    И еще один говнокодец на тему ASN.1 - распаковка OID'а.
    Кто найдет ошибку - получит пирожок с полочки ;)

    bormand, 12 Августа 2012

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