Funniest code snippet ever! Must See!

Page 2 - Seeking answers? Join the AnandTech community: where nearly half-a-million members share solutions and discuss the latest tech.

UNCjigga

Lifer
Dec 12, 2000
25,594
10,293
136
wait, I thought the text-entry string was a text-type field and this guy's trying to change it to a numeric field. Doesn't look dumb if that's the case...though it would be easier to define the select variable as a number! Bah, I never got past high school coding meself really...
 

bunker

Lifer
Apr 23, 2001
10,572
0
71
Originally posted by: jumpr
Originally posted by: notfred
Originally posted by: jumpr
I've only taken elementary C++, so I might not know what I'm talking about, but do you need 'break' statments when writing a case statement also?

It's ASP code, not C++ did you read the first post?
Right, I know. But I was wondering if ASP uses break statements just like C++. So you didn't really answer my question. :p

You can use a break in ASP, but it's not required.
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
Originally posted by: notfred
Originally posted by: jumpr
I've only taken elementary C++, so I might not know what I'm talking about, but do you need 'break' statments when writing a case statement also?

It's ASP code, not C++ did you read the first post?

To be pedantic, ASP isn't a language ;)

He's reassigning the variable to the integer literal as opposed to the string as VBScript has no data type other than a variant (VT_VARIANT). The string literal "1" is of variant type VT_BSTR, and the integer literal 1 is of variant type VT_INT. I guess he thought they were incompatible and thus used the explicit assignment.

Either way, it's completely idiotic because there's no need for conversion between either variant types, and even if there were he could've used CInt(). Btw, thanks for remining me why I dislke VBScript so much.
 

conjur

No Lifer
Jun 7, 2001
58,686
3
0
Originally posted by: Viper GTS
Originally posted by: notfred
Originally posted by: gigapet
someone explain the humor

It's the equivelant of:

If this number is 1, make this number be 1.
If this number is 2, make this number be 2.
...
Up through 9...

It's worse than that, they're reassigning the value to the SAME VARIABLE.

Viper GTS

Well...converting from a string var to a numeric.

Oh wait...is this script? It's all variant anyway.

That's just teh l4m3!
 

Mucman

Diamond Member
Oct 10, 1999
7,246
1
0
For the people that don't get it... the code is completely redundant... I could remove it from their code and I wouldn't affect the "logic" (who knows how logical their code is after seeing this) and it wouldn't change a thing.

think of it as IF statements

if ( x == 1) { x = 1; } for the C crowd.
 

manly

Lifer
Jan 25, 2000
13,306
4,084
136
Originally posted by: Electric Amish
Originally posted by: manly
Nah, that isn't funny besides the laughing at someone elses's stupidity.

Since I don't know VB, is that actually completely redundant, or is it essentially converting a string to an integer?

It's a case statement. They're the same function in all languages that support it, only the syntax may be a little different.
Bah, you had to quote my pre-edited reply. ;P

I know how a case statement works, but what I initially missed was the variable being switched on is the same one being assigned to. So my question isn't relevant.

However, what I was asking is if this VB snippet was a dumb man's equivalent of C's atoi function.
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
Originally posted by: Descartes
Originally posted by: notfred
Originally posted by: jumpr
I've only taken elementary C++, so I might not know what I'm talking about, but do you need 'break' statments when writing a case statement also?

It's ASP code, not C++ did you read the first post?

To be pedantic, ASP isn't a language ;)

I didn't say it was.
 

Mucman

Diamond Member
Oct 10, 1999
7,246
1
0
Oh... and the developer is a girl... she sounds quite cute on the phone too :). Unfortunately, with this kind of coding, I'll have to pass ;)
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
Originally posted by: notfred
Originally posted by: jumpr
Originally posted by: notfred
Originally posted by: jumpr
I've only taken elementary C++, so I might not know what I'm talking about, but do you need 'break' statments when writing a case statement also?

It's ASP code, not C++ did you read the first post?
Right, I know. But I was wondering if ASP uses break statements just like C++. So you didn't really answer my question. :p

Apparently not, since the code runs.

break statements aren't required in C or C++; in fact, it's quite helpful to fall through various case statements. e.g.:

switch (msg)
{
case WM_CLOSE:
case WM_DESTROY:
// handle both the same
}

Unfortunately most newer languages with syntactically similar switch constructs require an explicit break :disgust:
 

skace

Lifer
Jan 23, 2001
14,488
7
81
But what I don't understand is... if that code works, why is it consuming all the CPU and RAM? That sounds more like an infinite loop. Does that case statement create some sort of infinite loop in the context that it is used?
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
Originally posted by: notfred
Originally posted by: Descartes
Originally posted by: notfred
Originally posted by: jumpr
I've only taken elementary C++, so I might not know what I'm talking about, but do you need 'break' statments when writing a case statement also?

It's ASP code, not C++ did you read the first post?

To be pedantic, ASP isn't a language ;)

I didn't say it was.

"ASP code"

ASP has no code.
 

Mucman

Diamond Member
Oct 10, 1999
7,246
1
0
Originally posted by: skace
But what I don't understand is... if that code works, why is it consuming all the CPU and RAM? That sounds more like an infinite loop. Does that case statement create some sort of infinite loop in the context that it is used?

That's not the code that's breaking the server... What's breaking the server is mostly like some bad DB code ie :

On Error Resume Next

While not rs.EOF
'notice the lack of rs.MoveNext
Loop

 

conjur

No Lifer
Jun 7, 2001
58,686
3
0
Originally posted by: skace
But what I don't understand is... if that code works, why is it consuming all the CPU and RAM? That sounds more like an infinite loop. Does that case statement create some sort of infinite loop in the context that it is used?

He just found that code in the .asp file.
 

Electric Amish

Elite Member
Oct 11, 1999
23,578
1
0
Originally posted by: skace
But what I don't understand is... if that code works, why is it consuming all the CPU and RAM? That sounds more like an infinite loop. Does that case statement create some sort of infinite loop in the context that it is used?

I don't think that code broke the site. I think this is just a humorous aside.

amish
 

Viper GTS

Lifer
Oct 13, 1999
38,107
433
136
Originally posted by: skace
But what I don't understand is... if that code works, why is it consuming all the CPU and RAM? That sounds more like an infinite loop. Does that case statement create some sort of infinite loop in the context that it is used?

It's not, it's just something he stumbled across in the course of his troubleshooting. If this kind of stuff is in there god only knows what else is there.

Viper GTS
 

manly

Lifer
Jan 25, 2000
13,306
4,084
136
Originally posted by: Mucman
Oh... and the developer is a girl... she sounds quite cute on the phone too :). Unfortunately, with this kind of coding, I'll have to pass ;)
So you'd rather hang out with an ugly geekgirl? :p
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
Originally posted by: Descartes
Originally posted by: notfred
Originally posted by: Descartes
Originally posted by: notfred
Originally posted by: jumpr
I've only taken elementary C++, so I might not know what I'm talking about, but do you need 'break' statments when writing a case statement also?

It's ASP code, not C++ did you read the first post?

To be pedantic, ASP isn't a language ;)

I didn't say it was.

"ASP code"

ASP has no code.

If I was talking about Mozilla source code and said "browser code" would that imply that I thought "browser" was a specific language?
 

gigapet

Lifer
Aug 9, 2001
10,005
0
76
should people have to get liscensed before they are allowed to code?

oh thats a whole thread in itself.
 

manly

Lifer
Jan 25, 2000
13,306
4,084
136
Originally posted by: Descartes

break statements aren't required in C or C++; in fact, it's quite helpful to fall through various case statements. e.g.:

switch (msg)
{
case WM_CLOSE:
case WM_DESTROY:
// handle both the same
}
There goes Descartes trying to prove his 1337-ness again. :)
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
Originally posted by: manly
Originally posted by: Descartes

break statements aren't required in C or C++; in fact, it's quite helpful to fall through various case statements. e.g.:

switch (msg)
{
case WM_CLOSE:
case WM_DESTROY:
// handle both the same
}
There goes Descartes trying to prove his 1337-ness again. :)

Nah, just proving the case for follow-through case statements ;)
 

Mucman

Diamond Member
Oct 10, 1999
7,246
1
0
Originally posted by: Descartes
Originally posted by: manly
Originally posted by: Descartes

break statements aren't required in C or C++; in fact, it's quite helpful to fall through various case statements. e.g.:

switch (msg)
{
case WM_CLOSE:
case WM_DESTROY:
// handle both the same
}
There goes Descartes trying to prove his 1337-ness again. :)

Nah, just proving the case for follow-through case statements ;)

I used that behaviour when I was playing around with Win32 programming :) yet I'm still not 1337 :p

I found a couple more case statements in the code! And lots of blah = Request("blah") with no error checking! The
site can probably be exploited using lots of SQL Injection techniques...
 

Mucman

Diamond Member
Oct 10, 1999
7,246
1
0
Oh wait! There's more!

The header and footer pages are all HTML... except they are ASP files full of :

Response.Write("
")
Response.Write(" some text")
Response.Write("</body>")

lol
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
Originally posted by: Mucman
Originally posted by: Descartes
Originally posted by: manly
Originally posted by: Descartes

break statements aren't required in C or C++; in fact, it's quite helpful to fall through various case statements. e.g.:

switch (msg)
{
case WM_CLOSE:
case WM_DESTROY:
// handle both the same
}
There goes Descartes trying to prove his 1337-ness again. :)

Nah, just proving the case for follow-through case statements ;)

I used that behaviour when I was playing around with Win32 programming :) yet I'm still not 1337 :p

I found a couple more case statements in the code! And lots of blah = Request("blah") with no error checking! The
site can probably be exploited using lots of SQL Injection techniques...

The lack of so many things in ASP with respect to validation (e.g. a lucid regular expressions engine) made such things like SQL injection pretty common. ASP.NET largely obviates the need for such checking the page validation facilities and server controls (e.g. RegularExpressionsValidator).
 

manly

Lifer
Jan 25, 2000
13,306
4,084
136
Originally posted by: Mucman

I used that behaviour when I was playing around with Win32 programming :) yet I'm still not 1337 :p

I found a couple more case statements in the code! And lots of blah = Request("blah") with no error checking! The
site can probably be exploited using lots of SQL Injection techniques...
I find it funny everytime there's a discussion about outsourcing, how some people have to chime in and deride the low quality of overseas programmers (or other engineers, or tech workers).

I know this is but one example, but I think in many organizations, software developers would have some understanding that their overseas counter-parts are not necessarily weaker than some of their colleagues.