CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2010

    Angry Class instancing produces buffer overrun

    I dont know what's happening... never seen this before :-/


    void Test()
    CConfigLoader loader;

    class CConfigLoader
    CONFIG Config;

    CConfigLoader(void) {};
    ~CConfigLoader(void) {};

    bool LoadFromFile(char *path) {code_not_being_invoked()};
    void LoadDefault() { code_not_being_invoked() };

    CONFIG Get() {return Config; };

    typedef struct _CONFIG
    struct Video
    word port;
    char profile[64];
    } video_ir, video_cam;
    bool b_video_ir, b_video_cam;

    struct Commands
    word port;
    word timeout;
    } commands;
    bool b_commands;

    struct Detection
    word sensibility_line[640];
    word threshold_1_line[640];
    word threshold_2_line[640];

    byte sensibility_value[640];
    byte threshold_1_value[640];
    byte threshold_2_value[640];

    int sensibility_count;
    int threshold_1_count;
    int threshold_2_count;
    } detection;
    bool b_detection;

    struct DeviceIR
    char source[MAX_PATH];
    in_addr address;
    word port;
    word width;
    word height;
    byte range;
    bool autobrightness;
    bool autocontrast;
    byte brightness;
    byte contrast;
    byte ab_brightness;
    byte ac_contrast;
    bool gamma;
    byte nucmode;
    byte avg_filter;
    byte shrp_filter;
    } ir;
    bool b_ir;

    struct DeviceCAM
    char source[MAX_PATH];
    in_addr address;
    word port;
    word width;
    word height;
    byte zoom;
    byte focus;
    byte shutter;
    byte iris;
    byte gain;
    byte bright;
    byte aperture;
    bool dzoom;
    bool autofocus;
    bool palette_negative;
    bool palette_bw;
    bool osd;
    bool icr;
    bool autoirc;
    bool backlight;
    byte whitebalance;
    byte autoexposure;
    } cam;
    bool b_cam;

    struct DevicePTZ
    in_addr address;
    word port;
    float pan;
    float tilt;
    } ptz;
    bool b_ptz;

    char source[MAX_PATH];

    This produces "Run-Time Check Failure #2 - Stack around the variable 'loader' was corrupted." if running in debug mode when function Test() exits or buffer overrun if running in release.
    Any idea?


    void Test()
    CONFIG loader;
    loader.b_ptz = true;
    doesn't produce any buffer overrun....

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Seattle, WA

    Re: Class instancing produces buffer overrun

    This mostly looks like C, but there are a few bits of C++ in there. Given that you're using C++, it would probably be safer and easier to use std::strings rather than fixed-size char arrays, so long as you're aware of the caveats when working with non-POD types.

    I don't see a main() function there, so I can't give your program a test run. I certainly don't see anything which could cause a buffer overflow offhand.

  3. #3
    Join Date
    Aug 2005
    San Diego, CA

    Lightbulb Re: Class instancing produces buffer overrun

    Edit the post, and paste properly formatted source. Highlight it and press that little # key to add code tags. If we could read it and if there was a main function that compiles we could read it and give it a test run. I'm not even going to try to decipher that original post.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.