Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Upwork Freelancers vs Dedicated React.js Teams: What’s Better for Your Project in 2025?

      August 1, 2025

      Is Agile dead in the age of AI?

      August 1, 2025

      Top 15 Enterprise Use Cases That Justify Hiring Node.js Developers in 2025

      July 31, 2025

      The Core Model: Start FROM The Answer, Not WITH The Solution

      July 31, 2025

      Finally, a sleek gaming laptop I can take to the office (without sacrificing power)

      August 1, 2025

      These jobs face the highest risk of AI takeover, according to Microsoft

      August 1, 2025

      Apple’s tariff costs and iPhone sales are soaring – how long until device prices are too?

      August 1, 2025

      5 ways to successfully integrate AI agents into your workplace

      August 1, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      Enhancing Laravel Queries with Reusable Scope Patterns

      August 1, 2025
      Recent

      Enhancing Laravel Queries with Reusable Scope Patterns

      August 1, 2025

      Everything We Know About Livewire 4

      August 1, 2025

      Everything We Know About Livewire 4

      August 1, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      YouTube wants to use AI to treat “teens as teens and adults as adults” — with the most age-appropriate experiences and protections

      August 1, 2025
      Recent

      YouTube wants to use AI to treat “teens as teens and adults as adults” — with the most age-appropriate experiences and protections

      August 1, 2025

      Sam Altman is afraid of OpenAI’s GPT-5 creation — “The Manhattan Project feels very fast, like there are no adults in the room”

      August 1, 2025

      9 new features that arrived on the Windows 11 Insider Program during the second half of July 2025

      August 1, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»News & Updates»CodeSOD: Going on a teDa

    CodeSOD: Going on a teDa

    July 30, 2025

    Carlos G found some C++ that caused him psychic harm, and wanted to know how it ended up that way. So he combed through the history. Let’s retrace the path with him.

    Here was the original code:

    void parseExpiryDate (const char* expiryDate)
    {
        // expiryDate is in "YYMM" format
        int year, month;
        sscanf(expiryDate, "%2d%2d", &year, &month);
    	
        //...
    }
    

    This code takes a string containing an expiry date, and parses it out. The sscanf function is given a format string describing two, two digit integers, and it stores those values into the year and month variables.

    But oops! The expiry date is actually in a MMYY format. How on earth could we possibly fix this? It can’t be as simple as just swapping the year and month variables in the sscanf call, can it? (It is.) No, it couldn’t be that easy. (It is.) I can’t imagine how we would solve this problem. (Just swap them!)

    void parseExpiryDate(const char* expiryDate)
    {
        // expiryDate is in "YYMM" format but, in some part of the code, it is formatted to "MMYY"
        int year, month;	 
        char correctFormat[5];
    
        correctFormat[0] = expiryDate[2];
        correctFormat[1] = expiryDate[3];
        correctFormat[2] = expiryDate[0];
        correctFormat[3] = expiryDate[1];
        correctFormat[4] = '';
        sscanf(correctFormat, "%2d%2d", &year, &month);
    
        //...
    }
    

    There we go! That was easy! We just go, character by character, and shift the order around and copy it to a new string, so that we format it in YYMM.

    The comment here is a wonderful attempt at CYA. By the time this function is called, the input is in MMYY, so that’s the relevant piece of information to have in the comment. But the developer really truly believed that YYMM was the original input, and thus shifts blame for the original version of this function to “some part of the code” which is shifting the format around on them, thus justifying… this trainwreck.

    Carlos replaced it with:

    void parseExpiryDate (const char* expiryDate)
    {
        // expiryDate is in "MMYY" format
        int month, year;
        sscanf(expiryDate, "%2d%2d", &month, &year);
    	
        //...
    }
    

    [Advertisement]
    Keep all your packages and Docker containers in one place, scan for vulnerabilities, and control who can access different feeds. ProGet installs in minutes and has a powerful free version with a lot of great features that you can upgrade when ready.Learn more.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticlePerformance Analysis with Laravel’s Measurement Tools
    Next Article RSLint – fast, customizable, and easy to use JavaScript and TypeScript linter

    Related Posts

    News & Updates

    Finally, a sleek gaming laptop I can take to the office (without sacrificing power)

    August 1, 2025
    News & Updates

    These jobs face the highest risk of AI takeover, according to Microsoft

    August 1, 2025
    Leave A Reply Cancel Reply

    For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

    Continue Reading

    Scoperte 2 Nuove Vulnerabilità che Minacciano il Mondo GNU/Linux

    Linux

    CVE-2025-31231 – Apple macOS Sequoia Location Information Disclosure Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-49864 – AFS Analytics Missing Authorization Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-5194 – WordPress Map Block Stored Cross-Site Scripting

    Common Vulnerabilities and Exposures (CVEs)

    Highlights

    Hey Sony, take notes! Virtuos’ The Elder Scrolls IV: Oblivion just proved there’s more to a great remaster than meets the eye

    April 23, 2025

    Bethesda and Virtuos have shown how a proper remaster needs more than pretty visuals. Sony…

    CVE-2025-6272 – wasm3 Out-of-Bounds Write Vulnerability

    June 19, 2025

    Rilasciato Celluloid 0.29: Lettore Video Libero e Moderno per GNU/Linux

    May 18, 2025

    CVE-2025-8244 – TOTOLINK X15 HTTP POST Request Handler Buffer Overflow Vulnerability

    July 28, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.