- 1
- 2
- 3
- 4
- 5
- 6
std::uint8_t octets[4];
for(int i = 0; i < 4; ++i) {
if(i != 0 && inp.get() != '.')
{ assert(false && "unexpected symbol"); }
inp >> octets[i];
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+56
std::uint8_t octets[4];
for(int i = 0; i < 4; ++i) {
if(i != 0 && inp.get() != '.')
{ assert(false && "unexpected symbol"); }
inp >> octets[i];
}
Два вида говна: в коде и в языке.
+133
if (*wpPat == L'\\')
{
wpCharStart=wpPat;
if (++wpPat >= wpMaxPat) goto Error;
if (*wpPat == L'x')
{
if (++wpPat >= wpMaxPat) goto Error;
if (*wpPat == L'{')
{
wpStrTmp=++wpPat;
for (;;)
{
if (wpPat >= wpMaxPat) goto Error;
if (*wpPat++ == L'}') break;
}
if (lpREGroupItem->nGroupLen != -1 && !bClassOpen)
{
nPatChar=(int)hex2decW(wpStrTmp, (wpPat - 1) - wpStrTmp);
if (nPatChar == -1)
{
wpPat=wpStrTmp;
goto Error;
}
if (nPatChar <= MAXWORD)
lpREGroupItem->nGroupLen+=1;
else
lpREGroupItem->nGroupLen+=2;
}
}
else
{
if (wpPat + 2 > wpMaxPat)
goto Error;
wpPat+=2;
if (lpREGroupItem->nGroupLen != -1 && !bClassOpen)
++lpREGroupItem->nGroupLen;
}
}
else if (*wpPat == L'u')
{
if (wpPat + 5 > wpMaxPat)
goto Error;
wpPat+=5;
if (lpREGroupItem->nGroupLen != -1 && !bClassOpen)
++lpREGroupItem->nGroupLen;
}
Регулярные велосипеды.
Akelpad.
+134
//// AEM_* AkelEdit control messages
if (uMsg >= WM_USER)
{
if (uMsg >= AEM_CANUNDO)
goto CanUndo;
//Text retrieval and modification
if (uMsg == AEM_EXSETTEXTA)
{
AESETTEXTA *at=(AESETTEXTA *)lParam;
return AE_SetTextAnsi(ae, at->nCodePage, at->pText, at->dwTextLen, at->nNewLine);
}
if (uMsg == AEM_EXSETTEXTW)
{
AESETTEXTW *at=(AESETTEXTW *)lParam;
return AE_SetText(ae, at->pText, at->dwTextLen, at->nNewLine, FALSE);
}
if (uMsg == AEM_SETTEXTA)
{
return AE_SetTextAnsi(ae, CP_ACP, (char *)lParam, wParam, AELB_ASINPUT);
}
if (uMsg == AEM_SETTEXTW)
{
return AE_SetText(ae, (wchar_t *)lParam, wParam, AELB_ASINPUT, FALSE);
}
if (uMsg == AEM_APPENDTEXTA)
{
AEAPPENDTEXTA *at=(AEAPPENDTEXTA *)lParam;
AE_AppendTextAnsi(ae, at->nCodePage, at->pText, at->dwTextLen, at->nNewLine);
return 0;
}
if (uMsg == AEM_APPENDTEXTW)
{
AEAPPENDTEXTW *at=(AEAPPENDTEXTW *)lParam;
AE_AppendText(ae, at->pText, at->dwTextLen, at->nNewLine);
return 0;
}
if (uMsg == AEM_REPLACESELA)
{
AEREPLACESELA *rs=(AEREPLACESELA *)lParam;
AE_ReplaceSelAnsi(ae, rs->nCodePage, rs->pText, rs->dwTextLen, rs->nNewLine, rs->dwFlags, rs->ciInsertStart, rs->ciInsertEnd);
return 0;
}
if (uMsg == AEM_REPLACESELW)
{
AEREPLACESELW *rs=(AEREPLACESELW *)lParam;
AE_ReplaceSel(ae, rs->pText, rs->dwTextLen, rs->nNewLine, rs->dwFlags, rs->ciInsertStart, rs->ciInsertEnd);
return 0;
}
if (uMsg == AEM_GETTEXTRANGEA)
{
AETEXTRANGEA *tr=(AETEXTRANGEA *)lParam;
return AE_GetTextRangeAnsi(ae, tr->nCodePage, tr->lpDefaultChar, tr->lpUsedDefChar, &tr->cr.ciMin, &tr->cr.ciMax, tr->pBuffer, tr->dwBufferMax, tr->nNewLine, tr->bColumnSel, tr->bFillSpaces);
}
И далее около сотни if'ов в таком духе.
AkelPad
+88
function TCalc.getRewardItems(items : AnsiString; countItems : integer; userId : Integer; from:integer) : ISuperObject;
var tmpFirstOdds : integer;
strLines, extrLines : TStringList;
strItems, strOdds, strOdds2: TIntegerList;
i, j, tmpCountItems : integer;
tmpOddsItems, sum : Integer;
str: ansistring;
begin
Result := nil;
// parse items line [id1,odd1],[id2,odd2],[id3,odd3]
strLines := TStringList.Create;
extrLines := TStringList.Create;
strItems := TIntegerList.Create;
strOdds := TIntegerList.Create;
ExtractStrings(['[', ']'],[','], PChar(items), strLines);
for i := 0 to strLines.Count - 1 do
begin
ExtractStrings([','],[' '], PChar(strLines[i]), extrLines);
strItems.Add(StrToInt(extrLines[0]));
strOdds.Add(StrToInt(extrLines[1]));
extrLines.Clear;
end;
// calculate odds [a,b,c,d] as [a,a+b,a+b+c,a+b+c+d]
sum := 0;
strOdds2 := TIntegerList.Create;
for i := 0 to strOdds.Count-1 do
begin
sum := sum + strOdds.Items[i];
strOdds2.Add(sum);
end;
// select items
str := '';
for i := 0 to countItems - 1 do
begin
tmpFirstOdds := Random(101); // 0-100
for j := 0 to strOdds2.Count-1 do
begin
if tmpFirstOdds < strOdds2.Items[j] then
begin
str := str + IntToStr(strItems[j]) + ',';
break;
end;
end;
end;
str := '['+Copy(str,1,Length(str)-1)+']';
// from monster
if from=0 then Result := so('{"part":"battle","func":"itemsdropped","data":'+str+'}');
// from chest
if from=1 then Result := so('{"part":"battle","func":"itemsdroppedchest","data":'+str+'}');
strLines.Free;
extrLines.Free;
strItems.Free;
strOdds.Free;
strOdds2.Free;
end;
У меня чуть глаза не вытекли от такого решения. Код по идее сообщает клиенту, что выпало из монстра после победы над ним.
+135
public void ValidateValue( ref object value ) {
bool b;
if ( value == null ) return;
var typeName = BaseType.Name;
var valueType = value.GetType();
if ( valueType.Name == "String" ) {
if ( BaseType == valueType ) return;
if ( BaseType == Constants.Types.Boolean ) {
if ( string.Compare( "yes", (string) value, StringComparison.OrdinalIgnoreCase ) == 0 ) value = true;
else if ( string.Compare( "no", (string) value, StringComparison.OrdinalIgnoreCase ) == 0 ) value = false;
#if !CF
else if ( Boolean.TryParse( value.ToString(), out b ) ) value = b;
#else
else if (TryParseUtility.TryParse(value.ToString(), out b)) value = b;
#endif
else throw new ArgumentException( String.Format( Resources.ValueNotCorrectType, value ) );
return;
}
}
#if !CF
if ( typeName == "Boolean"
&& Boolean.TryParse( value.ToString(), out b ) ) {
value = b;
return;
}
UInt64 uintVal;
if ( typeName.StartsWith( "UInt64" )
&& UInt64.TryParse( value.ToString(), out uintVal ) ) {
value = uintVal;
return;
}
UInt32 uintVal32;
if ( typeName.StartsWith( "UInt32" )
&& UInt32.TryParse( value.ToString(), out uintVal32 ) ) {
value = uintVal32;
return;
}
long intVal;
if ( typeName.StartsWith( "long" )
&& long.TryParse( value.ToString(), out intVal ) ) {
value = intVal;
return;
}
int intVal32;
if ( typeName.StartsWith( "Int32" )
&& Int32.TryParse( value.ToString(), out intVal32 ) ) {
value = intVal32;
return;
}
#else
if (typeName == "Boolean" && TryParseUtility.TryParse(value.ToString(), out b)) { value = b; return; }
UInt64 uintVal;
if (typeName.StartsWith("UInt64") && TryParseUtility.TryParse(value.ToString(), out uintVal)) { value = uintVal; return; }
UInt32 uintVal32;
if (typeName.StartsWith("UInt32") && TryParseUtility.TryParse(value.ToString(), out uintVal32)) { value = uintVal32; return; }
long intVal;
if (typeName.StartsWith("long") && TryParseUtility.TryParse(value.ToString(), out intVal)) { value = intVal; return; }
Int32 intVal32;
if (typeName.StartsWith("Int32") && TryParseUtility.TryParse(value.ToString(), out intVal32)) { value = intVal32; return; }
#endif
object objValue;
#if RT
Type baseType = BaseType.GetTypeInfo().BaseType;
#else
var baseType = BaseType.BaseType;
#endif
if ( baseType != null
&& baseType.Name == "Enum"
&& ParseEnum( value.ToString(), out objValue ) ) {
value = objValue;
return;
}
throw new ArgumentException( String.Format( Resources.ValueNotCorrectType, value ) );
}
MySql.Data 6.9.5, MySqlConnectionStringBuilder.cs
+51
std::list<COptions *> COptions::m_InstanceList;
..........
COptions::COptions()
{
for (int i = 0; i < OPTIONS_NUM; ++i)
m_OptionsCache[i].bCached = FALSE;
m_pOptionsHelperWindow = new COptionsHelperWindow(this);
simple_lock lock(m_mutex);
#ifdef _DEBUG
for (std::list<COptions *>::iterator iter=m_InstanceList.begin(); iter != m_InstanceList.end(); ++iter)
ASSERT(*iter != this);
#endif _DEBUG
m_InstanceList.push_back(this);
m_SpeedLimits[0] = m_sSpeedLimits[0];
m_SpeedLimits[1] = m_sSpeedLimits[1];
}
COptions::~COptions()
{
{
simple_lock lock(m_mutex);
std::list<COptions *>::iterator iter;
for (iter=m_InstanceList.begin(); iter != m_InstanceList.end(); ++iter) {
if (*iter == this)
break;
}
ASSERT(iter != m_InstanceList.end());
if (iter != m_InstanceList.end())
m_InstanceList.erase(iter);
}
if (m_pOptionsHelperWindow)
delete m_pOptionsHelperWindow;
m_pOptionsHelperWindow=0;
}
.......
В отладке включается тяжелый героиновый бред разработчиков FileZilla
+49
void ZModulesDlg::OnDestroy(HWND hwnd)
{
LVITEM lvi = { LVIF_PARAM };
if (lvi.iItem = ListView_GetItemCount(hwnd))
{
do
{
lvi.iItem--;
if (ListView_GetItem(hwnd, &lvi))
{
((ZDll*)lvi.lParam)->Release();
}
} while (lvi.iItem);
}
}
+156
// Real itemid is "contained" in public itemid in a bit tricky way. The formula is:
public_itemid = itemid * 256 + anum
// Quite easy, isn't it? Except where to get that anum. anum is some number assigned when you create a new post in LJ.
// But in fact, you don't need it. Because it is always less than 256, we can avoid searching for it, and just use simple Math to find itemid.
$anum = $public_itemid - floor($public_itemid / 256) * 256;
$itemid = ($public_itemid - $anum) / 256;
Прекрасный подход, то место, где вордпресс и ЖЖ сошлись воедино.
http://drumrock.skipitnow.org/livejournal-tools/itemid/
−106
qdev_id, iops = _update_device_iops(instance, device_for_change)
try:
qemu.volumes.set_io_throttle(controller.qemu(), qdev_id, iops)
except Exception as e:
# Check if we turn off this instance? just a moment ago.
if "'NoneType' object has no attribute 'connected'" in e:
LOG.warning("kemu process seems to be killed")
else:
raise
Метод set_io_throttle не бросает exception.
Мы так проверяем,есть ли connection к qemu или нет.
+126
.cat_mid a{
color: #ffa10e !important;
}
.cat_mid {
padding: 0 10px;
display: inline-block;
font-family: georgia, "times new roman", times, serif;
font-weight: normal;
font-size: 14px;
height: 64px !important;
overflow: hidden;
margin-bottom: -3px !important;
padding: 10px 10px 0;
}
.cat_hid {
color: #bc843f;
padding: 0 10px;
text-align: left;
z-index: 100;
position: relative;
display: none;
}
.cat_hid.not{
display: block !important;
padding: 8px 10px 19px;
}
.cat_hid.not.price{
height: 25px;
padding: 12px 10px 17px;
}
css