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

    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
    // почему это гавно не будет работать?
    auto size = buffer.size() - 1;
    auto *ptr = new byte[size];
    for (auto i = size; i >= 0; i--)
    {
        ptr[i] = 0;
    }
    
    // a это гавно будет работать :)
    auto size = buffer.size() - 1;
    auto *ptr = new byte[size];
    for (int i = size; i >= 0; i--)
    {
        ptr[i] = 0;
    }

    почему это говно не будет работать?

    ASD_77, 17 Марта 2021

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

    0

    1. 1
    Как крестьяне говна поели

    This function is defined as the RtlSecureZeroMemory function (see WinBase.h). The implementation of RtlSecureZeroMemory is provided inline and can be used on any version of Windows (see WinNT.h.)

    Use this function instead of ZeroMemory when you want to ensure that your data will be overwritten promptly, as some C++ compilers can optimize a call to ZeroMemory by removing it entirely.

    Petro-san, 10 Марта 2021

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

    +2

    1. 1
    2. 2
    3. 3
    int i = 42;
    foo(i); //не компилируется
    foo(static_cast<int>(i)); //компилируется

    raMagPuJI, 05 Марта 2021

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

    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
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    // -------------------------------------------
    // 2.2. binary calls
    // -------------------------------------------
    /*
        combination table:
    
          +-   | c a n
            ---|-------
             c | C A N
             a | A A N
             n | N N N
    
          *    | c a n
            ---|-------
             c | C A N
             a | A N N
             n | N N N
    
          /    | c a n
            ---|-------
             c | C N N
             a | A N N
             n | N N N
    
        argument:
          c : constant, as scalar, point, tensor, ect
          l : affine homogeneous expr argument: as field, field_indirect or field_expr_node::is_affine_homogeneous
          n : function, functor or ! field_expr_node::is_affine_homogeneous
        result:
          C : constant : this combination is not implemented here
          A,N : are implemented here
        rules:
          at least one of the two args is not of type "c"
          when c: c value is embeded in bind_first or bind_second
                  and the operation reduces to an unary one
          when a: if it is a field_convertible, it should be wrapped
                  in field_expr_v2_nonlinear_terminal_field
          when c: no wrapper is need
        implementation:
          The a and n cases are grouped, thanks to the wrapper_traits
          and it remains to cases :
            1) both args are  field_expr_v2_nonlinear or a function 
            2) one  arg  is a field_expr_v2_nonlinear or a function and the second argument is a constant
    */
    
    #define _RHEOLEF_make_field_expr_v2_nonlinear_binary(FUNCTION,FUNCTOR)	\
    template<class Expr1, class Expr2>						\
    inline										\
    typename									\
    std::enable_if<									\
         details::is_field_expr_v2_nonlinear_arg<Expr1>::value			\
      && details::is_field_expr_v2_nonlinear_arg<Expr2>::value			\
      && ! details::is_field_expr_v2_constant   <Expr1>::value			\
      && ! details::is_field_expr_v2_constant   <Expr2>::value			\
     ,details::field_expr_v2_nonlinear_node_binary<					\
        FUNCTOR									\
       ,typename details::field_expr_v2_nonlinear_terminal_wrapper_traits<Expr1>::type	\
       ,typename details::field_expr_v2_nonlinear_terminal_wrapper_traits<Expr2>::type 	\
      >										\
    >::type										\
    FUNCTION (const Expr1& expr1, const Expr2& expr2)				\
    {										\
      typedef typename details::field_expr_v2_nonlinear_terminal_wrapper_traits<Expr1>::type wrap1_t; \
      typedef typename details::field_expr_v2_nonlinear_terminal_wrapper_traits<Expr2>::type wrap2_t; \
      return details::field_expr_v2_nonlinear_node_binary <FUNCTOR,wrap1_t,wrap2_t> \
    	(FUNCTOR(), wrap1_t(expr1), wrap2_t(expr2)); 				\
    }										\
    template<class Expr1, class Expr2>						\
    inline										\
    typename 									\
    std::enable_if<									\
         details::is_field_expr_v2_constant     <Expr1>::value			\
      && details::is_field_expr_v2_nonlinear_arg<Expr2>::value			\
      && ! details::is_field_expr_v2_constant   <Expr2>::value			\
     ,details::field_expr_v2_nonlinear_node_unary<					\
        details::binder_first<							\
          FUNCTOR									\
         ,typename details::field_promote_first_argument<				\
            Expr1

    MAKAKA, 25 Февраля 2021

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

    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
    #include <iostream>
    #include <ctime>
    using namespace std;
    
    #define SIZE 200000000
    
    struct StackRazrivator {
    	int data[SIZE];
    };
    
    void razorvi() {
    	cout << "nachinau razrivat\n";
    	StackRazrivator r;
    }
    
    void razrivator() {
    	cout << "razrivator\n";
    	razorvi();
    }
    
    int main() {
        cout << "start" << endl;
    	razrivator();
    	return 0;
    }

    Что выведет программа, если скомпилировать без оптимизаций и почему?

    https://godbolt.org/z/75Yzer

    3_dar, 20 Февраля 2021

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

    −1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    void setAreaPreScale(double scale)
    {
      if(scale == 1)
        setFrameSize(initialFrameSize.first, initialFrameSize.second);
      else
      {
        double widthPart = (1 - initialFrameSize.first) * (1 - scale);
        double heightPart = (1 - initialFrameSize.second) * (1 - scale);
        setFrameSize(initialFrameSize.first + widthPart, initialFrameSize.second + heightPart);
      }
    }

    требуется сделать отложенное масштабирование картинки, сначала рисуется (и скейлится методом setAreaPreScale) рамка с областью, в которую будет замасштабировано, затем отдельной кнопкой будет масштабироваться. в методе происходит рассчёт размера в пикселях рамки прескейла по параметру scale (отношение будущего масштаба к текущему). initialFrameSize на самом деле maxFrameSize, но авторский код сохранён

    gladijos, 11 Февраля 2021

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

    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
    // foo.h
    namespace Xru {
    struct Foo {
        Foo();
    };
    }
    
    // foo1.cpp
    #include <foo.h>
    using namespace Xru;
    Foo::Foo() {}
    
    // foo2.cpp
    #include <foo.h>
    namespace Xru {
    Foo::Foo() {}
    }

    Вы пишите как 1 или 2?
    До меня другой коллега доёбуецца, что нужно как 2.

    3_dar, 10 Февраля 2021

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

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    struct Foo { Foo(int, int); };
    struct Bar { explicit Bar(int, int); };
    
    Foo f1(1, 1); // ok
    Foo f2 {1, 1}; // ok
    Foo f3 = {1, 1}; // ok
    
    Bar b1(1, 1); // ok
    Bar b2 {1, 1}; // ok
    Bar b3 = {1, 1}; // NOT OKAY

    А вы пишите explicit у коньструкторов? До меня коллега доёбуецца, что я не пишу.

    3_dar, 10 Февраля 2021

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

    0

    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
    // https://github.com/google/ruy/blob/2887692065c38ef6617f423feafc6b69dd0a0681/ruy/pack_avx2_fma.cc#L66
    
    inline void Pack8bitColMajorForAvx2Packer(
        const std::int8_t* src_ptr, std::int8_t input_xor,
        const std::int8_t* zerobuf, int src_stride, int remaining_src_cols,
        int src_rows, std::int8_t* packed_ptr, std::int32_t* sums_ptr,
        std::int8_t* trailing_buf) {
      using Layout = PackImpl8bitAvx2::Layout;
      RUY_DCHECK_EQ(Layout::kCols, 8);
      RUY_DCHECK_EQ(Layout::kRows, 4);
      // Each Layout::Rows is 4 contiguous input, contiguous packed elements.
      // We process 8 of these chunks at a time, padding short input chunks.
      constexpr int kNumRowChunks = 8;
      constexpr int kNumChunkedSrcRows = kNumRowChunks * Layout::kRows;
    
      const std::int8_t* src_ptr0 = src_ptr;
      const std::int8_t* src_ptr1 = src_ptr0 + src_stride;
      const std::int8_t* src_ptr2 = src_ptr1 + src_stride;
      const std::int8_t* src_ptr3 = src_ptr2 + src_stride;
      const std::int8_t* src_ptr4 = src_ptr3 + src_stride;
      const std::int8_t* src_ptr5 = src_ptr4 + src_stride;
      const std::int8_t* src_ptr6 = src_ptr5 + src_stride;
      const std::int8_t* src_ptr7 = src_ptr6 + src_stride;
      std::int64_t src_inc0 = kNumChunkedSrcRows;
      std::int64_t src_inc1 = kNumChunkedSrcRows;
      std::int64_t src_inc2 = kNumChunkedSrcRows;
      std::int64_t src_inc3 = kNumChunkedSrcRows;
      std::int64_t src_inc4 = kNumChunkedSrcRows;
      std::int64_t src_inc5 = kNumChunkedSrcRows;
      std::int64_t src_inc6 = kNumChunkedSrcRows;
      std::int64_t src_inc7 = kNumChunkedSrcRows;
      // Handle cases where source does not have Layout::kCols (8) columns.
      if (remaining_src_cols < 8) {
        if (remaining_src_cols <= 0) {
          src_ptr0 = zerobuf;
          src_inc0 = 0;
        }
        if (remaining_src_cols <= 1) {
          src_ptr1 = zerobuf;
          src_inc1 = 0;
        }
        if (remaining_src_cols <= 2) {
          src_ptr2 = zerobuf;
          src_inc2 = 0;
        }
        if (remaining_src_cols <= 3) {
          src_ptr3 = zerobuf;
          src_inc3 = 0;
        }
        if (remaining_src_cols <= 4) {
          src_ptr4 = zerobuf;
          src_inc4 = 0;
        }
        if (remaining_src_cols <= 5) {
          src_ptr5 = zerobuf;
          src_inc5 = 0;
        }
        if (remaining_src_cols <= 6) {
          src_ptr6 = zerobuf;
          src_inc6 = 0;
        }
        src_ptr7 = zerobuf;
        src_inc7 = 0;
      }
    
      const std::int8_t zero_point = zerobuf[0];
    
      if (sums_ptr) {
        // i: Layout::kCols.
        for (int i = 0; i < 8; ++i) {
          sums_ptr[i] = 0;
        }
      }
      std::int32_t sums_adjustment = 0;
      const __m256i ones_16bit = _mm256_set1_epi16(1);
      __m256i sums_4x2_32bit_lo = _mm256_set1_epi32(0);
      __m256i sums_4x2_32bit_hi = _mm256_set1_epi32(0);
    
      // The overall packing effectively pads the source rows to
      // (src_rows + 63) & ~63. The iteration over k may skip when m=1, and then we
      // only pack for (src_rows + 31) & ~31. When there is an incomplete
      // destination block, this is stored into trailing_buf instead of packed_ptr.
      for (int k = 0; k < src_rows; k += kNumChunkedSrcRows) {
        // Available source rows.
        // If this is less than 0 (for m=1), we skip, having filled trailing
        // buffer for m=0. Also, if source rows is zero on m=1, then we filled
        // exactly to the end of the column in the packed buffer.
        const int available_src_rows = src_rows - k;
        // Effectively,
        // available rows = std::max(0, std::min(8, src_rows - k));
        // treat each case separately.
        if (available_src_rows >= kNumChunkedSrcRows) {
          if (sums_ptr) {
            __m256i t0, t1, t2, t3, t4, t5, t6, t7;
            __m256i r0, r1, r2, r3, r4, r5, r6, r7;
            const __m256i input_xor_v = _mm256_set1_epi8(input_xor);
    
            t0 = _mm256_loadu_si256(reinterpret_cast<const __m256i*>(src_ptr0));
            t4 = _mm256_loadu_si256(reinterpret_cast<const __m256i*>(src_ptr4));
            t1 = _mm256_loadu_si256(reinterpret_cast<const __m256i*>(src_ptr1));

    Интересно, они это вручную всё писали, или какой-то хуйней генерировали?

    j123123, 08 Февраля 2021

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

    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
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    // https://github.com/WebKit/WebKit/blob/31b77296cf6d85c40313812d9f65a003cf41f440/Source/WebCore/page/Quirks.cpp#L330
    
    bool Quirks::isGoogleMaps() const
    {
        auto& url = m_document->topDocument().url();
        return topPrivatelyControlledDomain(url.host().toString()).startsWith("google.") && url.path().startsWithIgnoringASCIICase("/maps/");
    }
    
    bool Quirks::shouldDispatchSimulatedMouseEvents() const
    {
        if (RuntimeEnabledFeatures::sharedFeatures().mouseEventsSimulationEnabled())
            return true;
    
        if (!needsQuirks())
            return false;
    
        auto doShouldDispatchChecks = [this] () -> bool {
            auto* loader = m_document->loader();
            if (!loader || loader->simulatedMouseEventsDispatchPolicy() != SimulatedMouseEventsDispatchPolicy::Allow)
                return false;
    
            if (isAmazon())
                return true;
            if (isGoogleMaps())
                return true;
    
            auto& url = m_document->topDocument().url();
            auto host = url.host().convertToASCIILowercase();
    
            if (host == "wix.com" || host.endsWith(".wix.com")) {
                // Disable simulated mouse dispatching for template selection.
                return !url.path().startsWithIgnoringASCIICase("/website/templates/");
            }
    
            if ((host == "desmos.com" || host.endsWith(".desmos.com")) && url.path().startsWithIgnoringASCIICase("/calculator/"))
                return true;
            if (host == "figma.com" || host.endsWith(".figma.com"))
                return true;
            if (host == "trello.com" || host.endsWith(".trello.com"))
                return true;
            if (host == "airtable.com" || host.endsWith(".airtable.com"))
                return true;
            if (host == "msn.com" || host.endsWith(".msn.com"))
                return true;
            if (host == "flipkart.com" || host.endsWith(".flipkart.com"))
                return true;
            if (host == "iqiyi.com" || host.endsWith(".iqiyi.com"))
                return true;
            if (host == "trailers.apple.com")
                return true;
            if (host == "soundcloud.com")
                return true;
            if (host == "naver.com")
                return true;
            if (host == "nba.com" || host.endsWith(".nba.com"))
                return true;
            if (host.endsWith(".naver.com")) {
                // Disable the quirk for tv.naver.com subdomain to be able to simulate hover on videos.
                if (host == "tv.naver.com")
                    return false;
                // Disable the quirk for mail.naver.com subdomain to be able to tap on mail subjects.
                if (host == "mail.naver.com")
                    return false;
                // Disable the quirk on the mobile site.
                // FIXME: Maybe this quirk should be disabled for "m." subdomains on all sites? These are generally mobile sites that don't need mouse events.
                if (host == "m.naver.com")
                    return false;
                return true;
            }
            return false;
        };
    
        if (!m_shouldDispatchSimulatedMouseEventsQuirk)
            m_shouldDispatchSimulatedMouseEventsQuirk = doShouldDispatchChecks();
        return *m_shouldDispatchSimulatedMouseEventsQuirk;
    }

    Дааа блядь, давайте в движке браузера захардкодим какие-то говнодомены, что типа вот для них какая-то там блядь симуляция событий мыши работала каким-то таким образом. Охуенно!

    j123123, 04 Февраля 2021

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