Click here to Skip to main content
16,004,924 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: File Handaling Pin
Nishad S25-Oct-07 19:17
Nishad S25-Oct-07 19:17 
AnswerRe: File Handaling Pin
Paresh Chitte25-Oct-07 18:27
Paresh Chitte25-Oct-07 18:27 
Question(MFC42D.DLL): 0xC0000005: Access Violation. Pin
riteshsv25-Oct-07 17:37
riteshsv25-Oct-07 17:37 
AnswerRe: (MFC42D.DLL): 0xC0000005: Access Violation. Pin
Roger Stoltz25-Oct-07 22:44
Roger Stoltz25-Oct-07 22:44 
QuestionRe: (MFC42D.DLL): 0xC0000005: Access Violation. Pin
David Crow26-Oct-07 3:08
David Crow26-Oct-07 3:08 
AnswerRe: (MFC42D.DLL): 0xC0000005: Access Violation. Pin
Hamid_RT26-Oct-07 7:18
Hamid_RT26-Oct-07 7:18 
QuestionAccess unallocated memory... Pin
nmhuy25-Oct-07 16:20
nmhuy25-Oct-07 16:20 
AnswerRe: Access unallocated memory... Pin
Roger Stoltz25-Oct-07 22:42
Roger Stoltz25-Oct-07 22:42 
nmhuy wrote:
So the MyString object can access unallocated memory. Does it safe?


As long as you don't write to the memory you haven't allocated, you're fine as long as strlen() finds a '\0' char within the virtual address space assigned to the process.
You won't get an access violation by reading addresses on the heap even if the memory hasn't been allocated.


nmhuy wrote:
How can we solve this problem?


Well, it depends on how you want it to work.
Probably you can guess a maximum length of the strings and provide that as a default parameter to the constructor, e.g:
MyString( const char* pStr, int nMaxLength = 256 );

If the calculated length of the string exceeds the nMaxLength you could either treat is as an error and not copy the string and possibly throw an exception, or only copy nMaxLength chars of it. You would also have the possibility to make a new guess for the maximum string length for each string object constructed if you need to.

BTW, in your example you've declared the length member as a pointer to an integer...
I assume that it's really an integer in your code.


"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"High speed never compensates for wrong direction!" - unknown

AnswerRe: Access unallocated memory... Pin
nmhuy26-Oct-07 7:19
nmhuy26-Oct-07 7:19 
Questionvb.net to c++ Pin
vikrant kpr25-Oct-07 15:37
vikrant kpr25-Oct-07 15:37 
AnswerRe: vb.net to c++ Pin
Naveen25-Oct-07 15:49
Naveen25-Oct-07 15:49 
GeneralRe: vb.net to c++ Pin
vikrant kpr25-Oct-07 20:35
vikrant kpr25-Oct-07 20:35 
QuestionRe: vb.net to c++ Pin
Hamid_RT25-Oct-07 20:40
Hamid_RT25-Oct-07 20:40 
AnswerRe: vb.net to c++ Pin
vikrant kpr25-Oct-07 20:45
vikrant kpr25-Oct-07 20:45 
AnswerRe: vb.net to c++ Pin
JudyL_MD26-Oct-07 3:13
JudyL_MD26-Oct-07 3:13 
GeneralRe: vb.net to c++ Pin
vikrant kpr26-Oct-07 5:39
vikrant kpr26-Oct-07 5:39 
GeneralRe: vb.net to c++ Pin
JudyL_MD26-Oct-07 5:48
JudyL_MD26-Oct-07 5:48 
QuestionHow does CArray work? Pin
acerunner31625-Oct-07 14:25
acerunner31625-Oct-07 14:25 
AnswerRe: How does CArray work? Pin
Naveen25-Oct-07 15:45
Naveen25-Oct-07 15:45 
AnswerRe: How does CArray work? Pin
Mark Salsbery26-Oct-07 6:42
Mark Salsbery26-Oct-07 6:42 
GeneralRe: How does CArray work? Pin
acerunner31626-Oct-07 9:10
acerunner31626-Oct-07 9:10 
GeneralRe: How does CArray work? Pin
Mark Salsbery26-Oct-07 9:19
Mark Salsbery26-Oct-07 9:19 
GeneralRe: How does CArray work? Pin
acerunner31626-Oct-07 9:30
acerunner31626-Oct-07 9:30 
GeneralRe: How does CArray work? Pin
Mark Salsbery26-Oct-07 9:34
Mark Salsbery26-Oct-07 9:34 
AnswerRe: How does CArray work? Pin
Nelek29-Oct-07 4:06
protectorNelek29-Oct-07 4:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.