1. Куча / Говнокод #28800

    +1

    1. 1
    Приватный дневник-тред, который никто не прочтёт, чтобы писать сюда всякие секреты.

    Это место для тех, кто устал от публичности социальных сетей.
    Здесь можно взять любой логин, не указывая настоящего имени,
    вести свой дневник, закрыв его от части или всего виртуального
    мира. До 75% записей на сайте подзамочные — для избранных
    читателей. Можно писать в тред, который кроме вас вообще
    никто не прочтет.

    JloJle4Ka, 20 Июня 2023

    Комментарии (265)
  2. Куча / Говнокод #28799

    +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
    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
    // https://github.com/torvalds/linux/blob/b6dad5178ceaf23f369c3711062ce1f2afc33644/rust/alloc/alloc.rs#L376
    pub const fn handle_alloc_error(layout: Layout) -> ! {
        const fn ct_error(_: Layout) -> ! {
            panic!("allocation failed");
        }
    
        fn rt_error(layout: Layout) -> ! {
            unsafe {
                __rust_alloc_error_handler(layout.size(), layout.align());
            }
        }
    
        unsafe { core::intrinsics::const_eval_select((layout,), ct_error, rt_error) }
    }
    
    
    // https://github.com/torvalds/linux/blob/b6dad5178ceaf23f369c3711062ce1f2afc33644/rust/kernel/lib.rs#L96-L103
    fn panic(info: &core::panic::PanicInfo<'_>) -> ! {
        pr_emerg!("{}\n", info);
        // SAFETY: FFI call.
        unsafe { bindings::BUG() };
        // Bindgen currently does not recognize `__noreturn` so `BUG` returns `()`
        // instead of `!`. See <https://github.com/rust-lang/rust-bindgen/issues/2094>.
        loop {}
    }
    
    
    // https://github.com/torvalds/linux/blob/master/include/asm-generic/bug.h#L51-L68
    /*
     * Don't use BUG() or BUG_ON() unless there's really no way out; one
     * example might be detecting data structure corruption in the middle
     * of an operation that can't be backed out of.  If the (sub)system
     * can somehow continue operating, perhaps with reduced functionality,
     * it's probably not BUG-worthy.
     *
     * If you're tempted to BUG(), think again:  is completely giving up
     * really the *only* solution?  There are usually better options, where
     * users don't need to reboot ASAP and can mostly shut down cleanly.
     */
    #ifndef HAVE_ARCH_BUG
    #define BUG() do { \
    	printk("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \
    	barrier_before_unreachable(); \
    	panic("BUG!"); \
    } while (0)
    #endif

    О том, как в ядре Linux говнораст обрабатывает ошибку аллокации

    j123123, 19 Июня 2023

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

    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
    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
    struct node
    {
        void *data;
    
        struct node *head;
        struct node *tail;
    };
    struct list
    {
        int size;
    
        struct node *head;
        struct node *tail;
    
        void *(*alloc_node)(size_t);
        void *(*alloc_data)(size_t);
        void (*free_node)(void *);
        void (*free_data)(void *);
    };
    
    typedef struct node node_t;
    typedef struct list list_t;
    
    void list_init(list_t *list)
    {
        list->size = 0;
    
        list->head = (node_t*)list;
        list->tail = (node_t*)list;
    
        list->alloc_node = &malloc;
        list->alloc_data = &malloc;
        list->free_node = &free;
        list->free_data = &free;
    }
    void list_link(struct node *head, struct node *tail)
    {
        head->tail = tail;
        tail->head = head;
    }
    void *push_head(list_t *list, node_t *head, size_t size)
    {
        node_t *node = list->alloc_node(sizeof(node_t));
        void   *data = list->alloc_data(size);
    
        node->data = data;
        list_link(node, head->tail);
        list_link(head, node);
    
        list->size++;
        return data;
    }
    void *push_tail(list_t *list, node_t *tail, size_t size)
    {
        node_t *node = list->alloc_node(sizeof(node_t));
        void   *data = list->alloc_data(size);
    
        node->data = data;
        list_link(tail->head, node);
        list_link(node, tail);
    
        list->size++;
        return data;
    }
    void pop(list_t *list, node_t *node)
    {
        list_link(node->head, node->tail);
        list->size--;
    
        void *data = node->data;
    
        list->free_node(node);
        list->free_data(data);
    }
    void print(struct list *list)
    {
        printf("\n====\n");
    
        printf("size: %ld \n", list->size);
    
        int i = 0;
    
        for(node_t *node = list->head; node != list; node = node->head)
        {
            printf("index: %ld number: %ld \n", i, *(int*)(node->data));
            i++;
        }
    }
    
    struct list lst;
    
        list_init(&lst);
    
        print(&lst);
    
        void *data;
        data = push_tail(&lst, lst.tail, 4);
        *(int*)data = 1;

    итак скажите про название функций про то каких функций не хватает + alloc и free поля не трогать это мне нужно ТОЛЬКО НЕ советуйте перейти на с++ и использовать чтото другое(std::list)

    CodeTux, 16 Июня 2023

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

    +1

    1. 1
    2. 2
    3. 3
    // Всем привет. Я тоже принёс говнокода, но в необычном формате.
    // А именно, я написал мини-книгу "60 антипаттернов для С++ программиста".
    // https://pvs-studio.ru/ru/blog/posts/cpp/1053/

    Там вы найдёте и реальный C++ говнокод и просто вредные советы в духе "Пишите код так, как будто его будет читать председатель жюри IOCCC и он знает, где вы живёте (чтоб приехать и вручить вам приз)".

    Если сразу не понятно почему "совет" вреден, то там есть соответствующий разбор.

    Готов подискутировать про написанное. Ну и приглашаю накидывать в комментариях аналогичные советы.

    P.S. Предупреждаю: там много букв. Сразу запасайтесь кофе/энергетиком. Или попкорном :)

    Andrey_Karpov, 15 Июня 2023

    Комментарии (57)
  5. Python / Говнокод #28796

    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
    @dataclass(slots=True)
    class Govno:
        govno_index: int
        
        def patch(self, indices_dict: Dict[int, int]) -> None:
            new_index = indices_dict[self.govno_index]
            self.govno_index = new_index
    
    
    @dataclass(slots=True)
    class Mocha:
        mocha_index: int
        
        def patch(self, indices_dict: Dict[int, int]) -> None:
            new_index = indices_dict[self.govno_index]
            self.govno_index = new_index

    Метод «patch» был скопипащен из класса «Govno» в класс «Mocha». Тайпчекер никаких ошибок не показывал; все типы были выведены корректно.

    А в рантайме всё упало, что и неудивительно!

    ISO, 13 Июня 2023

    Комментарии (42)
  6. Куча / Говнокод #28795

    0

    1. 1
    Пиздец-оффтоп #84

    #54: https://govnokod.ru/28353 https://govnokod.xyz/_28353
    #55: https://govnokod.ru/28361 https://govnokod.xyz/_28361
    #56: https://govnokod.ru/28383 https://govnokod.xyz/_28383
    #57: https://govnokod.ru/28411 https://govnokod.xyz/_28411
    #58: https://govnokod.ru/28454 https://govnokod.xyz/_28454
    #59: https://govnokod.ru/28472 https://govnokod.xyz/_28472
    #60: https://govnokod.ru/28540 https://govnokod.xyz/_28540
    #61: https://govnokod.ru/28548 https://govnokod.xyz/_28548
    #62: https://govnokod.ru/28555 https://govnokod.xyz/_28555
    #63: https://govnokod.ru/28573 https://govnokod.xyz/_28573
    #64: https://govnokod.ru/28584 https://govnokod.xyz/_28584
    #65: https://govnokod.ru/28599 https://govnokod.xyz/_28599
    #66: https://govnokod.ru/28609 https://govnokod.xyz/_28609
    #67: https://govnokod.ru/28615 https://govnokod.xyz/_28615
    #68: https://govnokod.ru/28636 https://govnokod.xyz/_28636
    #69: (vanished) https://govnokod.xyz/_28660
    #70: (vanished) https://govnokod.xyz/_28667
    #71: https://govnokod.ru/28677 https://govnokod.xyz/_28677
    #72: https://govnokod.ru/28685 https://govnokod.xyz/_28685
    #73: https://govnokod.ru/28692 https://govnokod.xyz/_28692
    #74: https://govnokod.ru/28699 https://govnokod.xyz/_28699
    #75: https://govnokod.ru/28705 https://govnokod.xyz/_28705
    #76: https://govnokod.ru/28712 https://govnokod.xyz/_28712
    #77: https://govnokod.ru/28722 https://govnokod.xyz/_28722
    #78: https://govnokod.ru/28730 https://govnokod.xyz/_28730
    #79: https://govnokod.ru/28736 https://govnokod.xyz/_28736
    #80: https://govnokod.ru/28740 https://govnokod.xyz/_28740
    #81: https://govnokod.ru/28750 https://govnokod.xyz/_28750
    #82: https://govnokod.ru/28779 https://govnokod.xyz/_28779
    #83: https://govnokod.ru/28788 https://govnokod.xyz/_28788

    nepeKamHblu_nemyx, 13 Июня 2023

    Комментарии (411)
  7. Куча / Говнокод #28794

    0

    1. 1
    IT Оффтоп #185

    #155: https://govnokod.ru/28281 https://govnokod.xyz/_28281
    #156: https://govnokod.ru/28322 https://govnokod.xyz/_28322
    #157: https://govnokod.ru/28344 https://govnokod.xyz/_28344
    #158: https://govnokod.ru/28366 https://govnokod.xyz/_28366
    #159: https://govnokod.ru/28391 https://govnokod.xyz/_28391
    #160: https://govnokod.ru/28434 https://govnokod.xyz/_28434
    #161: https://govnokod.ru/28449 https://govnokod.xyz/_28449
    #162: https://govnokod.ru/28477 https://govnokod.xyz/_28477
    #163: https://govnokod.ru/28501 https://govnokod.xyz/_28501
    #164: https://govnokod.ru/28527 https://govnokod.xyz/_28527
    #165: https://govnokod.ru/28557 https://govnokod.xyz/_28557
    #166: https://govnokod.ru/28574 https://govnokod.xyz/_28574
    #167: https://govnokod.ru/28588 https://govnokod.xyz/_28588
    #168: https://govnokod.ru/28607 https://govnokod.xyz/_28607
    #169: https://govnokod.ru/28628 https://govnokod.xyz/_28628
    #170: https://govnokod.ru/28653 https://govnokod.xyz/_28653
    #171: (vanished) https://govnokod.xyz/_28665
    #172: https://govnokod.ru/28675 https://govnokod.xyz/_28675
    #173: https://govnokod.ru/28681 https://govnokod.xyz/_28681
    #174: https://govnokod.ru/28689 https://govnokod.xyz/_28689
    #175: https://govnokod.ru/28696 https://govnokod.xyz/_28696
    #176: https://govnokod.ru/28703 https://govnokod.xyz/_28703
    #177: https://govnokod.ru/28709 https://govnokod.xyz/_28709
    #178: https://govnokod.ru/28716 https://govnokod.xyz/_28716
    #179: https://govnokod.ru/28726 https://govnokod.xyz/_28726
    #180: https://govnokod.ru/28734 https://govnokod.xyz/_28734
    #181: https://govnokod.ru/28739 https://govnokod.xyz/_28739
    #182: https://govnokod.ru/28749 https://govnokod.xyz/_28749
    #183: https://govnokod.ru/28777 https://govnokod.xyz/_28777
    #184: https://govnokod.ru/28790 https://govnokod.xyz/_28790

    nepeKamHblu_nemyx, 12 Июня 2023

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

    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
    public class Archvile:Actor{public Archvile(){Health=700;Radius=20;Height=56;Mass=500;Speed=15;PainChance=10;Monster=true;MaxTargetRange=896;SetFlag(Flags.QUICKTORETALIATE,true);SetFlag(Flags.FLOORCLIP,true);SetFlag(Flags.NOTARGET,true);SeeSound="vile/sight";PainSound="vile/pain";DeathSound="vile/death";ActiveSound="vile/active";MeleeSound="vile/stop";Obituary="$OB_VILE";Tag="$FN_ARCH";}
    public override void BeginPlay(){base.BeginPlay();SetState("Spawn");}
    void Spawn(){SetState("See");}
    void See(){A_Chase();}
    void Missile(){A_VileStart();A_FaceTarget();A_VileTarget();A_FaceTarget();A_VileAttack();Delay(20);SetState("See");}
    void Heal(){Delay(10);SetState("See");}
    void Pain(){A_Pain();SetState("See");}
    void Death(){A_Scream();A_NoBlocking();Delay(7);SetState("Death   1");}
    void Death1(){Delay(7);SetState("Death   2");}
    void Death2(){Delay(7);SetState("Death   3");}
    void Death3(){Delay(7);SetState("Death   4");}
    void Death4(){Delay(7);SetState("Death   5");}
    void Death5(){Delay(7);SetState("Death   6");}
    void Death6(){Delay(7);SetState("Death   7");}
    void Death7(){Delay(1);Destroy();}
    void A_VileStart(){StartSound("vile/start",CHAN_VOICE);}
    void A_VileTarget(){if(target!=null){A_FaceTarget();Actor fog=Spawn<Actor>("ArchvileFire",target.Pos,SpawnFlags.ALLOW_REPLACE);if(fog!=null){tracer=fog;fog.target=self;fog.tracer=self.target;fog.A_Fire(0);}}}
    void A_VileAttack(){Actor targ=target;if(targ!=null){A_FaceTarget();if(!CheckSight(targ,0))return;StartSound("vile/stop",CHAN_WEAPON);int newdam=targ.DamageMobj(self,self,20,DamageType.none);if(newdam>0)targ.TraceBleed(newdam,self);Actor fire=tracer;if(fire!=null){fire.SetOrigin(targ.Vec3Angle(-24.0,angle,0),true);fire.A_Explode(70,70,ExplosionFlags.XF_NOSPLASH,false,0,0,0,"BulletPuff",DamageType.Fire);}
    if(!targ.bDontThrust){targ.Vel.z=1000.0*thrust/Math.Max(1,targ.Mass);}}}
    void A_StartFire(){StartSound("vile/firestrt",CHAN_BODY);A_Fire();}
    void A_Fire(){Actor dest=tracer;if(dest==null||target==null)return;if(!target.CheckSight(dest,0))return;SetOrigin(dest.Vec3Angle(24,dest.angle,0),true);}
    void A_FireCrackle(){StartSound("vile/firecrkl",CHAN_BODY);A_Fire();}}
    public static class ActorExtensions{public static void A_VileStart(this Actor self){self.StartSound("vile/start",CHAN_VOICE);}
    public static void A_VileTarget(this Actor self,string fire="ArchvileFire"){if(self.target!=null){self.A_FaceTarget();Actor fog=self.Spawn<Actor>(fire,self.target.Pos,SpawnFlags.ALLOW_REPLACE);if(fog!=null){self.tracer=fog;fog.target=self;fog.tracer=self.target;fog.A_Fire(0);}}}
    public static void A_VileAttack(this Actor self,string snd="vile/stop",int initialdmg=20,int blastdmg=70,int blastradius=70,double thrust=1.0,string damagetype="Fire",int flags=0){Actor targ=self.target;if(targ!=null){self.A_FaceTarget();if(!self.CheckSight(targ,0))return;self.StartSound(snd,CHAN_WEAPON);int newdam=targ.DamageMobj(self,self,initialdmg,(flags

    Арчвайл из ZDooM на C#

    DartPower, 07 Июня 2023

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

    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
    const ttfMeta = require('ttfmeta');
    const fs = require('fs');
    
    let oldName = process.argv[2];
    
    ttfMeta.ttfInfo(oldName, (err, result) => {
      if (err) {
        console.log('error', err)
      } else {
        let newName = result.tables.name[6];
    
        if(newName.charCodeAt(0) === 0) {
            let buf = new ArrayBuffer(newName.length);
            let bufView = new Uint16Array(buf);
            for (let i = 0, strLen = newName.length / 2; i < strLen; i++) {
              bufView[i] = (newName.charCodeAt(2 * i) << 8) + newName.charCodeAt(2 * i + 1);
            }
            newName = String.fromCharCode.apply(null, bufView);
        }
        
        newName = 'renamed/' + newName + '.ttf';
        fs.createReadStream(oldName).pipe(fs.createWriteStream(newName));
      }
    });

    Дано: 100500 ttf-файлов с рандомными именами файла (цифры, гуиды, что угодно, но только не название шрифта).
    Требуется: переименовать файлы так, чтобы название хоть как-то было похоже на имя шрифта.
    Решение: есть 100500 библиотек на сишке для вытаскивания метушни из ttf-файлов, но мы же извращенцы, поэтому напишем на скриптушне.

    Багор: пакет «ttfmeta» из «npm» иногда возвращает нормальные текстовые строки, а иногда хуйню (детектируемую условием newName.charCodeAt(0) === 0), когда пара соседних «символов» — это на самом деле половинки кодпоинта из кодировки utf16be. «Нода» умеет только в toString('utf16le'), а кодировку с большим индейцем ('utf16be') не знает.

    Izumka, 05 Июня 2023

    Комментарии (54)
  10. Java / Говнокод #28791

    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
    public class MathGame {
    
        public static Map<Integer, String> data = new HashMap<Integer, String>();
        public static Map<String, Integer> result = new HashMap<String, Integer>();
        String problem;
        Random random = new Random();
    
        public void NewProblem() {
    
            String sign = null;
    
            for (int i = 1; i < 5; i++) {
    
                switch (GenNumber(3)) {
                    case 1:
                        sign = Sign.MINUS.get();
                        break;
                    case 2:
                        sign = Sign.PLUS.get();
                        break;
                    case 3:
                        sign = Sign.TIMES.get();
                        break;
                    default:
                        sign = Sign.PLUS.get();
                        break;
                }
    
                problem = GenNumber(9) + " " + sign + " " + GenNumber(9);
                result.put(problem + " = ???", Decide(Integer.parseInt(
                        problem.split(" ")[0]), problem.split(" ")[1], Integer
                        .parseInt(problem.split(" ")[2])));
                data.put(i, problem);
    
            }
        }
    
        private int GenNumber(int s) {
            return random.nextInt(s) + 1;
        }
    
        private int Decide(int a, String sign, int b) {
            switch (sign) {
                case "+":
                    return a + b;
                case "-":
                    return a - b;
                case "*":
                    return a * b;
            }
            return 0;
        }
    
        public enum Sign {
            PLUS("+"),
            MINUS("-"),
            TIMES("*");
    
            private final String sign;
    
            Sign(String sign) {
                this.sign = sign;
            }
    
            public String get() {
                return sign;
            }
    
        }
    
    }

    girixok149, 05 Июня 2023

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