GetBuffer(-1) Assert Error
-
lundi 16 avril 2012 08:19
Hi,
When executing unit tests with GetBuffer(-1) in the code of the dll that wil be tested i get the next error:
Assert.Fail failed. System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception.
The code is:
fpExport = fopen(csExportFile.GetBuffer(-1), "w+b");
When i change the ...GetBuffer(-1) to ...GetBuffer() i get no error. Apparently -1 in GetBuffer was used before when the length of the CString was unknown. My project has 313 positions where GetBuffer(-1) is used, and i don't want to change the code right now. So is there another possebility to avoid the assert error, a project setting maybe?
P.s. i use Visual Studio 2010 Premium.
Regards,
Programmer Leon
Toutes les réponses
-
mardi 17 avril 2012 08:37Modérateur
Hi Leon,
Thank you for posting in the MSDN forum.
The code is:
fpExport = fopen(csExportFile.GetBuffer(-1), "w+b");
I’m not very sure this is related to your class method or this unit tests. Do you mean that this line code is in your unit test method? If so, did you change anything when the unit test is created automatically?
Assert.Fail failed. System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception.
Since it is hard for us to repro this issue, it would be better if you could share us a simple project. We will check it in our computer.
Please attach your Visual Studio project, you can upload it to the sky driver, and then share the download link in your post.
If there's any concern, please feel free to let us know.
Best Regards,
Jack Zhai [MSFT]
MSDN Community Support | Feedback to us
-
mardi 17 avril 2012 10:25
Hi Jack,
The ...GetBuffer(-1) code in not in the unit test method but in the application dll that i'm testing.
Best Regards,
ProgrammerLeon
-
mardi 17 avril 2012 11:51
Hi Jack,
I posted the project 'ExtendedMath_Unmanaged.zip' on sky driver. When you run the unit tests you will see that TestFibonacci2 will generate an error as i described in this thread.
Best Regards,
ProgrammerLeon
-
mercredi 18 avril 2012 02:03Modérateur
Hi Leon,
Could you share us the download link in your post? So we could download and check it.
Best Regards,
Jack Zhai [MSFT]
MSDN Community Support | Feedback to us
-
mercredi 18 avril 2012 06:52
Hi Jack,
The link is https://skydrive.live.com/#cid=2677F188C9EB54D8
I hope that works, i'm not yet familiar with sky driver.
Regards,
ProgrammerLeon
-
mercredi 18 avril 2012 09:12Modérateur
Hi Leon,
It seems that I couldn’t download it, but you could send your project to jackzhai at Hotmail dot com.
Best Regards,
Jack Zhai [MSFT]
MSDN Community Support | Feedback to us
-
jeudi 19 avril 2012 09:17
Hi Jack,
I've send the project yesterday to you.
Regards,
ProgrammerLeon
-
vendredi 20 avril 2012 04:36Modérateur
Hi Leon,
Sorry for my delay.
I try to run this test and get the same result. But I’m sure that it is related to your C++ class method, it is not a unit test issue.
fpExport = fopen (csExportFile.GetBuffer(A), "w+b");
It seems that if the int value A>=0 or use fpExport = fopen (csExportFile.GetBuffer(), "w+b")
, the unit test will be passed. I’m not a C++ expert, but I did some research about this issue, it seems that “GetBuffer (XXX)”returns a pointer to the internal character buffer for the CString object. If possible, you could check this article:
http://msdn.microsoft.com/en-us/library/kt26tkzx.aspx. I'm afraid that CSimpleStringT::GetBuffer() should not accept negative numbers for the length. We should throw an exception when negative lengths are passed in. This can hide potential buffer overrun problems.
About this issue, if possible, you could try to use the GetBuffer() instead of the GetBuffer(-1), I know it is not a good solution, but you could submit this feedback to Microsoft Connect feedback portal: http://connect.microsoft.com, Microsoft engineers will evaluate them seriously. Thanks for your understanding.
Best Regards,
Jack Zhai [MSFT]
MSDN Community Support | Feedback to us
- Modifié Jack Zhai - MSFTMicrosoft Contingent Staff, Moderator vendredi 20 avril 2012 08:07
- Proposé comme réponse Jack Zhai - MSFTMicrosoft Contingent Staff, Moderator vendredi 20 avril 2012 08:26
- Marqué comme réponse Jack Zhai - MSFTMicrosoft Contingent Staff, Moderator lundi 23 avril 2012 01:42
-
vendredi 20 avril 2012 08:22
Hi Jack,
Thanks for the reply.
GetBuffer() should also work, because if i read the article the default parameter for ReadBuffer(minimum length) is already -1, so ReadBuffer(-1) is not neccesary.
Regards,
ProgrammerLeon

