1. 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)
  2. 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)
  3. 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)
  4. 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)
  5. 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)
  6. 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)
  7. C++ / Говнокод #17115

    +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
    79. 79
    int lenNameTrack = byteArrAudioFile->size() - 128 + 3,
          lenAutorTrack =             byteArrAudioFile->size() - 128 + 3 + 30,
          lenAlbumTrack =            byteArrAudioFile->size() - 128 + 3 + 30 + 30,
          lenYearTrack =               byteArrAudioFile->size() - 128 + 3 + 30 + 30 + 30,
          lenCommentTrack =      byteArrAudioFile->size() - 128 + 3 + 30 + 30 + 30 + 4,
          lenFlagNumberTrack =   byteArrAudioFile->size() - 128 + 3 + 30 + 30 + 30 + 4 + 28,
          lenNumberTrack =         byteArrAudioFile->size() - 128 + 3 + 30 + 30 + 30 + 4 + 28 + 1,
          lenIdGenreTrack =         byteArrAudioFile->size() - 128 + 3 + 30 + 30 + 30 + 4 + 28 + 1 + 1;
    
                      for(int i = byteArrAudioFile->size() - 128+3; i <= byteArrAudioFile->size(); i++)
                      {
                          if(i == lenAutorTrack) //Названние трэка
                              for(int j = lenNameTrack, k = 0;   j < lenAutorTrack; ++j)
                              {
                                  if( (int) byteArrAudioFile->at(j) == 0)
                                      break;
                                  if( ((int) byteArrAudioFile->at(j)) < 0 )
                                      ID3v1.title.append( toUnicod( (int) byteArrAudioFile->at(j) ) );
                                  else ID3v1.title.append(  byteArrAudioFile->at(j) );
                              }
                          if(i == lenAlbumTrack) //Исполнитель
                              for(int j = lenAutorTrack; j < lenAlbumTrack; ++j)
                              {
                                  if( (int) byteArrAudioFile->at(j) == 0)
                                      break;
                                  if( ((int) byteArrAudioFile->at(j)) < 0 )
                                      ID3v1.autor.append( toUnicod( (int) byteArrAudioFile->at(j) ) );
                                  else ID3v1.autor.append(  byteArrAudioFile->at(j) );
                              }
                          if(i == lenYearTrack) //Альбом
                              for(int j = lenAlbumTrack; j < lenYearTrack; ++j)
                              {
                                  if( (int) byteArrAudioFile->at(j) == 0)
                                      break;
                                  if( ((int) byteArrAudioFile->at(j)) < 0 )
                                      ID3v1.album.append( toUnicod( (int) byteArrAudioFile->at(j) ) );
                                  else ID3v1.album.append(  byteArrAudioFile->at(j) );
                              }
                          if(i == lenCommentTrack) //Год
                              for(int j = lenYearTrack; j < lenCommentTrack; ++j)
                              {
                                  if( (int) byteArrAudioFile->at(j) == 0)
                                      break;
                                  ID3v1.year.append(byteArrAudioFile->at(j));
                              }
                          if(i == lenFlagNumberTrack) //Комментарий
                              for(int j = lenCommentTrack; j < lenFlagNumberTrack; ++j)
                              {
                                  if( (int) byteArrAudioFile->at(j) == 0)
                                      break;
                                  if( ((int) byteArrAudioFile->at(j)) < 0 )
                                      ID3v1.comment.append( toUnicod( (int) byteArrAudioFile->at(j) ) );
                                  else ID3v1.comment.append(  byteArrAudioFile->at(j) );
                              }
                          if(i == lenNumberTrack) //Если есть номер трэка то установлен нулевой байт
                              for(int j = lenFlagNumberTrack; j < lenNumberTrack; ++j)
                              {
                                  if( (int) byteArrAudioFile->at(j) == 0)
                                      break;
                                  ID3v1.flagNumberTrack.append(byteArrAudioFile->at(j));
                              }
                          if(i == lenIdGenreTrack) //Номер трэка
                              for(int j = lenNumberTrack; j < lenIdGenreTrack; ++j)
                              {
                                  if( (int) byteArrAudioFile->at(j) == 0)
                                      break;
                                  ID3v1.numberTrack.append(byteArrAudioFile->at(j));
                              }
                          if(i == lenIdGenreTrack + 1) //Индетификатор жанра
                          {
                              for(int j = lenIdGenreTrack; j <= lenIdGenreTrack; ++j)
                              {
                                  if( (int) byteArrAudioFile->at(j) == 0)
                                      break;
                                  ID3v1.genre.append( QString::number( (int) byteArrAudioFile->at(j)));
                              }
                              ID3v1.genre.append(genreList(ID3v1.genre.toInt()));
                          }
                      }

    Парсинг ID3v1 тегов

    ConstantineVL, 16 Ноября 2014

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

    +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
    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
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    99. 99
    void zxc()
    {
    	DWORD i = 256, j, k, l, nTry, N = 0;
    	ULONG_PTR a = 0, b = 0, aa = 0, bb = 0;
    	_PTE* pte = PXE(256);
    	do 
    	{
    		if (pte->Valid)
    		{
    			pte->Owner = 1;
    			__try
    			{
    				j = 0, nTry = 0;
    
    				_PTE* pte = PPE(i, 0);
    
    				do 
    				{
    					if (pte->Valid)
    					{
    						pte->Owner = 1;
    
    						__try
    						{
    							k = 0, nTry = 0;
    
    							_PTE* pte = PDE(i, j, 0);
    
    							do 
    							{
    								if (pte->Valid)
    								{
    									pte->Owner = 1;
    
    									if (pte->LargePage)
    									{
    										b = LA(i, j, k, 0);
    
    										if (!a)
    										{
    											a = b;
    										}
    										continue;
    									}
    									__try
    									{
    										l = 0, nTry = 0;
    
    										_PTE* pte = PTE(i, j, k, 0);
    
    										do 
    										{
    											b = LA(i, j, k, l);
    
    											if (pte->Valid)
    											{
    												pte->Owner = 1;
    
    												if (!a)
    												{
    													a = b;
    												}
    											}
    											else
    											{
    												if (!pte->Prototype && pte->Protection && pte->Protection < MM_NOCACHE)
    												{
    												}
    												else if (a)
    												{
    													aa = a, bb = b, a = 0, N++;
    												}
    											}
    										} while (nTry = 0, ++pte, ++l < PTE_PER_PAGE);
    									}
    									__except(OnPteException(pte, nTry)){}
    								}
    								else if (a)
    								{
    									aa = a, bb = LA(i, j, k, 0), a = 0, N++;
    								}
    							} while (nTry = 0, ++pte, ++k < PDE_PER_PAGE);
    						}
    						__except(OnPteException(pte, nTry)){}
    					}
    					else if (a)
    					{
    						aa = a, bb = LA(i, j, 0, 0), a = 0, N++;
    					}
    				} while (nTry = 0, ++pte, ++j < PPE_PER_PAGE);
    			}
    			__except(OnPteException(pte, nTry)){}
    		}
    		else if (a)
    		{
    			aa = a, bb = LA(i, 0, 0, 0), a = 0, N++;
    		}
    	} while (++pte, ++i < PXE_PER_PAGE);
    }

    #define LA(i, j, k, l) (0xFFFF000000000000 + \
    ((ULONG_PTR)(i) << PXI_SHIFT) + \
    ((ULONG_PTR)(j) << PPI_SHIFT) + \
    ((ULONG_PTR)(k) << PDI_SHIFT) + \
    ((ULONG_PTR)(l) << PTI_SHIFT))

    zhukas, 15 Ноября 2014

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

    +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
    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
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    99. 99
    DWORD getDirectoryIndex()
    	{
    		STATIC_OBJECT_ATTRIBUTES(oa, "\\");
    		HANDLE hFile;
    		DWORD ObjectTypeIndex = 0;
    
    		if (0 <= ZwOpenDirectoryObject(&hFile, DIRECTORY_QUERY, &oa))
    		{
    			NTSTATUS status;
    			PVOID buf = 0, stack = alloca(guz);
    			DWORD cb = 0, rcb = 0x10000;
    
    			do 
    			{
    				if (cb < rcb) cb = RtlPointerToOffset(buf = alloca(rcb - cb), stack);
    
    				if (0 <= (status = ZwQuerySystemInformation(SystemExtendedHanfleInformation, buf, cb, &rcb)))
    				{
    					PSYSTEM_HANDLE_INFORMATION_EX pshti = (PSYSTEM_HANDLE_INFORMATION_EX)buf;
    
    					if (ULONG NumberOfHandles = (ULONG)pshti->NumberOfHandles)
    					{
    						PSYSTEM_HANDLE_TABLE_ENTRY_INFO_EX Handles = pshti->Handles;
    
    						ULONG_PTR UniqueProcessId = GetCurrentProcessId();
    						do 
    						{
    							if (Handles->UniqueProcessId == UniqueProcessId && Handles->HandleValue == (ULONG_PTR)hFile)
    							{
    								ObjectTypeIndex = Handles->ObjectTypeIndex;
    								break;
    							}
    
    						} while (Handles++, --NumberOfHandles);
    					}
    				}
    			} while (STATUS_INFO_LENGTH_MISMATCH == status);
    
    			ZwClose(hFile);
    		}
    
    		return ObjectTypeIndex;
    	}
    
    	ZOBJECT_ALL_TYPES_INFORMATION()
    	{
    		_TypeInformation = 0, _NumberOfTypes = 0;
    
    		if (DWORD DirectoryTypeIndex = getDirectoryIndex())
    		{
    			PVOID stack = alloca(guz);
    			OBJECT_ALL_TYPES_INFORMATION* poati = 0;
    			DWORD cb = 0, rcb = 0x2000;
    			NTSTATUS status;
    			do 
    			{
    				if (cb < rcb)
    				{
    					cb = RtlPointerToOffset(poati = (OBJECT_ALL_TYPES_INFORMATION*)alloca(rcb - cb), stack);
    				}
    
    				if (0 <= (status = ZwQueryObject(0, ObjectAllTypeInformation, poati, cb, &rcb)))
    				{
    					if (DWORD NumberOfTypes = poati->NumberOfTypes)
    					{
    						if (OBJECT_TYPE_INFORMATION* TypeInformation = (OBJECT_TYPE_INFORMATION*)LocalAlloc(0, rcb))
    						{
    							_NumberOfTypes = NumberOfTypes;
    							_TypeInformation = TypeInformation;
    
    							STATIC_UNICODE_STRING_(Directory);
    							OBJECT_TYPE_INFORMATION* pti = poati->TypeInformation;
    							PWSTR buf = (PWSTR)(TypeInformation + NumberOfTypes);
    							int Index = 0;
    							do 
    							{
    								if (RtlEqualUnicodeString(&Directory, &pti->TypeName, TRUE))
    								{
    									_firstObjectTypeIndex = DirectoryTypeIndex - Index;
    								}
    
    								DWORD Length = pti->TypeName.Length, MaximumLength = pti->TypeName.MaximumLength;
    								memcpy(buf, pti->TypeName.Buffer, Length);
    
    								*TypeInformation = *pti;
    								TypeInformation++->TypeName.Buffer = buf;
    
    								buf = (PWSTR)RtlOffsetToPointer(buf, Length);
    
    								pti = (OBJECT_TYPE_INFORMATION*)
    									(((ULONG_PTR)pti + sizeof(OBJECT_TYPE_INFORMATION) + MaximumLength + sizeof(PVOID)-1) & ~(sizeof(PVOID)-1));
    
    							} while (Index++, --NumberOfTypes);
    						}
    					}
    				}
    			} while (status == STATUS_INFO_LENGTH_MISMATCH);
    		}
    	}

    ObjectTypeIndex

    zhukas, 15 Ноября 2014

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

    +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
    #include <iostream>
    using namespace std;
    
    void f(int i)
    {
    	cout << "----" << endl;
    	void *array[] = { &&foo, &&bar, &&baz };
    	goto *array[i];
    	foo:
    	cout << "Foo" << endl;
    	bar:
    	cout << "Bar" << endl;
    	baz:
    	cout << "Baz" << endl;
    }
    
    int main() {
    	// your code goes here
    	f(0);
    	f(1);
    	f(2);
    	return 0;
    }

    http://ideone.com/63tRls
    gcc extension

    DlangGovno, 10 Ноября 2014

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