Jump to content
  • Advertisement
Sign in to follow this  
SiS-Shadowman

Error "destination of memory copy is too small"

This topic is 4010 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I get a strange error when compiling a library for my engine. I don't know when it exactly started, I've just ignored it for the last weeks, but it still bugs me, because I want to know what goes wrong. This is a part of the ouput log of msvc 2005: Generating code e:\microsoft visual studio 8\vc\include\vector(1125) : warning C4789: destination of memory copy is too small Finished generating code The code around this line looks like this:
	void _Insert_n(iterator _Where,
		size_type _Count, const _Ty& _Val)
		{	// insert _Count * _Val at _Where

 #if _HAS_ITERATOR_DEBUGGING
		if (_Where._Mycont != this
			|| _Where._Myptr < _Myfirst || _Mylast < _Where._Myptr)
			_DEBUG_ERROR("vector insert iterator outside range");
 #endif /* _HAS_ITERATOR_DEBUGGING */

		_Ty _Tmp = _Val;	// in case _Val is in sequence <-- line 1125
		size_type _Capacity = capacity();

I'm no expert programmer, but why does it give that error? _Ty is the class, the template is based on, so why can't the temporary variable just hold a reference? I'm compiling this stuff on Windows Vista with MSVC2005. This message appears in release and debug builds. If you need more information, just say so :)

Share this post


Link to post
Share on other sites
Advertisement
Are you using arrays somewhere in your related code, and your array is defined as char[0] or something similar?

The MVS SC++L works, so there's no need to post that. Show your code that's using this.

Share this post


Link to post
Share on other sites
from ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_vccomp/html/5800c301-5afb-4af0-85c1-ceb54d775234.htm

Error Message
destination of memory copy is too small


Data whose length is known at compile time was copied into a data block whose size is also known at compile time and whose size is too small for the data, and where the copy was done by the intrinsic form of one of the following CRT functions:

strcpy

memset

memcpy, wmemcpy

Compiling with /Oi- or /Od will resolve this warning

-----------

It's likely the error is somewhere in your code where you're using a vector incorrectly. Look around for where you use vectors if the calling code is referenced in the error list and verify the objects and sizes are correct.

Share this post


Link to post
Share on other sites
Looks like you have intrinsic functions enabled and your copy constructor (for the user-defined type you're using with std::vector) is using either strcpy, memset, memcpy, or wmemcpy, their intrinsic forms. The exact meaning of the warning message code is here.

Share this post


Link to post
Share on other sites
Okay, I've searched the project for the use of vectors, and I found two different usages. One time, I just use a std::vector<mystruct>, the other time a std::vector<std::string>.
Since the latter is the newer code, I suppose this is the troublemaker.
What can I do to create an array of strings without provoking an error?

Share this post


Link to post
Share on other sites
Quote:
Original post by SiS-Shadowman
Okay, I've searched the project for the use of vectors, and I found two different usages. One time, I just use a std::vector<mystruct>, the other time a std::vector<std::string>.
Since the latter is the newer code, I suppose this is the troublemaker.
What can I do to create an array of strings without provoking an error?


Quote:
Original post by Antheus
Show your code that's using this.

Share this post


Link to post
Share on other sites

std::vector<std::string> dirs;
std::size_t n = 0;
std::size_t last = 0;
std::string fName = fname;
while(true)
{
n = fName.find( "/", last );
if( n >= fName.size() ) {
n = fName.find( "\\", last );
if( n >= fName.size() )
break;
}

dirs.push_back( fName.substr( 0, n + 1 ) );
last = n + 1;
}

for( std::vector<std::string>::iterator i = dirs.begin();
i != dirs.end(); i++ )
{
_mkdir( (*i).c_str() );
}

Share this post


Link to post
Share on other sites
That is the whole output from the log:

------ Neues Erstellen gestartet: Projekt: Library, Konfiguration: Release Win32 ------
Die Zwischen- und Ausgabedateien für das Projekt "Library" mit der Konfiguration "Release|Win32" werden gelöscht.
Kompilieren...
Resource.cpp
Registry.cpp
lua_lib.cpp
LUA.cpp
Textlog.cpp
e:\code\library\library\Textlog.h(20) : warning C4251: 'lib::CTextLog::m_File' : class 'std::basic_ofstream<_Elem,_Traits>' needs to have dll-interface to be used by clients of class 'lib::CTextLog'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
wildcard.cpp
.\wildcard.cpp(165) : warning C4996: 'strncpy' was declared deprecated
E:\Microsoft Visual Studio 8\VC\include\string.h(156) : see declaration of 'strncpy'
Message: 'This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
FindFile.cpp
Backup.cpp
Buffer.cpp
Archive.cpp
__int1024.cpp
StdCrypt.cpp
rc4.cpp
Bitmap.cpp
Misc.cpp
Debug.cpp
RAMInfo.cpp
OSInfo.cpp
e:\code\library\library\OSInfo.h(25) : warning C4251: 'lib::OSInfo::m_strDescription' : class 'std::basic_string<_Elem,_Traits,_Ax>' needs to have dll-interface to be used by clients of class 'lib::OSInfo'
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Ax=std::allocator<char>
]
FileVersionInfo.cpp
CPUInfo.cpp
Ressourcen werden kompiliert...
Verknüpfen...
Creating library E:\Code\Star Wars\Release\Library.lib and object E:\Code\Star Wars\Release\Library.exp
Generating code
e:\microsoft visual studio 8\vc\include\vector(1125) : warning C4789: destination of memory copy is too small
Finished generating code
zlib1.lib(zutil.obj) : warning LNK4049: locally defined symbol _malloc imported
zlib1.lib(zutil.obj) : warning LNK4049: locally defined symbol _free imported
Das Manifest wird eingebettet...
Das Buildprotokoll wurde unter "file://e:\Code\Library\Library\Release\BuildLog.htm" gespeichert.
Library - 0 Fehler, 6 Warnung(en)
========== Alles neu erstellen: 1 erfolgreich, Fehler bei 0, 0 übersprungen ==========

As you can see, there is no error above C4789
The warnings and errors reported above do not have anything to do with std::vector, so I don't know what exactly is wrong, since I am only using std::vector two different times, one on a struct and the second on the std::string.

Share this post


Link to post
Share on other sites
Quote:
Original post by SiS-Shadowman
wildcard.cpp
.\wildcard.cpp(165) : warning C4996: 'strncpy' was declared deprecated
E:\Microsoft Visual Studio 8\VC\include\string.h(156) : see declaration of 'strncpy'


Let's see that part, please.

Share this post


Link to post
Share on other sites
Here you go

bool wildcard::StartCmp(char *src,const char *cmp)
{
int len = (int)strlen(cmp);

int i=0;
for ( ;i<len && src != '*';++i)
if (src != cmp && src != '?')
return false;

if (i < len)
strncpy(src, src+i , strlen(src)-i+1);

return true;
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!