run-time check faluire #2 stack around the variable is corrupted

Posted on 2008-11-18
Last Modified: 2013-12-14
I am getting an error for the following code

char tmpMaxCompression[19];
double MinVal = 0.0;

//MinVal is dynamic input from the user

sprintf_s( tmpMaxCompression, _countof(tmpMaxCompression) + 1 , "19.2%d" , MinVal );

The error - run-time check failure #2 - stack around the variable 'tmpMaxCompression' was corrupted
Question by:ndenson
    1 Comment
    LVL 3

    Accepted Solution

    > char tmpMaxCompression[19];
    > sprintf_s( tmpMaxCompression, _countof(tmpMaxCompression) + 1 , "19.2%d" , MinVal );

    20 chars (including termination '\0') are written to array of size 19
    to fix: increase array size, decrease 2nd arg of sprintf_s

    char tmpMaxCompression[20];
    sprintf_s( tmpMaxCompression, _countof(tmpMaxCompression) , "19.2%d" , MinVal );

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
    Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
    The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
    The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now