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

    +51

    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
    std::list<COptions *> COptions::m_InstanceList;
    ..........
    COptions::COptions()
    {
    	for (int i = 0; i < OPTIONS_NUM; ++i)
    		m_OptionsCache[i].bCached = FALSE;
    	m_pOptionsHelperWindow = new COptionsHelperWindow(this);
    	simple_lock lock(m_mutex);
    #ifdef _DEBUG
    	for (std::list<COptions *>::iterator iter=m_InstanceList.begin(); iter != m_InstanceList.end(); ++iter)
    		ASSERT(*iter != this);
    #endif _DEBUG
    	m_InstanceList.push_back(this);
    	m_SpeedLimits[0] = m_sSpeedLimits[0];
    	m_SpeedLimits[1] = m_sSpeedLimits[1];
    }
    
    COptions::~COptions()
    {
    	{
    		simple_lock lock(m_mutex);
    		std::list<COptions *>::iterator iter;
    		for (iter=m_InstanceList.begin(); iter != m_InstanceList.end(); ++iter) {
    			if (*iter == this)
    				break;
    		}
    
    		ASSERT(iter != m_InstanceList.end());
    		if (iter != m_InstanceList.end())
    			m_InstanceList.erase(iter);
    	}
    
    	if (m_pOptionsHelperWindow)
    		delete m_pOptionsHelperWindow;
    	m_pOptionsHelperWindow=0;
    }
    .......

    В отладке включается тяжелый героиновый бред разработчиков FileZilla

    fsmoke, 24 Ноября 2014

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

    +50

    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
    90. 90
    91. 91
    92. 92
    #include <deque>
    #include <stdint.h>
    #include <iterator>
    #include <algorithm>
    #include <iostream>
    #include <iomanip>
    using namespace std;
    typedef uint32_t bt;
    typedef uint64_t dbt;
    typedef deque<bt> bn;
    #define cat2(b,e) b##e
    #define cat(b,e) cat2(b,e)
    #define fsi(i,s,e) for(size_t i(s), cat(i,_end)(e); i<cat(i,_end); ++(i))
    #define fe(i,c) for(auto i((c).begin()), cat(i,_end)((c).end()); i!=cat(i,_end); ++(i))
    void ml10(bn& n){
      n.push_front(0);
    }
    uint32_t ni(const bn& n, size_t i){
      if(n.size()<=i)
        return 0;
      else
        return n[i];
    }
    size_t ms(const bn& n1, const bn& n2){
      return (max) (n1.size(), n2.size());
    }
    bt gr(dbt tr){
      return tr & (numeric_limits<bt>::max)();
    }
    bt gc(dbt tr){
      return (tr & (~((dbt)(numeric_limits<bt>::max)()))) >> (numeric_limits<bt>::digits);
    }
    void pb(bt b1, bt b2, bt lc, bt& r, bt& c){
      dbt tr = ((uint64_t)b1 + b2 + lc);
      r = gr(tr);
      c = gc(tr);
    }
    void mb(bt b1, bt b2, bt lc, bt& r, bt& c){
      dbt tr = ((uint64_t)b1 * b2 + lc);
      r = gr(tr);
      c = gc(tr);
    }
    bn /*constexpr*/ bi(bn n){
      reverse(n.begin(), n.end());
      return n;
    }
    bn pl(const bn& n1, const bn& n2){
      bn r;
      bt c=0,br=0;
      size_t ms_ = ms(n1, n2);
      //r.reserve(ms_+1);
      fsi(i,0,ms_){
        pb(ni(n1,i),ni(n2,i),c,br,c);
        r.push_back(br);
      }
      if (c)
        r.push_back(c);
      return r;
    }
    bn ml(bn n1, const bn& n2){
      bn lr, r;
      bt c=0;
      //r.reserve(n1.size() + n2.size() + 1);
      fsi(i2,0,n2.size()){
        fsi(i1, 0, n1.size()){
          lr.emplace_back();
          mb(n1[i1], n2[i2], c, lr[i1], c);
        }
        if (c){
          lr.push_back(c);
          c = 0;
        }
        r = pl(r, lr);
        lr.clear();
        ml10(n1);
      }
      return r;
    }
    #define STR1(x) #x
    #define STR(x) STR1(x)
    #define EXPECT_TRUE(expr)\
    do{\
      if(!(expr))\
        cout<<"*****Failed test: \"" STR(expr) "\"" << endl;\
        else\
        cout << "Test OK: \"" STR(expr) "\"" << endl;\
    }while(false)
    #define TEST(expr)\
    do{\
        cout << "Test begined: \"" STR(expr) "\"" << endl;\
        (void)(expr);\
    } while (false)

    И вот мой просмотр аниме закончен.
    http://ideone.com/eRJ7FA
    main смотри в коментах

    LispGovno, 24 Ноября 2014

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

    +52

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    int QTabBarPrivate::indexAtPos(const QPoint &p) const
    {
        Q_Q(const QTabBar);
        if (q->tabRect(currentIndex).contains(p))
            return currentIndex;
        for (int i = 0; i < tabList.count(); ++i)
            if (tabList.at(i).enabled && q->tabRect(i).contains(p))
                return i;
        return -1;
    }

    currentIndex - видимо откат заплатил

    PS
    Cкоро всю Qt на говнокод заливать придется.
    Плохое настроение или хотите поржать - открывайте исходники Qt в случайном месте - поднимаете себе настроение идиотскими решениями - профит

    fsmoke, 23 Ноября 2014

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

    +57

    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
    typedef deque<uint8_t> bn;
    #define cat2(b,e) b##e
    #define cat(b,e) cat2(b,e)
    #define fsi(i,s,e) for(size_t i(s), cat(i,cat(_fsi_end_,__LINE__))(e); i<cat(i,cat(_fsi_end_,__LINE__)); ++(i))
    void ml10(bn& n){
      n.push_front(0);
    }
    uint8_t ni(const bn& n, size_t i){
      if(n.size()<=i)
        return 0;
      else
        return n[i];
    }
    size_t ms(const bn& n1, const bn& n2){
      return (max) (n1.size(), n2.size());
    }
    void pb(uint8_t b1, uint8_t b2, uint8_t lc, uint8_t& r, uint8_t& c){
      uint8_t tr = (b1+b2+lc);
      r = tr & 1;
      c = !!(tr & 2);
    }
    bn bi(bn n){
      reverse(n.begin(), n.end());
      return n;
    }
    bn pl(const bn& n1, const bn& n2){
      bn r;
      uint8_t c=0,br=0;
      fsi(i,0,ms(n1, n2)){
        pb(ni(n1,i),ni(n2,i),c,br,c);
        r.push_back(br);
      }
      if (c)
        r.push_back(c);
      return r;
    }
    bn ml(bn n1, const bn& n2){
      bn r;
      fsi(i,0,n2.size()){
        if(n2[i])
          r=pl(r,n1);
        ml10(n1);
      }
      return r;
    }

    У меня к вам вопрос парни.
    В нашем отделе взяли олимпиадника. За ним не следили. Он написал много кода и ушел в гугл.
    Как бы за ним теперь код поправить? Хотябы конструкции языка типа for вернуть вместо например fsi?
    Код не из проекта. но его. В проекте похожий и даже хуже.
    Нужно типа утилиты препроцессор крестов для части макросов (все разворачивать макросы или инклудить хедеры очевидно нельзя).

    laMer007, 23 Ноября 2014

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

    +55

    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
    On Wed, 29 Oct 2014 20:29:33 +0000
    via Digitalmars-d <[email protected]> wrote:
    
    > On Wednesday, 29 October 2014 at 20:13:34 UTC, ketmar via 
    > Digitalmars-d wrote:
    > > On Wed, 29 Oct 2014 13:07:38 -0700
    > > Walter Bright via Digitalmars-d <[email protected]> 
    > > wrote:
    > >
    > >> There are still two string types, something you can't quite 
    > >> escape dealing with.
    > > and D has three string types. it's even better than C++!
    > 
    > Only three? C++ has seven:
    > 
    > 1. const char*  /* zero terminated single byte*/
    > 2. const char*  /* zero terminated multi byte */
    > 3. const wchar_t*  /* zero terminated wide */
    > 4. std::string	
    > 5. std::wstring
    > 6. std::u16string
    > 7. std::u32string
    ah, D has those 'char*' family too, but i don't count them as string
    types. ok, C++ wins. again. ;-)

    Хоть и не код, но смешно.
    Источник: http://forum.dlang.org/thread/[email protected]?page=3

    rst256, 18 Ноября 2014

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

    +57

    1. 1
    2. 2
    float factor = ((float)sizeof(char) / sizeof(wchar_t));
    fileSize = (long)((float)fileSize * factor);

    вот так выглядит деление на sizeof(wchar_t) :)

    fsmoke, 18 Ноября 2014

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

    +53

    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
    int CALLBACK ZDll::Compare(ZDll* p, ZDll* q, LPARAM lParamSort)
    {
    	ULONG_PTR a, b;
    	int s = GET_Y_LPARAM(lParamSort) ? -1 : +1;
    	
    	switch (GET_X_LPARAM(lParamSort))
    	{
    	default: __assume(false);
    	case 0:
    		a = p->_index, b = q->_index;
    		break;
    	
    	case 1:
    		a = (ULONG_PTR)p->_BaseOfDll, b = (ULONG_PTR)q->_BaseOfDll;
    		break;
    
    	case 2:
    		a = p->_SizeOfImage, b = q->_SizeOfImage;
    		break;
    
    	case 3:
    		PCWSTR pa = p->_ImageName, pb = q->_ImageName;
    		if (!pa) return -s;
    		if (!pb) return +s;
    		return _wcsicmp(pa, pb)*s;
    	}
    
    	if (a < b) return -s;
    	if (a > b) return +s;
    	return 0;
    }
    
    INT_PTR ZModulesDlg::DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
    	switch (uMsg)
    	{
    	case WM_NOTIFY:
    		if (((LPNMHDR)lParam)->idFrom == IDC_LIST1)
    		{
    			LVITEM lvi;
    
    			switch (((LPNMHDR)lParam)->code)
    			{
    			case LVN_COLUMNCLICK:
    				if ((DWORD)(lvi.iSubItem = ((LPNMLISTVIEW)lParam)->iSubItem) < 4)
    				{
    					ListView_SortItems(((LPNMHDR)lParam)->hwndFrom, ZDll::Compare, 
    						MAKELPARAM(lvi.iSubItem, _bittestandcomplement(&_SortOrder, lvi.iSubItem)));
    				}
    				break;
    
    			case LVN_GETINFOTIP:
    				lvi.iItem = ((LPNMLVGETINFOTIP)lParam)->iItem;
    				lvi.mask = LVIF_PARAM;
    
    				if (ListView_GetItem(((LPNMHDR)lParam)->hwndFrom, &lvi))
    				{
    					if (PWSTR ImagePath = ((ZDll*)lvi.lParam)->_ImagePath)
    					{
    						if (DWORD n = ((LPNMLVGETINFOTIP)lParam)->cchTextMax)
    						{
    							WCHAR *pszText = ((LPNMLVGETINFOTIP)lParam)->pszText, c;
    							do 
    							{
    								*pszText++ = c = *ImagePath++;
    							} while (c && --n);
    
    							if (c)
    							{
    								pszText[-1] = 0;
    							}
    						}
    					}
    				}
    				break;
    			}
    		}
    		break;

    жесть

    zhukas, 17 Ноября 2014

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

    +49

    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
    void ZModulesDlg::OnDestroy(HWND hwnd)
    {
    	LVITEM lvi = { LVIF_PARAM };
    
    	if (lvi.iItem = ListView_GetItemCount(hwnd))
    	{
    		do 
    		{
    			lvi.iItem--;
    			if (ListView_GetItem(hwnd, &lvi))
    			{
    				((ZDll*)lvi.lParam)->Release();
    			}
    		} while (lvi.iItem);
    	}
    }

    zhukas, 17 Ноября 2014

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

    +52

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    template<typename T> Light *create_instance(args &parameters) { return new T(parameters); }
    static map<string, Light* (*)(args &)> light_factory;
    
    template<typename T> GeometricPrimitive * create_instance(args &parameters) { return new T(parameters); }
    static map<string, GeometricPrimitive* (*)(args &)> geometry_factory;

    Откопал в архиве студенческих времен. Ray Tracing. abstract factory по именам.

    codemonkey, 17 Ноября 2014

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

    +53

    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
    const VS_FIXEDFILEINFO* GetFileVersion(PCWSTR name)
    {
    	HMODULE hmod = GetModuleHandle(name);
    	static LPCWSTR a[3] = { RT_VERSION, MAKEINTRESOURCE(1) };
    	PIMAGE_RESOURCE_DATA_ENTRY pirde;
    	PVOID pv;
    	DWORD size;
    
    	return !hmod || 
    		0 > LdrFindResource_U(hmod, a, 3, &pirde) || 
    		0 > LdrAccessResource(hmod, pirde, &pv, &size) ||
    		size < sizeof(VS_FIXEDFILEINFO)
    		? 0 : (VS_FIXEDFILEINFO*)findDWORD((size - sizeof(VS_FIXEDFILEINFO))/sizeof(DWORD) + 1, (PDWORD)pv, 0xfeef04bd);
    }

    zhukas, 17 Ноября 2014

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