Thread: Examine Code

  1. #1
    Registered User
    Join Date
    May 2012

    Question Examine Code

    i am good at coding and stuff so please can anyone please help me in finding 1)some vulnerability of class/type 2) the exact cause of the problem 3) How to fix the code to mitigate the vulnerability.??
    int get_stuff()
    { int ran1, ran2;
    char stuff[64];
    ran2 = ran1 = rand(); /* get a random number */
    if (ran1 != ran2)
    exit(); /* something wrong */
    /* proceed */

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    If you're "good at coding", then you should really know about the gets() flaws already, and how to fix them.

    Or at least be able to read about it in pretty much any C programming FAQ around the net.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    May 2012
    @salem - sorry that's my typo mistake, I meant to say I'm not good at programming. Can u help me with this code??

  4. #4
    Registered User
    Join Date
    May 2009
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  5. #5
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    London, UK
    1) "get_stuff" is a terrible function name
    2) variables should be declared on their own lines
    3) variables should be initialised
    4) Nothing should go on the same line after a curly brace
    5) As mentioned gets is a big no-no
    6) You're using C++ style comments
    7) Always use braces with if statements
    8) Don't exit from functions, especially when they have a return variable
    9) Always return something unconditionally from a function that has a return value
    10) Indent your code properly
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Examine size of code/data in the exe
    By idelovski in forum Windows Programming
    Replies: 4
    Last Post: 01-03-2012, 02:44 PM
  2. Examine Core Dump
    By wenxinleong in forum C Programming
    Replies: 1
    Last Post: 07-04-2011, 10:52 AM
  3. Examine hex number?
    By Sly in forum C Programming
    Replies: 16
    Last Post: 03-01-2009, 01:04 PM
  4. Examine a variable with GDB
    By ^xor in forum Linux Programming
    Replies: 8
    Last Post: 08-16-2005, 01:40 PM
  5. Examine my code please
    By TWIXMIX in forum C++ Programming
    Replies: 13
    Last Post: 03-21-2004, 12:28 PM