• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Stainless

Funniest line of code ever ?

126 posts in this topic

Trying to track down a memory leak the other day I ended up in a bit of the code base that hasn't been touched for many years.

 

I slowly worked through it unitl I hit this LOC and just cracked up.

 

#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))

 

Any body else got a good one?

 

 

2

Share this post


Link to post
Share on other sites

What is wrong with this preprocessor line? It just means to do stuff if this is gcc and we're on an x86 system... I'm not getting the joke.

 

It's basically saying "if your computer is really, really, really old.... or really new"

 

If you have a 486, pentium, or any modern 32 bit processor, you are out of luck.

rolleyes.gif

0

Share this post


Link to post
Share on other sites

This was during a C programming class, someone wrote that code to 'use' a null terminated string. Both me and the teacher spent quite a while staring at it, trying to 'guess' why it crashes.

void use_str(char * str)
{
  while(*str=!0)
  {
	//do something with char in *str
	++str;
  }
}

Also, a nice attempt to hardcode the password in php that someone I know did on their personal filesharing website (I'm not good with PHP, so this code might be wrong, but you get the idea laugh.png ).

if ($pass === "password1" || "password2")
Edited by FRex
0

Share this post


Link to post
Share on other sites

 

This was during a C programming class, someone wrote that code to 'use' a null terminated string. Both me and the teacher spent quite a while staring at it, trying to 'guess' why it crashes.

void use_str(const char * str)
{
  while(str=!0)
  {
	//do something with char in *str
	++str;
  }
}

Also, a nice attempt to hardcode the password in php that someone I know did on their personal filesharing website (I'm not good with PHP, so this code might be wrong, but you get the idea laugh.png ).

if ($pass === "password1" || "password2")

 

Ah that zero terminated string thing must have been crashing bad unless you sent NULL to it... biggrin.png

 

The PHP code example, I believe is more common that you would like to know.  Seems like perfectly legal PHP to me, but I assume the point is that you should never put your password in clear text in the source file?  

 

It has been a while since I have touched PHP now, but I used to do a trick like this to make sure I had number values from user input fields:

$user_input += 0;

//Then use in an SQL query, safely knowing it can't be escaped...

Not sure if that is still regarded as a safe trick to force number values.

 

-- Oh, and I actually used the 'eval' function on data that was sent from the user once...  Not a good idea unless you really are knowing what you are doing.

 

I should have written down all the stupid errors I have done during the years, and I would be able to fill a whole book lol...  biggrin.png

Edited by aregee
0

Share this post


Link to post
Share on other sites

 

Ah that zero terminated string thing must have been crashing bad unless you sent NULL to it... biggrin.png

I'm not sure what you mean by that. biggrin.png (Actually - I made mistake in original snippet, I've corrected that now, the point is that code is writing 1s to string forever instead of checking for 0 because ! and = are swapped).

 

the point is that you should never put your password in clear text in the source file?

The point is that it works as

if (($pass === "password1") || "password2")

and the literal he used was interpreted as true (it wasn't "0" or ""), the condition was always true so any password worked. It also makes sense if you read it out loud (and that wasn't a programmer writing that): "if variable pass is strictly equal to password1 or password2".

What he meant was

if (($pass === "password1") || ($pass === "password2"))
Edited by FRex
0

Share this post


Link to post
Share on other sites


So it's saying "If you're on x86 or on x86-64..." tongue.png wink.png

 

Not on our compiler, 386 MEANS 386 , not x86 generic, just 386. 

 

We also have things like __ppc__ , __mips__, __arm__, __x86__,  and the most scary of all __WIN64__   ohmy.png

0

Share this post


Link to post
Share on other sites

I debugged a problem some years ago and found the following line:

logbook->logMutex( true, true, false, true );

Unfortunately at that moment I didn't had much time to laught about it smile.png .

 

Kimmi

0

Share this post


Link to post
Share on other sites


Why doesn't the compiler complain that you are trying to assign to a read-only variable?

 

Because its a pointer to const char, and not a const pointer to char. The pointer itself is not readonly... or did I miss the joke? :D

1

Share this post


Link to post
Share on other sites


*str=!0



does assign to *str, it is assigning !0 to it.

 

God, I was looking at the wrong line... *feels ashamed and goes to the corner*

2

Share this post


Link to post
Share on other sites

 

Why doesn't the compiler complain that you are trying to assign to a read-only variable?

Because I put the const there out of habit and was writing that out of my memory. The original obviously didn't have the const because it modified the str and simply crashed when pointer finally went too far. I've corrected the original snippet (again).

 

The pointer itself is not readonly... or did I miss the joke? biggrin.png

No, that was my mistake, the actual 'joke' (this happened in class so it's more of a funny error than a joke) is that this code looks ok at a glance but the swapped ! and = make it try and fill all the memory, starting with str, with 1s instead of doing intended work...

Edited by FRex
0

Share this post


Link to post
Share on other sites
I think by now I want a version of C++ that doesn't do any automatic type conversions at all. !0 is the int 1, and you shouldn't be allowed to assign that to a char without an explicit cast.
0

Share this post


Link to post
Share on other sites

 

What he meant was

if (($pass === "password1") || ($pass === "password2"))

 "Equal to" and "of the same type" ... bit redundant .

0

Share this post


Link to post
Share on other sites

From a Kinect Game i was refactoring.

 

The level had a fixed size and you were moving through kind of a tube, only capable of strafing and adjusting your speed.

Player.Score += (int)(60f * Player.Velocity.Length() * gameTime.GetDelta());
1

Share this post


Link to post
Share on other sites

 

 "Equal to" and "of the same type" ... bit redundant .

Maybe, but at least that prevents surprises from numerical conversions and weird interactions between $pass and the string if $pass is some other type. It gets really screwy:

http://php.net/manual/en/types.comparisons.php

I don't remember if it was === or == actually, it could have been ==, it was long ago and that person wasn't a programmer.

Edited by FRex
0

Share this post


Link to post
Share on other sites

My favorites are always static analyzer stuff.  Frequently annotated with "//to shut up the static analyzer".  I can't think of any recent examples though.

1

Share this post


Link to post
Share on other sites

I knew a guy who wrapped some code that would never be reached in:

if (superman > batman){
//some code
}

biggrin.png

1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0