• (nodebb)

    Wow, the memory management is actually the first red flag I noticed.

    In C/C++ you either have a factory or you have a buffer. You don't mix them for various architectural reasons but also because you can end up with two different memory management implementations for example in the main app and libraries which would result in super weird memory issues that are super annoying to detect - often worse than multi threading issues.

  • Anonymous (unregistered)

    Actually, it isn't accessing "out of bounds" because the declaration says there are 1000 elements, and since there is an initializer, the remaining elements do get initialized to 0.

  • (nodebb)

    Wow! This is the first time ever I see a piece of code and the first adjective that comes to my mind is "cursed". Just in case, don't read it out loud because it gives the impression it might summon something nasty. :D

  • (nodebb)

    And, given that the result is an out-of-bounds array access

    Um.

    char an[1000][3] =

    No, it's not out-of-bounds. The extra 10 entries are all full of zeroes, specifically { '\0', '\0', '\0' } in each one, seeing as how the array is declared at 1000 entries.

  • Scragar (unregistered)

    we start dividing my 1000

    Should be

    we start dividing by 1000

  • (nodebb)

    I think I figured out the naming. dl is data_len, but it's used as the index into an, so I think it's the length of something that's being converted to a string, probably for display to a user. Then len_len is part of a structure called cfg, so it's probably some kind of configuration setting that means "the display length of the length property of the data".

    Or something.

  • Richard Brantley (unregistered)

    "And frankly, why we couldn't just use itoa or a similar library function which already does this and is probably more optimized than anything I'm going to write."

    I have long since concluded that a simple sense of humility can be a programmer's greatest strength.

  • (nodebb)

    That break on the 14th line won't do anything, unless this code is inside a loop that we don't see. Assuming it's not, then execution will proceed merrily along.

  • (nodebb)

    ha ha ha ha nice try, Remy, but I've been through enough that you couldn't pay me to examine that code. Those days are GONE.

    I like a good CodeSOD as much as the next reader, but I have my limits.

  • Tinkle (unregistered)
    Comment held for moderation.
  • (nodebb) in reply to RogerC

    Even if it's in a loop it won't do anything. It's for breaking out of the switch.

    Why we have a switch statement with only one case is the new question, unless Remy chose not to show the rest of it.

  • (nodebb)

    It seems that all of you assume the memory gets zero-filled. I don't think this is guaranteed.

  • (nodebb) in reply to davethepirate

    It seems that all of you assume the memory gets zero-filled. I don't think this is guaranteed.

    It's C, which guarantees that initialised-but-not-fully aggregates (arrays, structs) are "zero"-filled in the parts that aren't initialised.

    "zero" in quotes because it's not necessarily just a memset-to-zero, if the in-memory representation of e.g. floats, doubles or NULL pointers is not the all-zeroes bit pattern. (The main culprit these days would be IBM's iSystem machines, formerly AS/400, where the bitpattern for NULL is not all-zeroes.)

  • Duke of New York (unregistered)
    Comment held for moderation.

Leave a comment on “itouhhh…”

Log In or post as a guest

Replying to comment #:

« Return to Article