• Hanzito (unregistered)

    A frist thing happened.

  • (nodebb)

    A thrid thing happened

  • DQ (unregistered)

    And then a scnd thing

  • (nodebb)

    This is one of those so obvious so dumb things that it's hardly WTF worthy.

    I don't know those particular syscalls, but was there any good reason they couldn't have simply replaced the call to the first with the call to the second then output all the date & time components from that result value?

    Looks to me like another example of doing without thinking. And of "the best change is the smallest change". Both of which are shortsighted crap pushed by ignorant managements. Faster isn't better when you have to do it twice to get it right. Or more.

  • Hanzito (unregistered) in reply to WTFGuy

    This is one of those so obvious so dumb things that it's hardly WTF worthy.

    You may think so, but the other day, I saw an announcement for some kind of "no code" declarative thingy that translates to SQL and JavaScript (and something else), which was vibe-coded and had this exact same error in the example on the front page. Nobody seemed to notice it. So there's that...

  • (nodebb) in reply to WTFGuy

    I don't know those particular syscalls, but was there any good reason they couldn't have simply replaced the call to the first with the call to the second then output all the date & time components from that result value?

    No, there wasn't a good reason. That's why it's a WTF and posted on this site.

  • (nodebb)

    At least this code is pretty easy to fix:

    #include <cstdio>
    #include <ctime>
    #include <sys/time.h>
    
    int main() {
        struct timeval now_tv;
        gettimeofday( &now_tv, NULL );
        struct tm* now_tm = gmtime( &now_tv.tv_sec );
        
        printf(
            "[%04d-%02d-%02d %02d:%02d:%02d.%06d] Foo\n",
            now_tm->tm_year + 1900,
            now_tm->tm_mon + 1,
            now_tm->tm_mday,
            now_tm->tm_hour,
            now_tm->tm_min,
            now_tm->tm_sec,
            (int) now_tv.tv_usec
        );
        
        return 0;
    }
    

    A couple things I noticed in the original code that's probably from anonymization: now_tv was declared on the stack but its members accessed via -> instead of . and time(); was being called without an argument (often just NULL), both of which result in compiler errors.

  • (author)

    This (wasn't, but) looks like the kind of code an LLM might write and probably skates through code review. It's certain to pass all but the most thoroughly mocked-out testing. It sure is a shame to have to write many many manhours of time-taxed test code where a little bit of "be careful and pay attention" would suffice.

  • Back to the 1990s (unregistered)

    Fixed just this kind of error back in about 1991 or 1992.
    Was a utility that read a collection of data for the logs in the NOC and created a report. Initial bug was reported as certain days near midnight would end up on the later side of midnight. Fixed with just one call to now=time() and kept using time().
    The code base was C. The network was late-1980s packet switching. No pipes, tubes or information super highway off-ramps yet.

Leave a comment on “Well Timed Double Checking”

Log In or post as a guest

Replying to comment #690219:

« Return to Article