locked
Missing memmove_s.c file

    Question

  • I seem to be missing a File/Code that Visual C++ Express wants to access, this causes the Program to just exit without seeming to have an error, the code I am using is:

    vector<Sprite*>::iterator siSprite;

    for (siSprite = m_vSprites.begin(); siSprite != m_vSprites.end(); siSprite++)

    {

    delete (*siSprite);

    m_vSprites.erase(siSprite);

    siSprite--;

    }

    where m_vSprite is declared as a protected member of the Vector type.

    I managed to step into the code with the debugger to find the problematical point which seems to be in the following Code:

    if (_Off > 0)

    _CRT_SECURE_MEMMOVE(&*_Dest, _Off * sizeof (*_First), &*_First, _Off * sizeof (*_First));

    return _Result;

    When it gets to this point it either looks for the memmove_s.c code or simply states that the code is unavailable, I searched through all the files on my computer for it and there is no sign of it being anywhere.

    However when I Searched for any files with *.c I found all of them contained within the Microsoft Platform SDK sub directories and one of them was memmove.c, I don't want to mess around with the files contained in the SDK for fear of damaging the integrity of the program as it stands, but I'm at a loss as to how I can fix this problem, any help or advice would be appreciated.

    Friday, March 16, 2007 7:23 PM

Answers

  •  DominicJudd wrote:

    for (siSprite = m_vSprites.begin(); siSprite != m_vSprites.end(); siSprite++)

    {

    delete (*siSprite);

    m_vSprites.erase(siSprite);

    siSprite--;

    }

    Try to remove this line(in bold), see if problem persists.

    Monday, March 19, 2007 6:41 AM
  • In short, it is a sort of logic problem that causing these assertions.

     DominicJudd wrote:

    With the line in bold included, it causes a problem at the same place as I originally had it, with the line commented out I get the same problem as I do in the other code without it.

    With the line in bold included:
    In the first time "iTestIterator--;" get executed, iTestIterator is point to the first element of vector, "iTestIterator--;" statement makes this iterator point to one element before the first element, whose behavior is undefined hence first assertion.

    With the line commented out:
    The vector is size 1, after the execute of statement "iTestVector.erase(iTestIterator);" its size becomes 0, this time iTestIterator is equal to "iTestVector.end(); ", so "iTestIterator++" in for loop will make the iTestIterator point to the second element after the last element of vector, which is also undefined hence second assertion.

    Be careful that erase container's elements in a loop like this is dangerous since container's size has changed when some elements has been erased and so that make the current iterator become illegal.

    To correct these errors, you need to improve your program's logic.

    Monday, March 26, 2007 7:18 AM

All replies

  •  DominicJudd wrote:

    for (siSprite = m_vSprites.begin(); siSprite != m_vSprites.end(); siSprite++)

    {

    delete (*siSprite);

    m_vSprites.erase(siSprite);

    siSprite--;

    }

    Try to remove this line(in bold), see if problem persists.

    Monday, March 19, 2007 6:41 AM
  • Thank you for the advice, I Commented out the line as suggested and unfortunately the program crashed while running in debug mode.

    First it asked for dbghook.c which I was able to find within the Microsoft Platform SDK subdirectories and the program tried to continue, however, immediately after that it asked for invarg.c which also seems to be unavailable, more ideas would be appreciated.

    Monday, March 19, 2007 2:29 PM
  • hello

    Could you explain a little about how can you tell it ask for a source file(dbghook.c , etc)? It sounds like you were stepping into dbghook.c, am I understanding right? If yes, use step over(F10) rather than step into(F11) when debugging, and see in exactly which line of code cause crashs. Also make a minimum sample code(if possible) that can reproduce this error and paste these sample code here, that will be a big approach to the solution.

    Tuesday, March 20, 2007 2:07 AM
  • After commenting out the line recomended and running the program, it detects a fatal error in the program and gives me the option to 'press break to debug or continue to terminate', when debugging the problem point seems to be within the Vector standard header in the following code

    _Myt& operator++()

    { // preincrement

    _SCL_SECURE_VALIDATE(this->_Mycont != NULL);

    _SCL_SECURE_VALIDATE_RANGE(_Myptr < ((_Myvec *)(this->_Mycont))->_Mylast);

    ++_Myptr;

    return (*this);

    }

    The Line in bold is the line it breaks at, at this point the last time I tested it I used step over (F10) and it claimed that the 'The source file is different from when the module was built. would you like to use it anyway?' selecting yes proceeds to open a file picker looking for  f:\rtm\vctools\crt_bld\self_x86\crt\src\dbghook.c

    I found this file within the Microsoft Platform SDK sub directories and chose it with the file picker, continuing the program with Step Over (F10) again and I get a report saying there is no source code for the selected location.

    I am working on creating a small program to reproduce this problem in simpler code, I'll post it as soon as I've managed to get it breaking in the same place.

    Wednesday, March 21, 2007 3:51 PM
  • The following code was added to a project created as a new win32 console application:

    // Vector Test.cpp : Defines the entry point for the console application.

    //

    #pragma comment(lib, "winmm.lib")

    #pragma comment(lib, "msimg32.lib")

    #include "stdafx.h"

    int main()

    {

    vector<int> iTestVector;

    // Reserve some storage space for the vector

    iTestVector.reserve(2);

    // add an integer into the vector

    iTestVector.push_back(1);

    // Test if the vector is half full

    if (iTestVector.size() >= (iTestVector.capacity() / 2))

    // If the vector is half full reserve double the capacity

    iTestVector.reserve(iTestVector.capacity() * 2);

     

    // Remove the Integers from the Vector

    vector<int>::iterator iTestIterator;

    for (iTestIterator = iTestVector.begin(); iTestIterator != iTestVector.end(); iTestIterator++)

    {

    iTestVector.erase(iTestIterator);

    iTestIterator--;

    }

    return 0;

    }

    With the line in bold included, it causes a problem at the same place as I originally had it, with the line commented out I get the same problem as I do in the other code without it.

    Minor Edit: I have the following code in the header file for using vectors:

    #include <vector>

    using namespace std;



     

    Friday, March 23, 2007 2:16 PM
  • In short, it is a sort of logic problem that causing these assertions.

     DominicJudd wrote:

    With the line in bold included, it causes a problem at the same place as I originally had it, with the line commented out I get the same problem as I do in the other code without it.

    With the line in bold included:
    In the first time "iTestIterator--;" get executed, iTestIterator is point to the first element of vector, "iTestIterator--;" statement makes this iterator point to one element before the first element, whose behavior is undefined hence first assertion.

    With the line commented out:
    The vector is size 1, after the execute of statement "iTestVector.erase(iTestIterator);" its size becomes 0, this time iTestIterator is equal to "iTestVector.end(); ", so "iTestIterator++" in for loop will make the iTestIterator point to the second element after the last element of vector, which is also undefined hence second assertion.

    Be careful that erase container's elements in a loop like this is dangerous since container's size has changed when some elements has been erased and so that make the current iterator become illegal.

    To correct these errors, you need to improve your program's logic.

    Monday, March 26, 2007 7:18 AM