• Old Wolf (unregistered) in reply to austinjp
    austinjp:

    THIS IS NOT A WTF!

    There is a subtle bug with the: char strDigit[1]; //store 1 digit in that the null terminator from strcpy will overwrite something, but that is a common misstake and not an example of some crazy code that makes me want to throw up my hands and throttle the guy.

    This is exactly the sort of attitude that leads directly to the existence of so many buffer overflow exploits. I'm sure you also don't mind too much that your computer crashes sometimes.
    Anyway, I'm giving up on this site. Have fun!
    Please do the world a favour and give up on programming too.
  • (cs) in reply to Ornedan
    Ornedan:
    dp.design:
    As a student, I was definitely responsible for much worse crap than this. I don't think it's fair to pick on learner's mistakes.
    Considering it's the Software Engineering project, it is fair to pick on the mistakes. You're not supposed to be learning to code by then anymore, that's what the previous labworks and courses were for.

    I'm sure it varies between schools. My 2nd or 3rd CS course was intro to software engineering. At that point I probably made equally stupid mistakes.

    Of course if this was an upper division software engineering course... then, yeah...

  • Chutney (unregistered)

    The error handler-

    mOwner.mLogger.Warn("Input Error: %s is not 0-9 or A-F", strDigit);

    //Should I crash or not?????

    Probably will crash...

    strDigit is a char[1] not a null terminated C string which is what the %s specifier usually means - but who knows with this lot. Prob should be ..."Input Error: %c is not 0-9 or A-F"...

    Agree with the comments about using student code though - we all have to learn by our mistakes.

  • David V. (unregistered) in reply to austinjp
    austinjp:
    Anyway, I'm giving up on this site. Have fun!

    The site should have a special hit counter to list how many people that claim that come back the next day to troll again ;;)

  • (cs)

    I have to agree with the rest of the peanut gallery. For students, this is actually pretty good code, inasmuch as it actually works.

    To the person who decided to post this as a WTF: This code is awkward and poorly designed, but so were you when you were young.

  • AdT (unregistered) in reply to austinjp
    austinjp:
    THIS IS NOT A WTF!

    ...

    Anyway, I'm giving up on this site. Have fun!

    You did notice that

    1. The code pointlessly creates substring objects for single characters. (Read up on std::basic_string's operator[] if you will.)
    2. The code pointlessly uses strcpy to copy those substrings into a char buffer.
    3. The buffer will overflow, resulting in undefined behavior.
    4. The use of the pow function is completely redundant.
    5. The call to "Warn" results in undefined behavior, as was pointed out by others.
    6. The code pointlessly uses strcmp instead of operator ==(char, char) or even switch, in this case resulting in undefined behavior.
    7. "//Should I crash or not?????" If that isn't a major comment WTF, I don't know what is.

    Even if the strDigit buffer is fixed to accomodate two characters, this code is a horribly inefficient mess.

    And you think given all of this there is no WTF? If that is your attitude towards software quality, I'm sure this site will hear of you, one way or the other.

  • AdT (unregistered) in reply to IQpierce
    IQpierce:
    I have to agree with the rest of the peanut gallery. For students, this is actually pretty good code, inasmuch as it actually works.

    No, it might just happen to work on some C++ implementations.

    IQpierce:
    To the person who decided to post this as a WTF: This code is awkward and poorly designed, but so were you when you were young.

    I was poorly designed when I was young? Well then, blame it on the designer.

  • Ken (unregistered) in reply to gentian

    I am the original submitter of the code. I don't know why this was posted as "student code". This was NOT student code. This was "co-op" code. He WAS being paid to write this code, although he is still in his last year of university. He has 3 years of C++ experience and should be expected to write better code than this.

    Besides, quit your damn whining and laugh at the funny code man!

  • Ken (unregistered) in reply to IQpierce

    First of all, as I mentioned elsewhere, this was NOT student code, and I don't know why they posted it that way.

    Second, if you think this is "pretty good code", then I imagine you've been featured on WTF at some point as well.

    Third, I can promise you that I never wrote anything this bad even in university. Some people just "get it" when it comes to programming, and some people clearly do not.

  • brendan (unregistered) in reply to Old Wolf
    Comment held for moderation.
  • liz (unregistered) in reply to dp.design
    dp.design:
    As a student, I was definitely responsible for much worse crap than this. I don't think it's fair to pick on learner's mistakes.

    very well said...

  • Price (unregistered)

    I've your learning a language and have no clue about data types and binary representations... You skipped a few lessons.

    Thats the WTF for me here.

    ps; 'A'!='a' in Hex??

  • John (unregistered) in reply to fist-poster
    fist-poster:
    Asgeir:
    Skybert:
    cognac:
    vt_mruhlin:
    //-------------------------------------------------------------
    //Hex2Char: converts hex to a decimal. i.e. 0x0A becomes 'A'
    char UC_Crypt::Hex2Char(char nHex){
         switch(nHex){
              case '0': return 0;
              case '1': return 1;
    ...
              case 'F': return 15;
         }
         return 0;
    }
    
    ....
    If that switch is supposed to be c or c++, it features a nice bug. ;)
    Looks ok, works ok. What's the bug? (I don't count missing default or misleading method-name as bugs).
    If you pass any ascii value other than from the (0..9, a..f, A..F) set into it, it will return zero.

    And so exactly where does c or c++ come in? It does return a default and that is unfortunately chosen (I think it should crash, or at least it should consider that possibility), but it would work the same in pretty much any language supported a switch-like thing.

    The bug should be obvious people - the method signature returns a char instead of an int.

  • shoot (unregistered) in reply to ElectroDruid
    ElectroDruid:
    Same as the other guys have said, I don't understand why student work has suddenly become "fair game". We were all beginners once. Is this site running out of decent submissions or something?

    Agreed in principle, but you can expect a student to make a go of understanding what they are doing, surely?

    Some of these are up there with "Sir Francis Drake circumcised the globe with a 100ft clipper", or "The pyramids are a range of mountains between France and Spain."

  • 855 (unregistered)
    Comment held for moderation.

Leave a comment on “That'll Show the Grader”

Log In or post as a guest

Replying to comment #:

« Return to Article