|
TOX,
i too got "CodeProject".. y no error is displayed?
V
-- modified at 7:32 Monday 29th August, 2005
|
|
|
|
|
yes, i understood that point. did you visit the link to the msdn i provided ?
strcpy() doesn't check for sufficient space in strDestination before copying strSource...
TOXCCT >>> GEII power [toxcct][VisualCalc]
-- modified at 7:34 Monday 29th August, 2005
|
|
|
|
|
|
char *strcpy( char *strDestination, const char *strSource );
The strcpy function copies strSource, including the terminating null character, to the location specified by strDestination. No overflow checking is performed when strings are copied or appended.
Have a look at the strlen() function.
Regards
We can do no great things, only small things with great love. - Mother Theresa
|
|
|
|
|
To complete the previous answers:
It will perhaps output 'Codeproject' but you cannot be sure because strcpy is copying the charcters outside the bounds of t2 (so in 'unprotected memory'). So, this memory is not 'locked' and your program can write other things in it. Even worse, because you are writing outside the bounds of t2, it may be that you write on some memory allocated for another variable, thus, erasing it's value that can lead to really baaaaaad things (like your variable changed magically)
|
|
|
|
|
cedric moonen wrote:
Even worse, because you are writing outside the bounds of t2, it may be that you write on some memory allocated for another variable, thus, erasing it's value
cedric,
if the other variable is declared ,as u said it could reside only in 'protected memory' then how will it(unsure strcpy!) overwrite on a content which is in protected memory?.. plz expln
Thanx
V
-- modified at 7:46 Monday 29th August, 2005
|
|
|
|
|
Sorry, protected was not really the good word. What I meant is memory allocated for another variable. strcpy will never check 1) that it writes still in the bounds of the string 2) if the memory it writes to is already allocated or not.
When you declare a variable, memory is allocated for it to holds its value. So if something write at this location in memory, the value of the variable will altered.
|
|
|
|
|
so by no way u can assure that a properly declared variable can never get its value corrupted? so sad.. .. anyway.. thank you so much
V
|
|
|
|
|
t1 and t2 are stack variables. Your allocation makes the compiler to reserve memory on the stack for t1 and t2.
The order of the allocation is undefined (I think).
So if you are lucky, it the stack allocation starts with t2, followed by t1. You copy the content of t1 to t2, including the terminating \0, and nothing happens. Output will be "Codeproject". (If you output t1, it will be "eproject").
If it´s allocated the other way around, it will still output "Codeproject", but your program will likely go bananas when the function terminates, due to the corrupted stack. (The stack also contains the address to return to, usually the address to the function that called the present function).
There are a lot of articles about what´s on the stack, written by people with far more knowledge on the subject than myself. If you want accurate info, pls. read those articles.
|
|
|
|
|
Depends on what you do after the code provided ... all after the third character can be overwritten at any time so, this data, is unsecured.
... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.
|
|
|
|
|
I have a tooltip defined for system tray icon. I am going to set the timeout for display using uTimeout member. But time out never happens. Any idea?
|
|
|
|
|
Does anyone know if there is an SQL server for development purposes for free? I don’t care if it is limited to a trivial number of entries. What I need to do is define some tables, put in some data (a trivial amount) and then beat on it with my code in C++. In the actual site there is a real SQL server which will do real work, but I need something on my local disk for testing purposes.
Thanks,
Ilan
|
|
|
|
|
Thanks,
I found it myself.
|
|
|
|
|
hi i have a promblem that i have a string "首YはYO二OK亜KM。M"
i want get the & of head but i can't getting the right~
like this:
CString m_str="首YはYO二OK亜KM。M";
wchar_t *m_T=(LPWSTR)_bstr_t(m_str);
wchar_t m_tem=*m_T;
fontOld=pDC->SelectObject(pFont);
pDC->TextOut(rc.left+m_Width,rc.top+m_Depth,&m_tem);
but it display 首???????? i only want 首
thank in advance very much.
nothing
|
|
|
|
|
why not you try char array ? so that u can take the particular item .. m_tem[1];
thanx
V
|
|
|
|
|
ebinaini wrote:
wchar_t m_tem=*m_T;
wchar_t m_tem=m_T[0];
.. maybe, so that your m_tem is really only one char wide.
BTW, there must be better ways (meaning safer ways) to do this :
ebinaini wrote:
wchar_t *m_T=(LPWSTR)_bstr_t(m_str);
~RaGE();
|
|
|
|
|
TextOut displays a string, not a character. Passing &m_tem , TextOut still treats it as a string and, as such, is exactly the same as m_T .
By the way, as has been alluded, CString doesn't like to be messed with internally like you might be trying. Use a char array instead, or you're going to blow something up later.
Bob Ciora
|
|
|
|
|
I have a dialog that use to send data using IP address. The dialog include a IP address box to key in the IP address which is the destination IP address. It also have a send button that when I click on it, it will send the data to the destination that I key in the IP address box. Beside that, the dialog also include some button that have their name such as open door, close door, on aircon etc. When I click on those button, it will automatic send the button name to the destination.
This dialog just add all those button but did not do the program inside the dialog. So the dialog cannot work exactly what I mention above. I don't know how to do the program for the send button and the IP address box which is when I key in the destination IP address and the message that I want to send and last click on the send button, it will send the message. thank you very much if somebody can help.
|
|
|
|
|
Hi,
I have a problem with using a path. I have to obtain the program files' path programatically, therefore I use this function.
CString PFPath;
SHGetSpecialFolderPath(NULL,PFPath.GetBuffer(_MAX_PATH),
CSIDL_PROGRAM_FILES, FALSE);
MessageBox(PFPath);
and the message box says:
C:\Program Files
I need to add something at the end of this string and then i try to use it in another function which needs the paths in double back slashes like:
"C:\\Program Files"
Then I try to do a conversion in PFPath in order to double the backslashes to change from
"C:\Program Files" to "C:\Program Files"
int i=0;
i = PFPath.Find("\\",i);
while( i>-1 )
{
CString found;
found.Format("Backslash found at index: %d",i);
MessageBox(found);
PFPath.Insert(i,(CString)"\\");
MessageBox(PFPath);
i += 2;
i = PFPath.Find("\\",i);
}
if(i==-1)
MessageBox("No more backslashes");
MessageBox(PFPath);
The message box output of this path is:
Backslash found at index: 2
\
No more backslashes
\
As seen, the insert function turned the whole string into a single backslash instead of inserting one.
CString WholePath = PFPath + (CString)"\\some_folder\\myfile.exe";
SHELLEXECUTEINFO shellInfo;
...
shellInfo.lpFile = WholePath;
::ShellExecuteEx(&shellInfo);
The conversion cannot be done properly, and shellInfo.lpFile needs double slashes. Therefore ShellExecuteEx cannot receive the path.
I have also tried the '\' conversion issue with CString::Replace ; CString::left, CString::Right and concetanation with operator + . Now I'm almost convinced that it is not possible to do it with the CString class.
Is there any other way to convert the '\' to '\\'?
Regards and thanks in advance,
Caykahve
-- modified at 5:49 Monday 29th August, 2005
|
|
|
|
|
Hi,
if you want to get the path of your application, just access your
theApp.m_pszHelpFilePath member. Its extension is "hlp". Just cahnge it to "exe".
Regards
We can do no great things, only small things with great love. - Mother Theresa
|
|
|
|
|
It's not my application actually.. There might be several applications whose "theApp" I don't have.
|
|
|
|
|
Sorry,
I missed the point. If your want to wrap your path name, try something like that:
CString getWrapped(const CString& Text, char Esc)
{
CString buffer;
int size = Text.GetLength();
buffer += '"';
for(int i = 0; i < size; i++)
{
char c = Text[i];
if ((c == '"') || (c == Esc))
{
buffer += Esc;
}
buffer += c;
}
buffer += '"';
return buffer;
}
CString test = getWrapped(path, '\\');
Is this your question?
Regards
We can do no great things, only small things with great love. - Mother Theresa
|
|
|
|
|
The example I posted recently was previously developed for the std::string class.
If you are just using CString objects wrapping is even easier:
CString test;
test += "\"";
test += path;
test += "\"";
test.Replace("\\", "\\\\");
Regards
We can do no great things, only small things with great love. - Mother Theresa
|
|
|
|
|
I do not want to put quotation marks to both ends of the text.
I want to convert a string (i.e. CString) like C:\Program Files to C:\\Program Files - which is doubling the back slashes...
Regards
|
|
|
|
|
Ok, that's a one-liner
If you have
CString test("C:\\Program Files");
just call
test.Replace("\\", "\\\\");
Regards
We can do no great things, only small things with great love. - Mother Theresa
|
|
|
|