1. Assembler / Говнокод #11531

    +138

    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
    .text:00018584                 EXPORT get_msg_sequence
    .text:00018584 get_msg_sequence                        ; CODE XREF: IPC_send_singleIPC+6p
    .text:00018584                                         ; __IPC_send_singleIPC+6p
    .text:00018584                 LDR             R0, =0x7800C
    .text:00018586                 PUSH            {R4,LR}
    .text:00018588                 ADD             R0, PC
    .text:0001858A                 LDR             R0, [R0]
    .text:0001858C                 LDRB            R3, [R0]
    .text:0001858E                 CBZ             R3, loc_185A2
    .text:00018590                 LDR             R1, =(aRil - 0x1859C)
    .text:00018592                 MOVS            R0, #6
    .text:00018594                 LDR             R2, =(aS_0 - 0x1859E)
    .text:00018596                 LDR             R3, =(aGet_msg_sequen - 0x185A0)
    .text:00018598                 ADD             R1, PC  ; "RIL"
    .text:0001859A                 ADD             R2, PC  ; "%s()"
    .text:0001859C                 ADD             R3, PC  ; "get_msg_sequence"
    .text:0001859E                 BLX             __android_log_print
    .text:000185A2
    .text:000185A2 loc_185A2                               ; CODE XREF: get_msg_sequence+Aj
    .text:000185A2                 LDR             R3, =(unk_98E7E - 0x185A8)
    .text:000185A4                 ADD             R3, PC
    .text:000185A6                 LDRB            R2, [R3]
    .text:000185A8                 CMP             R2, #0xFD
    .text:000185AA                 BLS             loc_185B0
    .text:000185AC                 MOVS            R2, #0
    .text:000185AE                 B               loc_185B2
    .text:000185B0 ; ---------------------------------------------------------------------------
    .text:000185B0
    .text:000185B0 loc_185B0                               ; CODE XREF: get_msg_sequence+26j
    .text:000185B0                 ADDS            R2, #1
    .text:000185B2
    .text:000185B2 loc_185B2                               ; CODE XREF: get_msg_sequence+2Aj
    .text:000185B2                 LDR             R1, =(unk_98E7E - 0x185BA)
    .text:000185B4                 STRB            R2, [R3]
    .text:000185B6                 ADD             R1, PC
    .text:000185B8                 LDRB            R0, [R1]
    .text:000185BA                 POP             {R4,PC}
    .text:000185BA ; End of function get_msg_sequence

    Потрясающе эффективный выхлоп GCC. Компилировалось, вероятно, все-таки с включенной оптимизацией.

    Например, последовательность LDR R1/ADD R1,PC/LDRB R0, [R1] в конце вообще лишняя: достаточно было использовать R0 вместо R2.

    Grindars, 04 Августа 2012

    Комментарии (8)
  2. PHP / Говнокод #11530

    +59

    1. 1
    if ( (is_file($filename) == true) == true)

    MaxSvargal, 04 Августа 2012

    Комментарии (14)
  3. Куча / Говнокод #11529

    +125

    1. 1
    2. 2
    3. 3
    Сайт оптимизирован под 
    браузер GooGle Chrome
    Разрешение: 1280х1024

    http://anidream.net/

    zim, 04 Августа 2012

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

    +12

    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
    void EllipticPoint::Add(const EllipticPoint &b, const EllipticCoord &a, const EllipticCoord &p, EllipticPoint &res) {
        if (!x.IsNotZero() && !y.IsNotZero()) {
            res = b;
        } else if (!b.x.IsNotZero() && !b.y.IsNotZero()) {
            res = *this;
        } else if (x.Compare(b.x)!=0) {
            EllipticCoord tmp1, tmp2, lambda;
            b.x.Sub(x,p,tmp1); tmp1.Invert(p,tmp2);
            b.y.Sub(y,p,tmp1); tmp1.Mul(tmp2,p,lambda);
            lambda.Mul(lambda,p,tmp1);
            tmp1.Sub(x,p,tmp2); tmp2.Sub(b.x,p,res.x);
            x.Sub(res.x,p,tmp1); lambda.Mul(tmp1,p,tmp2); tmp2.Sub(y,p,res.y);
        } else if (y.Compare(b.y)==0) {
            EllipticCoord tmp1, tmp2, tmp3, lambda;
            x.Mul(x,p,tmp1); tmp1.Add(tmp1,p,tmp3); tmp1.Add(tmp3,p,tmp2); tmp2.Add(a,p,tmp1);
            y.Add(y,p,tmp2); tmp2.Invert(p,tmp3); tmp1.Mul(tmp3,p,lambda);
            lambda.Mul(lambda,p,tmp1); tmp1.Sub(x,p,tmp2); tmp2.Sub(x,p,res.x);
            x.Sub(res.x,p,tmp1); lambda.Mul(tmp1,p,tmp3); tmp3.Sub(y,p,res.y);
        } else {
            res.x.SetZero();
            res.y.SetZero();
        }
    }

    Из моего велосипеда четырехлетней давности.
    Кусочек реализации ГОСТ Р 34.10-2001.

    bormand, 03 Августа 2012

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

    +142

    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
    while (true)
    {
        try
        {
            ProductService.Invoke(method);
            return; 
        }
        catch(Exception ex)
        {
            if (ex is System.ServiceModel.CommunicationException)
            {
                if (currentRetryCount == RetryCount)
                        throw new CommunicationException(CommunicationFailureMessage, ex);
                    System.Threading.Thread.Sleep(RetryWait);
                    currentRetryCount++;
            }
        }
    }

    abatishchev, 03 Августа 2012

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

    +148

    1. 1
    2. 2
    3. 3
    4. 4
    $("#select_id :selected").attr("selected", false);
    $("#select_id option[value='" + new_value + "']").attr("selected", true);
    вместо
    $("#select_id").val(new_value);

    splinter89, 03 Августа 2012

    Комментарии (4)
  7. PHP / Говнокод #11525

    +56

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    $cur_url=$_SERVER['REQUEST_URI'];
    if ($cur_url=='/') { 
    	$cur_url=$_SERVER['REQUEST_URI']; 
    	if ($cur_url=='/') { // Точно-точно адрес не равен слэшу
    		echo '';// После всех проверок можно с уверенностью вывести пустую строку
    	}
    }
    $cur_url2=$_SERVER['REQUEST_URI'];// И ещё разок
    if ($cur_url2!='/') { 
    	echo '';
    }

    Из движка одного московского портала, директор которого пытается нас убедить что там нормальный код

    RedMonkey, 03 Августа 2012

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

    +140

    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
    FileInfo file = new FileInfo(fileName);
    FileSecurity fSecurity = File.GetAccessControl(fileName);
    
    foreach (FileSystemAccessRule permissions in fSecurity.GetAccessRules(true, true, typeof(NTAccount)))
    {
         string login = permissions.IdentityReference.Translate(typeof(NTAccount)).Value.ToString();
         string permiss =  permissions.FileSystemRights.ToString();
    
         if ((login != "логин") && (login != "логин") && (login != "логин"))
         {
             fSecurity.SetAccessRuleProtection(true, false);
             fSecurity.RemoveAccessRule(new FileSystemAccessRule(login, permissions.FileSystemRights, AccessControlType.Allow));
         }
         fSecurity.AddAccessRule(new FileSystemAccessRule("логин", FileSystemRights.FullControl, AccessControlType.Allow));
         fSecurity.AddAccessRule(new FileSystemAccessRule("логин", FileSystemRights.FullControl, AccessControlType.Allow));
    
    }
    File.SetAccessControl(fileName, fSecurity);

    vertu, 03 Августа 2012

    Комментарии (11)
  9. Java / Говнокод #11523

    +90

    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
    public enum TimeUnit {
       NANOSECONDS {
            public long toNanos(long d)   { return d; }
            public long toMicros(long d)  { return d/(C1/C0); }
            public long toMillis(long d)  { return d/(C2/C0); }
            public long toSeconds(long d) { return d/(C3/C0); }
            public long toMinutes(long d) { return d/(C4/C0); }
            public long toHours(long d)   { return d/(C5/C0); }
            public long toDays(long d)    { return d/(C6/C0); }
            public long convert(long d, TimeUnit u) { return u.toNanos(d); }
            int excessNanos(long d, long m) { return (int)(d - (m*C2)); }
        }
    ....
        public long convert(long sourceDuration, TimeUnit sourceUnit) {
            throw new AbstractMethodError();
        }
    
     
        public long toNanos(long duration) {
            throw new AbstractMethodError();
        }
    
      
        public long toMicros(long duration) {
            throw new AbstractMethodError();
        }
    
        public long toMillis(long duration) {
            throw new AbstractMethodError();
        }
    
     
        public long toSeconds(long duration) {
            throw new AbstractMethodError();
        }
    
      
        public long toMinutes(long duration) {
            throw new AbstractMethodError();
        }
    
      
        public long toHours(long duration) {
            throw new AbstractMethodError();
        }
    
     
        public long toDays(long duration) {
            throw new AbstractMethodError();
        }
    
      
        abstract int excessNanos(long d, long m);
    }

    Но зачем?

    3.14159265, 02 Августа 2012

    Комментарии (61)
  10. ActionScript / Говнокод #11522

    −92

    1. 1
    2. 2
    3. 3
    public function xor(lhs:Boolean, rhs:Boolean):Boolean {
     return !( lhs && rhs ) && ( lhs || rhs );
    }

    Из http://as3snippets.blogspot.com/2010/09/logical-xor.html

    Как известно, в AS3 есть численный оператор XOR ^, а вот для логических значений ^^ нет. Поэтому ребята придумали такую конструкцию (и ещё вариант return Boolean(int(a) ^ int(b)); в комментах), и только через год какой-то чувак догадался что XOR для логических значений всё-таки есть и называется !=

    makc3d, 02 Августа 2012

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