Go Back   RareWareCentral Forums > Blogs > Listen to the hat.

Rate this Entry

The Daily Stumble - Coding Story - 13/04/2011

Posted 04-13-2011 at 01:46 AM by Anthrax

Okay, I got this off a site, I found it really funny but others that don't understand will find it completely 'unfunny'.

Quote:
(This one is kind of technical, sorry.) We're working on this computer game called Terra Nova, where you run around outside in powered battle armor with your squadmates beating people up.
One guy on the team is a junior programmer, who is a fine guy and an okay coder, but whose coding style isn't all that 'mature', as we say in the business -- the code often isn't very elegant or robust.
Anyway, he's working on this system for displaying data about your powered battle armor. There's a little 3-digit LED that shows the suit's temperature, and he's putting the temperature into string form for displaying there. So his code looks something like this:

temp_to_str (int temp)
{
char str[4];
sprintf (str, "%d", temp);
and so forth. I tell him, "Hey, this is no good, because if the temperature ever goes over 1000 (or under -100), you'll overflow your string and the game will just totally crash without warning."
He says, "Oh yeah, okay, whatever, I'll fix it."
So I look back at the code a couple days later, to make sure that he's fixed it, and he has indeed changed the code. It now looks like this:

temp_to_str (int temp)
{
char str[4];
if (temp <= -100 || temp >= 1000)
fprintf (stderr, "WARNING: PROGRAM IS ABOUT TO CRASH!\n");
sprintf (str, "%d", temp);
(Source)
Views 515 Comments 2 Edit Tags Email Blog Entry
« Prev     Main     Next »
Total Comments 2

Comments

  1. Old Comment
    Darksardine's Avatar
    I think I get it.
    Posted 04-13-2011 at 08:12 PM by Darksardine Darksardine is offline
  2. Old Comment
    GameMasterGuy's Avatar
    I get it Except for the s before "printf".
    Posted 04-15-2011 at 12:23 AM by GameMasterGuy GameMasterGuy is offline
 

All times are GMT. The time now is 03:32 AM.