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

    −1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    enum class NodeFlags : int {
        None               = 0,
        Let                = 1 << 0,
    // ...
    }
    
    contextFlags &= ~flag;
    
    // error C2675: unary '~': 'NodeFlags' does not define this operator or a conversion to a type acceptable to the predefined operator

    Кому нужны такие гавно-компиляторы? которые даже не в состоянии привети четко прописанные типы?

    ASD_77, 20 Марта 2021

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    metrics_key::metrics_key(std::initializer_list<std::string> const& il) {
      TRI_ASSERT(il.size() > 0);
      TRI_ASSERT(il.size() < 3);
      name = *il.begin();
      if (il.size() == 2) {
        labels = *(il.begin()+1);
      }
      _hash = std::hash<std::string>{}(name + labels);
    }

    просто гавно

    gnusmas, 18 Марта 2021

    Комментарии (36)
  3. Си / Говнокод #27302

    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
    if (LD3_state == 0 || LD2_state == 0 || LD1_state == 0)
    {
        GPIO_SetBits(GPIOB, LED1); //RED ON
        LD_Status = NO_LOCK;
    }
    else
    {
        LD_Status = LOCK_OK;
    }
    
    if (LD4_state == 0 && LD_Status == LOCK_OK)
    {
        GPIO_SetBits(GPIOB, LED1); //RED ON
    }
    else
    {
        GPIO_ResetBits(GPIOB, LED1); //RED OF
    }
    
    if (LD4_state == 0 && LD_Status == LOCK_OK)
    {
        GPIO_ResetBits(GPIOB, LED1); //RED OFF
    }
    
    /* Ну можно же было сделать по-человечески, а? */
    /* Эквивалентный код: */
    
    LD_Status = LD1_state && LD2_state && LD3_state && LD4_state;
    if (LD_Status)
    {
        GPIO_ResetBits(GPIOB, LED1); //RED OFF
    }
    else
    {
        GPIO_SetBits(GPIOB, LED1); //RED ON
    }

    Как же я ненавижу чье-то легаси...

    viteo, 18 Марта 2021

    Комментарии (33)
  4. 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)
  5. JavaScript / Говнокод #27300

    0

    1. 1
    2. 2
    3. 3
    // These are equivalent:
    fn`some string here`;
    fn(['some string here']);

    Джаваскриптеры переизобрели руби (ладно-ладно, скрестили с FormattableString из шарпа)

    https://styled-components.com/docs/advanced#tagged-template-literals

    Fike, 16 Марта 2021

    Комментарии (14)
  6. JavaScript / Говнокод #27299

    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
    // Since styled-components allows you to use arbitrary input as interpolations, you must be careful to sanitize that input.
    // Using user input as styles can lead to any CSS being evaluated in the user's browser that an attacker can place in your application.
    
    // This example shows how bad user input can even lead to API endpoints being called on a user's behalf.
    
    // Oh no! The user has given us a bad URL!
    const userInput = '/api/withdraw-funds'
    
    const ArbitraryComponent = styled.div`
      background: url(${userInput});
      /* More styles here... */
    `

    в процессе многолетнего пересоздания ruby on rails с нуля фронтендеры умудрились accidentally a bottle of injections

    https://styled-components.com/docs/advanced#security

    Fike, 16 Марта 2021

    Комментарии (61)
  7. Pascal / Говнокод #27297

    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
    type
    .....
    TSyncParamsPasser = class
       PassedJSON:String;
       constructor Create(RJS:String);
       procedure ProcessExternalCmd;
      end;
    .....
    .....
    procedure TForm1.TCPServerExecute(AContext: TIdContext);
    begin
    .....
       SyncParamsPasser:=TSyncParamsPasser.Create(CustomData);
       TIdSync.SynchronizeMethod(SyncParamsPasser.ProcessExternalCmd);
       FreeAndNil(SyncParamsPasser);
    .....
    end;
    .....
    constructor TSyncParamsPasser.Create(RJS:String);
    begin
     PassedJSON:=RJS;
    end;
    
    procedure TSyncParamsPasser.ProcessExternalCmd;
    var
     JSON:TJSONObject;
    begin
     JSON:=TJSONObject.ParseJSONValue(PassedJSON) as TJSONObject;
    .....

    Событие OnExecute компонента TCPServer вызывается из рабочего потока, в котором обрабатывается входящее подключение.

    Способ передачи параметров в процедуру, выполняющуюся внутри Synchronize, с помощью класса.
    Говно или сойдёт?

    SmseR, 16 Марта 2021

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

    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
    using System;
    
    namespace NoName
    {
        class TwoVariables
        {
            static void Main(string[] args)
            {
                Int32 FirstVariable = Convert.ToInt32(Console.ReadLine());
                Int32 SecondVariable = Convert.ToInt32(Console.ReadLine());
                FirstVariable = FirstVariable + SecondVariable;
                SecondVariable = FirstVariable - SecondVariable;
                FirstVariable = FirstVariable - SecondVariable;
                Console.WriteLine("First Variable is: " + FirstVariable);
                Console.WriteLine("Second Variable is: " + SecondVariable);
                Console.ReadKey();
            }
        }
    }
    
    
    
    
    
    
    
    
    
    
    // Продам гараж

    BelCodeMonkey, 15 Марта 2021

    Комментарии (19)
  9. Си / Говнокод #27294

    +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
    // https://gcc.gnu.org/onlinedocs/gcc-10.1.0/gcc/Common-Function-Attributes.html
    
    access
    access (access-mode, ref-index)
    access (access-mode, ref-index, size-index)
    
    // примеры:
    
    __attribute__ ((access (read_only, 1))) int puts (const char*);
    __attribute__ ((access (read_only, 1, 2))) void* memcpy (void*, const void*, size_t);
    
    __attribute__ ((access (read_write, 1), access (read_only, 2))) char* strcat (char*, const char*);
    
    __attribute__ ((access (write_only, 1), access (read_only, 2))) char* strcpy (char*, const char*);
    __attribute__ ((access (write_only, 1, 2), access (read_write, 3))) int fgets (char*, int, FILE*);

    В GCC 10 какой-то новый атрибут access появился, чтоб более строго что-то там гарантировать:

    The access attribute enables the detection of invalid or unsafe accesses by functions to which they apply or their callers, as well as write-only accesses to objects that are never read from. Such accesses may be diagnosed by warnings such as -Wstringop-overflow, -Wuninitialized, -Wunused, and others.

    The access attribute specifies that a function to whose by-reference arguments the attribute applies accesses the referenced object according to access-mode. The access-mode argument is required and must be one of three names: read_only, read_write, or write_only. The remaining two are positional arguments.

    The required ref-index positional argument denotes a function argument of pointer (or in C++, reference) type that is subject to the access. The same pointer argument can be referenced by at most one distinct access attribute.

    The optional size-index positional argument denotes a function argument of integer type that specifies the maximum size of the access. The size is the number of elements of the type referenced by ref-index, or the number of bytes when the pointer type is void*. When no size-index argument is specified, the pointer argument must be either null or point to a space that is suitably aligned and large for at least one object of the referenced type (this implies that a past-the-end pointer is not a valid argument). The actual size of the access may be less but it must not be more.

    j123123, 14 Марта 2021

    Комментарии (242)
  10. Куча / Говнокод #27293

    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
    start_link(Shard, Subscriber) ->
        gen_server:start_link(?MODULE, {server, Shard, Subscriber}, []).
    
    start_link_client(Shard, RemoteNode, Parent) ->
        gen_server:start_link(?MODULE, {client, Shard, RemoteNode, Parent}, []).
    
    
    init({server, Shard, Subscriber}) ->
        {ok, #server{ shard      = Shard
                    , subscriber = Subscriber
                    }};
    init({client, Shard, RemoteNode, Parent}) ->
        {ok, #client{ parent     = Parent
                    , shard      = Shard
                    }}.

    CHayT, 12 Марта 2021

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