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

    +141

    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
    const char *pS;
    		char *pD;
    
    		// clear out new string
    		szNew[0] = '\0';
    
    		pS = pszValue;
    		pD = szNew;
    
    		// step through the string, only copying back in characters that are printable
    		while( *pS )
    		{
    			if( ((byte)*pS) < 32 || ((byte)*pS) > 255 )
    			{
    				pS++;
    				continue;
    			}
    			*pD++ = *pS++;
    		}
    
    		// terminate the new string
    		*pD = '\0';

    Мало того, char в проекте подразумевается signed

    mittorn, 12 Мая 2015

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

    +143

    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
    if(!$user['email']) {
         $err = $this->system_message->getLang('empty_email');
    } elseif(strlen($user['email']) < self::MIN_USER_NAME) {
          $err = $this->system_message->getLang('small_email');
    } elseif(strlen($user['email']) > self::MAX_USER_NAME) {
          $err = $this->system_message->getLang('long_email');
    } elseif(!filter_var($user['email'], FILTER_VALIDATE_EMAIL)) {
          $err = $this->system_message->getLang('incorrect_name');
    } 
    
    if(!$user['passw']) {
          $err = $this->system_message->getLang('empty_passw');
    } elseif(strlen($user['passw']) < self::MIN_PASSWORD_NAME) {
          $err = $this->system_message->getLang('small_passw');
    } elseif(strlen($user['passw']) > self::MAX_PASSWORD_NAME) {
          $err = $this->system_message->getLang('long_passw');
    }
    if($err) {
       //!TODO add a exeption
    		
    } else {
          $find_email = $this->db_users->prepare("SELECT * FROM `users` WHERE `email` = :email");
          $find_email->execute(array(':email' => $user['email']));

    Мдэээ...

    Dev_18, 12 Мая 2015

    Комментарии (13)
  3. PHP / Говнокод #18155

    +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
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    <?php
    /**
      * @desc Локализация сайта
      *
      **/
    class System_Message{
      private function openLangFail($lang){
        $path = '/../message/'.$lang.'.php';
        if (file_exists($path)) {
          return 'File with languages not found';
        } else {
          return include $path; 
        }
      } 
      
      public function getLang($value, $lang='ru'){
        $lang = self::openLangFail($lang);
        if($lang[$value] != '') {
          return $lang[$value];
        } else {
    	  return false;
    	}
      }
    }

    Ну как?

    Dev_18, 12 Мая 2015

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

    +143

    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
    public enum WebViewImageType {
    	Back = 0,
    	Close = 1,
    	Menu = 2
    }		
    
    WebViewImageType GetImageType(int jsType){ 
    	switch (jsType) {
    		case 0:
    			return WebViewImageType.Back;
    		case 1:
    			return WebViewImageType.Close;
    		case 2:
    			return WebViewImageType.Menu;
    		default:
    			return WebViewImageType.Back;
    	}
    }

    kjuby8709gsome, 12 Мая 2015

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

    +48

    1. 1
    auto filename = std::string{};

    laMer007, 12 Мая 2015

    Комментарии (157)
  6. PHP / Говнокод #18152

    +165

    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
    // Whoever introduced xml to shipping companies should be flogged
    $xml  = '<?xml version="1.0"?>';
    $xml .= '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://fedex.com/ws/rate/v10">';
    $xml .= '	<SOAP-ENV:Body>';
    $xml .= '		<ns1:RateRequest>';
    $xml .= '			<ns1:WebAuthenticationDetail>';
    
    // почти сотня строк
    
    $xml .= '</SOAP-ENV:Envelope>';
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $xml);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HEADER, false);
    curl_setopt($curl, CURLOPT_TIMEOUT, 30);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

    Смотри-ка, оно еще и ругается

    https://github.com/opencart/opencart/blob/58eeb544e2eddbe18b00224e10d2761259e8ce7b/upload/catalog/model/shipping/fedex.php#L48

    Fike, 12 Мая 2015

    Комментарии (77)
  7. JavaScript / Говнокод #18151

    +145

    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
    var errorFirst = true;
    		var errorSec   = true;
    		
    		if(errFirstV!==false && errFirstN!==false){
    			errorFirst=true;
    		}
    		else if (errFirstV===false && errFirstN!==false) {
    			
    			errorFirst=false;
    			
    		}
    		else if (errFirstV===false && errFirstN===false) {
    			
    			errorFirst=false;
    			
    		}
    		else if (errFirstV!==false && errFirstN===false) {
    			
    			errorFirst=false;
    			
    		}
    		
    		
    		if(errFirstT!==false && errFirstE!==false){
    		
    			errorSec=true;
    		}
    		else if(errFirstT===false && errFirstE!==false){
    		
    			errorSec=false;
    		}
    		else if(errFirstT===false && errFirstE===false){
    		
    			errorSec=false;
    		}
    		else if(errFirstT!==false && errFirstE===false){
    		
    			errorSec=false;
    		}
    		
    		// check both lines
    		
    		if (errorFirst !==true && errorSec !== true) {
    			error=false;
    		}

    ЭТО шЭдэвр!!!!

    armengabriel, 12 Мая 2015

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

    +142

    1. 1
    Как-то долго на PHP говнокода не появляется, все научились писать что ли?

    proweber1, 12 Мая 2015

    Комментарии (14)
  9. PHP / Говнокод #18149

    +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
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    public function api() {
    	...
    	if ($this->validate()) {
    		if ($store_info) {
    			$url = $store_info['ssl'];
    		} else {
    			$url = HTTPS_CATALOG;
    		}
    		if (isset($this->session->data['cookie']) && isset($this->request->get['api'])) {
    			...
    			$curl = curl_init();
    			// Set SSL if required
    			if (substr($url, 0, 5) == 'https') {
    				curl_setopt($curl, CURLOPT_PORT, 443);
    			}
    			curl_setopt($curl, CURLOPT_HEADER, false);
    			curl_setopt($curl, CURLINFO_HEADER_OUT, true);
    			curl_setopt($curl, CURLOPT_USERAGENT, $this->request->server['HTTP_USER_AGENT']);
    			curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    			curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    			curl_setopt($curl, CURLOPT_FORBID_REUSE, false);
    			curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    			curl_setopt($curl, CURLOPT_URL, $url . 'index.php?route=' . $this->request->get['api'] . ($url_data ? '&' . http_build_query($url_data) : ''));
    			if ($this->request->post) {
    				curl_setopt($curl, CURLOPT_POST, true);
    				curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($this->request->post));
    			}
    			curl_setopt($curl, CURLOPT_COOKIE, session_name() . '=' . $this->session->data['cookie'] . ';');
    			$json = curl_exec($curl);
    			curl_close($curl);

    API в опенкарте. Ну, короч, приходит пользователь, дергает АПИ, а я сам в контроллере дергаю свое АПИ. Такая практика.

    https://github.com/opencart/opencart/blob/4a151334efc702729071bd8d45a7e4af4e07b3ef/upload/admin/controller/sale/order.php#L2152

    Fike, 12 Мая 2015

    Комментарии (2)
  10. Python / Говнокод #18148

    −119

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    import inspect
    
    def phpformat(fmt):
        return fmt.format(**inspect.getouterframes(inspect.currentframe())[1][0].f_locals)
    
    surname = "Бонд"
    name = "Джеймс"
    num = 7
    print(phpformat("{surname}. {name} {surname}. Агент {num:03d}."))

    PHP'шная интерполяция строк теперь и в питоне.

    Родилось в http://govnokod.ru/18147#comment285697

    bormand, 11 Мая 2015

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