1. Си / Говнокод #12653

    +135

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    // где-то в коде нашлось
    PRIVATE IdxArray* idx_array_append_val_dyn(IdxArray* arr, PlmIndex idx)
    
    // private.h
    #ifdef PLM_TEST
    #define PRIVATE extern
    #else
    #define PRIVATE static
    #endif

    внезапно...

    Try, 26 Февраля 2013

    Комментарии (34)
  2. Си / Говнокод #12604

    +125

    1. 1
    2. 2
    3. 3
    4. 4
    void get_me(const char **retval)
    {
        *retval = "Hello, Word!";
    }

    Надейся на компилятор...

    Novi4oK, 16 Февраля 2013

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

    +131

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    void *threadFunc(void *)
    {
    	// ...
    	pthread_exit( (void*)lTaskId );
    	return ( (void*)lTaskId );
    	// ...
    }

    позабавило.

    для непосвященных: return в функции потока аналогичен вызову pthread_exit().

    Dummy00001, 11 Февраля 2013

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

    +139

    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
    long __stdcall wndproc(HWND wnd, unsigned int message, WPARAM wparam, LPARAM lparam)
    {
    	switch(message)
    	{
    	case WM_USER + 100:
    		{
    			char data[128];
    			fill_data(data);
    			PostMessage(wnd, WM_USER + 666,  0, (LPARAM)data);
    			return 0;
    		}
    	case WM_USER + 666:
    		{
    			char * data = (char *)lparam;
    			use_data(data);
    			return 0;
    		}
    //etc

    Wandering of the pointer или как выжить вне стека.

    Xom94ok, 05 Февраля 2013

    Комментарии (26)
  5. Си / Говнокод #12534

    +111

    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
    /* ..от молодых, дерзких и успешных,
    форматирование и комментарии сохранены. */
    void zanulit_massiv ()
    {
    	int i;
    	for(i=0;i<27;i++) // dlja vseh elementov massiva
    	{
    		switch (i)   // perebiraem
    		{
    		case 0: mass_znach[0]=3;
    		case 1: mass_znach[0]=5;
    		case 2: mass_znach[0]=6;
    		case 3: mass_znach[0]=1;
    		case 4: mass_znach[0]=2;
    		case 5: mass_znach[0]=3;
    		case 6: mass_znach[0]=4;
    		case 7: mass_znach[0]=5;
    		case 8: mass_znach[0]=6;
    		case 9: mass_znach[0]=31;
    		case 10: mass_znach[0]=2;
    		case 11: mass_znach[0]=1;
    		case 12: mass_znach[0]=1;
    		case 13: mass_znach[0]=1;
    		case 14: mass_znach[0]=33;
    		case 15: mass_znach[0]=15;
    		case 16: mass_znach[0]=13;
    		case 17: mass_znach[0]=8;
    		case 18: mass_znach[0]=43;
    		case 19: mass_znach[0]=2;
    		case 20: mass_znach[0]=9;
    		case 21: mass_znach[0]=14;
    		case 22: mass_znach[0]=17;
    		case 23: mass_znach[0]=21;
    		case 24: mass_znach[0]=22;
    		case 25: mass_znach[0]=8;
    		case 26: mass_znach[0]=5;
    		default: break; // objazatelno v sluchae neizvesnogo znacheniya
    		}
    	}
    }

    Не могу больше :|

    neudachnik, 03 Февраля 2013

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

    +139

    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
    for( i=0; i<MAX_CHANNELS; i++ )
      {
        ht->ht_Voices[i].vc_Delta=1;
        ht->ht_Voices[i].vc_OverrideTranspose=1000;  // 1.5
        ht->ht_Voices[i].vc_SamplePos=ht->ht_Voices[i].vc_Track=ht->ht_Voices[i].vc_Transpose=ht->ht_Voices[i].vc_NextTrack = ht->ht_Voices[i].vc_NextTranspose = 0;
        ht->ht_Voices[i].vc_ADSRVolume=ht->ht_Voices[i].vc_InstrPeriod=ht->ht_Voices[i].vc_TrackPeriod=ht->ht_Voices[i].vc_VibratoPeriod=ht->ht_Voices[i].vc_NoteMaxVolume=ht->ht_Voices[i].vc_PerfSubVolume=ht->ht_Voices[i].vc_TrackMasterVolume=0;
        ht->ht_Voices[i].vc_NewWaveform=ht->ht_Voices[i].vc_Waveform=ht->ht_Voices[i].vc_PlantSquare=ht->ht_Voices[i].vc_PlantPeriod=ht->ht_Voices[i].vc_IgnoreSquare=0;
        ht->ht_Voices[i].vc_TrackOn=ht->ht_Voices[i].vc_FixedNote=ht->ht_Voices[i].vc_VolumeSlideUp=ht->ht_Voices[i].vc_VolumeSlideDown=ht->ht_Voices[i].vc_HardCut=ht->ht_Voices[i].vc_HardCutRelease=ht->ht_Voices[i].vc_HardCutReleaseF=0;
        ht->ht_Voices[i].vc_PeriodSlideSpeed=ht->ht_Voices[i].vc_PeriodSlidePeriod=ht->ht_Voices[i].vc_PeriodSlideLimit=ht->ht_Voices[i].vc_PeriodSlideOn=ht->ht_Voices[i].vc_PeriodSlideWithLimit=0;
        ht->ht_Voices[i].vc_PeriodPerfSlideSpeed=ht->ht_Voices[i].vc_PeriodPerfSlidePeriod=ht->ht_Voices[i].vc_PeriodPerfSlideOn=ht->ht_Voices[i].vc_VibratoDelay=ht->ht_Voices[i].vc_VibratoCurrent=ht->ht_Voices[i].vc_VibratoDepth=ht->ht_Voices[i].vc_VibratoSpeed=0;
        ht->ht_Voices[i].vc_SquareOn=ht->ht_Voices[i].vc_SquareInit=ht->ht_Voices[i].vc_SquareLowerLimit=ht->ht_Voices[i].vc_SquareUpperLimit=ht->ht_Voices[i].vc_SquarePos=ht->ht_Voices[i].vc_SquareSign=ht->ht_Voices[i].vc_SquareSlidingIn=ht->ht_Voices[i].vc_SquareReverse=0;
        ht->ht_Voices[i].vc_FilterOn=ht->ht_Voices[i].vc_FilterInit=ht->ht_Voices[i].vc_FilterLowerLimit=ht->ht_Voices[i].vc_FilterUpperLimit=ht->ht_Voices[i].vc_FilterPos=ht->ht_Voices[i].vc_FilterSign=ht->ht_Voices[i].vc_FilterSpeed=ht->ht_Voices[i].vc_FilterSlidingIn=ht->ht_Voices[i].vc_IgnoreFilter=0;
        ht->ht_Voices[i].vc_PerfCurrent=ht->ht_Voices[i].vc_PerfSpeed=ht->ht_Voices[i].vc_WaveLength=ht->ht_Voices[i].vc_NoteDelayOn=ht->ht_Voices[i].vc_NoteCutOn=0;
        ht->ht_Voices[i].vc_AudioPeriod=ht->ht_Voices[i].vc_AudioVolume=ht->ht_Voices[i].vc_VoiceVolume=ht->ht_Voices[i].vc_VoicePeriod=ht->ht_Voices[i].vc_VoiceNum=ht->ht_Voices[i].vc_WNRandom=0;
        ht->ht_Voices[i].vc_SquareWait=ht->ht_Voices[i].vc_FilterWait=ht->ht_Voices[i].vc_PerfWait=ht->ht_Voices[i].vc_NoteDelayWait=ht->ht_Voices[i].vc_NoteCutWait=0;
        ht->ht_Voices[i].vc_PerfList=0;
        ht->ht_Voices[i].vc_RingSamplePos=ht->ht_Voices[i].vc_RingDelta=ht->ht_Voices[i].vc_RingPlantPeriod=ht->ht_Voices[i].vc_RingAudioPeriod=ht->ht_Voices[i].vc_RingNewWaveform=ht->ht_Voices[i].vc_RingWaveform=ht->ht_Voices[i].vc_RingFixedPeriod=ht->ht_Voices[i].vc_RingBasePeriod=0;
    
        ht->ht_Voices[i].vc_RingMixSource = NULL;
        ht->ht_Voices[i].vc_RingAudioSource = NULL;
    
        memset(&ht->ht_Voices[i].vc_SquareTempBuffer,0,0x80);
        memset(&ht->ht_Voices[i].vc_ADSR,0,sizeof(struct hvl_envelope));
        memset(&ht->ht_Voices[i].vc_VoiceBuffer,0,0x281);
        memset(&ht->ht_Voices[i].vc_RingVoiceBuffer,0,0x281);
      }

    Щито оно делает?

    Govnocoder#0xFF, 03 Февраля 2013

    Комментарии (12)
  7. Си / Говнокод #12469

    +133

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    #if __BYTE_ORDER == __BIG_ENDIAN
    struct DWstruct { Wtype high, low;};
    #elif __BYTE_ORDER == __LITTLE_ENDIAN
    struct DWstruct { Wtype low, high;};
    #else
    #error Unhandled endianity
    #endif

    glibc, sysdeps/wordsize-32/divdi3.c

    bormand, 24 Января 2013

    Комментарии (18)
  8. Си / Говнокод #12447

    +110

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    int strnlen(const char *s, int size)
    {
            int i;
            for(i=0; i<size; i++) if(!*s) break;
            return i;
    }

    tz-lom, 18 Января 2013

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

    +118

    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
    void dwflt_to_str(DWORD dw, char *pch, int &nsmb)
    {
      DWORD dw_a = dw;
      char ch_a;
      char tbldec[] = "0123456789";
      nsmb = 0;
      if (dw_a == 0) { pch[0] = '0'; nsmb++; goto lab2; }
      while (dw_a != 0)
      {
        pch[nsmb] = tbldec[dw_a%10]; dw_a /= 10; nsmb++;
      }
      dw_a = nsmb/2;
      while (dw_a)
      {
        ch_a = pch[nsmb - dw_a]; pch[nsmb - dw_a] = pch[dw_a - 1]; pch[dw_a - 1] = ch_a; dw_a--;
      }
    lab2:
      pch[nsmb] = 0;
    }
    
    const int n_fr2 = 7; // - эта константа определяет фиксированное число цифр после точки в выводимой строке, представляющей float.
    
    void float_to_str(float flt, char *pchar, int &nsmb)
    {
      int i, deg, ns_int, ns_frac;
      double frac_dbl;
      DWORD dw_f, mant, intg, fract;
      DW_FL f_flt;
      char szfl_int[16], szfl_frac[16];
      f_flt.fl = flt;
      dw_f = f_flt.dw;
      if (dw_f == 0) { pchar[0] = '0'; pchar[1] = '.'; pchar[2] = '0'; pchar[3] = 0; nsmb = 3; return; }
      if (dw_f & 0x80000000) { pchar[0] = '-'; } else { pchar[0] = '+'; }
      deg = int((dw_f & 0x7F800000) >> 23) - 127;
      mant = (dw_f & 0x007FFFFF) | 0x00800000;
      if (deg == 0) { intg = 1; fract = dw_f & 0x007FFFFF; goto lab_1; }
      if (deg > 0) { intg = mant >> (23 - deg); fract = ((dw_f & 0x007FFFFF) << deg) & 0x007FFFFF; goto lab_1; }
      if (deg < 0) { intg = 0; fract = ((dw_f & 0x007FFFFF) | 0x00800000) >> (-deg); }
    lab_1:
      frac_dbl = double(fract)*1.1920928955078125;// 1.1920928955078125 = 10^n_fr2 / 2^23 = 10^7 / 2^23
      fract = (int)frac_dbl;
    
      dwflt_to_str(intg, szfl_int, ns_int);
      nsmb = 1; i = ns_int; while (i) { pchar[i + 1] = szfl_int[i]; i--; } pchar[1] = szfl_int[0];
      nsmb += ns_int; pchar[nsmb] = '.'; nsmb++;
    
      dwflt_to_str(fract, szfl_frac, ns_frac); szfl_frac[n_fr2] = 0;
      i = ns_frac; while (i) { szfl_frac[6 - ns_frac + i] = szfl_frac[i - 1]; i--; }
      i = n_fr2 - ns_frac; while (i) { szfl_frac[i - 1] = '0'; i--; }
    
      i = n_fr2 - 1; while (i) { pchar[nsmb + i] = szfl_frac[i]; i--; } pchar[nsmb] = szfl_frac[0];
      nsmb += n_fr2; pchar[nsmb] = 0;
    }
    void float_to_str_exp(float flt, char *pchar, int &nsmb)
    {
      int i, deg, poli, ns_int, ns_frac, ns_poli;
      double frac_dbl;
      DWORD dw_f, mant, intg, fract;
      DW_FL f_flt;
      char szfl_int[16], szfl_frac[16];
      f_flt.fl = flt;
      dw_f = f_flt.dw;
      if (dw_f == 0) { pchar[0] = '0'; pchar[1] = '.'; pchar[2] = '0'; pchar[3] = 0; nsmb = 3; return; }
      if (dw_f & 0x80000000) { pchar[0] = '-'; } else { pchar[0] = '+'; }
      deg = int((dw_f & 0x7F800000) >> 23) - 127;
      mant = (dw_f & 0x007FFFFF) | 0x00800000;
      if (deg == 0) { intg = 1; fract = dw_f & 0x007FFFFF; goto lab_1; }
      if (deg > 0) { intg = mant >> (23 - deg); fract = ((dw_f & 0x007FFFFF) << deg) & 0x007FFFFF; goto lab_1; }
      if (deg < 0) { intg = 0; fract = ((dw_f & 0x007FFFFF) | 0x00800000) >> (-deg); }
    lab_1:
      frac_dbl = double(fract)*1.1920928955078125;// 1.1920928955078125 = 10^n_fr2 / 2^23 = 10^7 / 2^23
      fract = (int)frac_dbl;
    
      dwflt_to_str(intg, szfl_int, ns_int);
      dwflt_to_str(fract, szfl_frac, ns_frac); szfl_frac[n_fr2] = 0;
      if (intg != 0)
      {
        nsmb = 1; i = ns_int; while (i) { pchar[i + 2] = szfl_int[i]; i--; } pchar[1] = szfl_int[0];
        pchar[2] = '.'; nsmb += ns_int + 1; poli = ns_int - 1;
      }
      else
      {
        i = ns_frac - 1; while (i) { pchar[2 + i] = szfl_frac[i]; i--; } pchar[1] = szfl_frac[0];
        pchar[2] = '.'; nsmb = 3;//nsmb += ns_frac + 1;
        poli = ns_frac - n_fr2 - 1; goto lab_2;
      }
    
      i = ns_frac; while (i) { szfl_frac[6 - ns_frac + i] = szfl_frac[i - 1]; i--; }
      i = n_fr2 - ns_frac; while (i) { szfl_frac[i - 1] = '0'; i--; }
    
      i = n_fr2 - 1; while (i) { pchar[nsmb + i] = szfl_frac[i]; i--; } pchar[nsmb] = szfl_frac[0];
    lab_2:
      nsmb += n_fr2; pchar[nsmb] = 'E';
    
      int_to_str(poli, &pchar[nsmb + 1], ns_poli);
      nsmb += ns_poli + 1; pchar[nsmb] = 0;
    }

    оттуда

    TarasB, 15 Января 2013

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

    +129

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    static int multipart_buffer_eof(multipart_buffer *self TSRMLS_DC)
    {
    	if ( (self->bytes_in_buffer == 0 && fill_buffer(self TSRMLS_CC) < 1) ) {
    		return 1;
    	} else {
    		return 0;
    	}
    }

    nyaknyan, 05 Января 2013

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