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

      Representative Line: Brace Yourself

      September 18, 2025

      Beyond the Pilot: A Playbook for Enterprise-Scale Agentic AI

      September 18, 2025

      GitHub launches MCP Registry to provide central location for trusted servers

      September 18, 2025

      MongoDB brings Search and Vector Search to self-managed versions of database

      September 18, 2025

      Distribution Release: Security Onion 2.4.180

      September 18, 2025

      Distribution Release: Omarchy 3.0.1

      September 17, 2025

      Distribution Release: Mauna Linux 25

      September 16, 2025

      Distribution Release: SparkyLinux 2025.09

      September 16, 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

      AI Momentum and Perficient’s Inclusion in Analyst Reports – Highlights From 2025 So Far

      September 18, 2025
      Recent

      AI Momentum and Perficient’s Inclusion in Analyst Reports – Highlights From 2025 So Far

      September 18, 2025

      Shopping Portal using Python Django & MySQL

      September 17, 2025

      Perficient Earns Adobe’s Real-time CDP Specialization

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

      Valve Survey Reveals Slight Retreat in Steam-on-Linux Share

      September 18, 2025
      Recent

      Valve Survey Reveals Slight Retreat in Steam-on-Linux Share

      September 18, 2025

      Review: Elecrow’s All-in-one Starter Kit for Pico 2

      September 18, 2025

      FOSS Weekly #25.38: GNOME 49 Release, KDE Drama, sudo vs sudo-rs, Local AI on Android and More Linux Stuff

      September 18, 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:

    <span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">parseExpiryDate</span> <span class="hljs-params">(<span class="hljs-type">const</span> <span class="hljs-type">char</span>* expiryDate)</span>
    </span>{
        <span class="hljs-comment">// expiryDate is in "YYMM" format</span>
        <span class="hljs-type">int</span> year, month;
        <span class="hljs-built_in">sscanf</span>(expiryDate, <span class="hljs-string">"%2d%2d"</span>, &year, &month);
    	
        <span class="hljs-comment">//...</span>
    }
    

    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!)

    <span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">parseExpiryDate</span><span class="hljs-params">(<span class="hljs-type">const</span> <span class="hljs-type">char</span>* expiryDate)</span>
    </span>{
        <span class="hljs-comment">// expiryDate is in "YYMM" format but, in some part of the code, it is formatted to "MMYY"</span>
        <span class="hljs-type">int</span> year, month;	 
        <span class="hljs-type">char</span> correctFormat[<span class="hljs-number">5</span>];
    
        correctFormat[<span class="hljs-number">0</span>] = expiryDate[<span class="hljs-number">2</span>];
        correctFormat[<span class="hljs-number">1</span>] = expiryDate[<span class="hljs-number">3</span>];
        correctFormat[<span class="hljs-number">2</span>] = expiryDate[<span class="hljs-number">0</span>];
        correctFormat[<span class="hljs-number">3</span>] = expiryDate[<span class="hljs-number">1</span>];
        correctFormat[<span class="hljs-number">4</span>] = <span class="hljs-string">''</span>;
        <span class="hljs-built_in">sscanf</span>(correctFormat, <span class="hljs-string">"%2d%2d"</span>, &year, &month);
    
        <span class="hljs-comment">//...</span>
    }
    

    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:

    <span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">parseExpiryDate</span> <span class="hljs-params">(<span class="hljs-type">const</span> <span class="hljs-type">char</span>* expiryDate)</span>
    </span>{
        <span class="hljs-comment">// expiryDate is in "MMYY" format</span>
        <span class="hljs-type">int</span> month, year;
        <span class="hljs-built_in">sscanf</span>(expiryDate, <span class="hljs-string">"%2d%2d"</span>, &month, &year);
    	
        <span class="hljs-comment">//...</span>
    }
    

    [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

    Distribution Release: Security Onion 2.4.180

    September 18, 2025
    News & Updates

    Distribution Release: Omarchy 3.0.1

    September 17, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    CVE-2025-30010 – SAP SRM Java Applet Cross-Site Scripting (XSS)

    Common Vulnerabilities and Exposures (CVEs)

    Zhipu AI Releases GLM-4.5V: Versatile Multimodal Reasoning with Scalable Reinforcement Learning

    Machine Learning

    OpenAI pulling GPT-4o from ChatGPT felt like a free hit to get us hooked — now it’s locked behind a $20/month paywall

    News & Updates

    You should probably delete any sensitive screenshots you have in your phone right now. Here’s why

    News & Updates

    Highlights

    Zoobook’s Customizable EHR: Why Your System Should Adapt to You

    May 21, 2025

    Post Content Source: Read More 

    CVE-2025-47423 – Furbo Personal Weather Station File Disclosure Vulnerability

    May 7, 2025

    CVE-2025-49446 – Minhlaobao Admin Notes CSRF Vulnerability

    June 6, 2025

    Best Rehabilitation Centre in Tirupur – Latchiyam Life Care Trust

    August 11, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

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