« first day (1191 days earlier)      last day (1665 days later) » 

4:45 AM
@PeterT in the cmakelist they have option to specify openjpeg WITH_OPENJPEGINC:PATH=WITH_OPENJPEGINC-NOTFOUND
i am not sure why this option is there
 
 
9 hours later…
2:12 PM
does someone think this is a problem?
	string str("abc");
	const char* str2 = "abcdef";
	memcpy((void*)str.c_str(), str2, 6);

	string tmp(str.c_str());
	str = tmp;
will this cause heap corruption, maybe not now, but maybe when str2 is very long?
 
2:28 PM
yes that is undefined behavior when the capacity of str is less than the length of str2
but std::string has various ways to overwrite the contents
 
 
2 hours later…
4:35 PM
@DexterLiu Yes, it's UB. No, that doesn't strike me as any loss. Why would you want to use memcpy instead of just str = str2; string tmp = str;?
 
5:05 PM
Very good question. Because actually in the place of memcpy, I have a WIN API function, which need a char* as parameter. But for certain reason I have to have a wrapper outside the WIN API function, with string as parameter.
So I made somehow strange coding like this:
LSTATUS WinRegistryInternalFunctions::RegEnumKeyW(HKEY hKey, DWORD dwIndex, std::wstring& lpName, DWORD cchName)
{
LSTATUS status;
if ((status = ::RegEnumKeyW(hKey, dwIndex, &lpName[0], cchName)) == ERROR_SUCCESS)
{
lpName = lpName.c_str();
}

return status;
}
this wstring later will be pushed to another vector
 
@DexterLiu that is some serious undefined behavior
 
I would really stop with the "if(a=b)" that's rarely how people read that
even if the code is shorter
 
@Mgetz It is, but since we have a MAX length for wstring, so I defined the wstring with MAX lenght before sending it to WIN API.
 
@DexterLiu cchName is not connected to lpName
thus they have no guarantee to be linked
lpName.length() is safe.
 
you are right cchName is not(really) connected with lpName, it is a MAX length for lpName.
 
5:16 PM
in which case that's UB if lpName is passed in and has not already been initialized to that length
 
It has been ;) At first i didn't, and it gave me a heap corruption.
How does lpName.length() work under the hood? If it is the same mechanism with c_str() then they share the same mechanism.
BTW, I do not know how length() can work, without using reading until the \0 method
 
@DexterLiu it's statically stored?
you really should read how std::string works
 
Yes
 
if you set the length of the string then the string is that length regardless of content
 
Haha. You are right. I never really did it fully ..
i am reading
But, lpName.length() is not what I want. i just wanna do a wrapper for WIN API, and WIN API itself is not safe, so its not safe ;)
 
5:48 PM
@DexterLiu no WinAPI can be safe if you use it correctly
if you wrap it incorrectly expect pain
 

« first day (1191 days earlier)      last day (1665 days later) »