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

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 16, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      May 16, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 16, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 16, 2025

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025

      Bing Search APIs to be “decommissioned completely” as Microsoft urges developers to use its Azure agentic AI alternative

      May 16, 2025

      Microsoft might kill the Surface Laptop Studio as production is quietly halted

      May 16, 2025

      Minecraft licensing robbed us of this controversial NFL schedule release video

      May 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

      The power of generators

      May 16, 2025
      Recent

      The power of generators

      May 16, 2025

      Simplify Factory Associations with Laravel’s UseFactory Attribute

      May 16, 2025

      This Week in Laravel: React Native, PhpStorm Junie, and more

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

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025
      Recent

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025

      Bing Search APIs to be “decommissioned completely” as Microsoft urges developers to use its Azure agentic AI alternative

      May 16, 2025

      Microsoft might kill the Surface Laptop Studio as production is quietly halted

      May 16, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»CodeSOD: Terminated Nulls

    CodeSOD: Terminated Nulls

    June 11, 2024

    When you get into the world of proprietary filesystems, things can get real weird. There are many a filesystem that doesn’t support directories, still in use today. Or filesystems which only allocated chunks in multi-megabyte blocks, which means you end up wasting a lot of space if you have small files. Or filesystems where the largest file size is itself a handful of megabytes.

    Dan was working on one such filesystem where, when you opened a file for writing, you could specify how many “fixed records” it needed to support. So, for example, if you wanted to open a file for writing, in binary mode, you might do this: open(pathToFile, “f4096wb”): support 4096 records, and open it for writing.

    Now, Dan’s predecessor wanted to do exactly that: open a file for writing, with 4096 records.

    This was their C code for doing that:

    char str[256];
    strcpy (str, “f4096”);
    strcat (str, (char *) “w”);
    strcat (str, “b”);
    strcat (str, “”);

    This code creates an empty array of characters 256 characters long. Then it copies the string “f4096” in. Then we use strcat to concatenate “w”- which we cast as (char*) which… fine? I suspect they originally tried to use ‘w’- a character, not a string- and got confused when it didn’t work. And then struggled when (char*)’w’ segfaulted. And by the time they landed on (char*)”w” they’d forgotten why they put the (char*) in there to begin with.

    Then they concatenate “b”- a “b” followed by a null terminator (which, also, the string literal also ends with a null terminator, not that it matters, as strcat stops at the first one). Then, for good measure, we concatenate another null terminator.

    All this could have been done with a simple string literal. None of this code is necessary. It certainly makes things more confusing to anyone reading the code.

    This block of code should be taken to be representative of the project that Dan was working on. This kind of “logic” was strewn all about the code.

    [Advertisement]
    Keep the plebs out of prod. Restrict NuGet feed privileges with ProGet. Learn more.

    Source: Read More 

    Hostinger
    Facebook Twitter Reddit Email Copy Link
    Previous Article10 Artificial Intelligence APIs for Developers
    Next Article Case Study: ToyFight — 2024

    Related Posts

    Security

    Nmap 7.96 Launches with Lightning-Fast DNS and 612 Scripts

    May 17, 2025
    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-48187 – RAGFlow Authentication Bypass

    May 17, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    Get faster and actionable AWS Trusted Advisor insights to make data-driven decisions using Amazon Q Business

    Machine Learning

    How to set up Microsoft Edge Game Assist on Windows 11

    News & Updates

    BISCUIT: Scaffolding LLM-Generated Code with Ephemeral UIs in Computational Notebooks

    Development

    Attack Surface Management vs. Vulnerability Management

    Development

    Highlights

    Development

    Meta AI Researchers Introduce Mixture-of-Transformers (MoT): A Sparse Multi-Modal Transformer Architecture that Significantly Reduces Pretraining Computational Costs

    November 14, 2024

    Advancements in AI have paved the way for multi-modal foundation models that simultaneously process text,…

    Build knowledge-powered conversational applications using LlamaIndex and Llama 2-Chat

    April 8, 2024

    Tbmk – terminal bookmarker

    January 14, 2025

    Salesforce CPQ Advanced Approvals: A Beginner’s Guide to Streamlined Approval Processes

    November 18, 2024
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

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