|
Which function is used in VC6.0 ? Is it sprintf() or sprintf_s() ?
If it is sprintf(), then nothing to wonder, becausee sprintfdoesnot check the output buffer size.
|
|
|
|
|
Member 9353776 wrote: sprintf_s(&buffer[offset],offset,"%s",Buffer);
Here you are stating your destination buffer has size 3 (parameter 2 of sprintf_s (see MSDN[^]). If the source buffer (namely Buffer ) contains a string with more than 3 characters then you get the assertion.
Veni, vidi, vici.
|
|
|
|
|
char buffer[50]
int offset =3;
char Buffer[250];
OR
char buffer[50]
int offset =3;
char Buffer[50];
Is working fine with VS6.0, but when the same code is compiled with VS2008 I am still getting the same error as mentioned above.
|
|
|
|
|
Short answer: You sprintf statement is plain wrong if 'it is working fine' maybe by accident.
Somewhat longer answer: If you have a 50 bytes buffer, why don't you pass 50 instead of 3 ? Why are you using the misleading name offset for passing a size?
Veni, vidi, vici.
|
|
|
|
|
First thing is that, trust the implementation made by Microsoft. This is a very primitive function and you will have to read the documentation first.
Second you can your strcpy_s or strcat_s (if you're concatenating). sprint_s is not really a choice string copy.
Third your strings must be null terminated.
To understand this better, I am illustrating this with a code example
char buffer[12]= {0};
int offset =3;
char Buffer[50] = "Hello World";
sprintf_s(buffer,sizeof(buffer), "%s", Buffer);
in the above example buffer has 12 character in legnth and Hello World String contains 11 characters + null terminated. Anything less than 12 character size will raise assertion buffer too small. for sprintf_s only the number of characters being copied only matters. not really the original size of the buffers.
-Sarath.
Rate the answers and close your posts if it's answered
|
|
|
|
|
I have fixed the issue,
I am very much thankful to all your replies
|
|
|
|
|
I can just find the BIOS offset(0xFE000)using SMBIOS structures,but do not know the detail of the info it disp in WinHex tool.
|
|
|
|
|
Take a look at some of these links[^].
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Hello. I'm currently extending an options risk application that makes use of Gunnar Bolle's neat little charting control. I'm trying to get a handle on the functionality by looking at the code but it would GREATLY speed things up if I could communicate with someone who is versed in the control. What I need to do is pretty basic; labeling, editing, scaling, etc. Any help would be greatly appreciated.
|
|
|
|
|
You could try posting a message in the forum at the end of the article so he sees it.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
I already tried that. I'm thinking of putting out an international APB.
|
|
|
|
|
I have the follow code :
CSize sizeDoc = pDoc->GetBitmapSize();
CDC MemDC, TempDC;
MemDC.CreateCompatibleDC(pDC);
TempDC.CreateCompatibleDC(pDC);
CBitmap* pOldBitmap = MemDC.SelectObject(&pDoc->GetBitmap());
pDC->SetStretchBltMode(HALFTONE);
TempDC.StretchBlt(0, 0, sizeLog.cx, sizeLog.cy, &MemDC, 0, 0, sizeDoc.cx, sizeDoc.cy, SRCCOPY);
pDC->StretchBlt(0, 0, sizeLog.cx, sizeLog.cy, &TempDC, 0, 0, sizeDoc.cx, sizeDoc.cy, SRCCOPY);
pDC->SelectObject(pOldBitmap);
and on view I see nothing ... what I'm doing wrong ? TempDC don't have the same structure like MemDC ? Because if I do so:
CSize sizeDoc = pDoc->GetBitmapSize();
CDC MemDC, TempDC;
MemDC.CreateCompatibleDC(pDC);
CBitmap* pOldBitmap = MemDC.SelectObject(&pDoc->GetBitmap());
pDC->SetStretchBltMode(HALFTONE);
pDC->StretchBlt(0, 0, sizeLog.cx, sizeLog.cy, &MemDC, 0, 0, sizeDoc.cx, sizeDoc.cy, SRCCOPY);
pDC->SelectObject(pOldBitmap);
everything it's ok ...
|
|
|
|
|
CSize sizeDoc = pDoc->GetBitmapSize();
CDC MemDC, TempDC;
MemDC.CreateCompatibleDC(pDC);
TempDC.CreateCompatibleDC(pDC);
CBitmap* pOldBitmap = MemDC.SelectObject(&pDoc->GetBitmap());
pDC->SetStretchBltMode(HALFTONE);
TempDC.StretchBlt(0, 0, sizeLog.cx, sizeLog.cy, &MemDC, 0, 0, sizeDoc.cx, sizeDoc.cy, SRCCOPY);
pDC->StretchBlt(0, 0, sizeLog.cx, sizeLog.cy, &TempDC, 0, 0, sizeDoc.cx, sizeDoc.cy, SRCCOPY);
pDC->SelectObject(pOldBitmap);
When a memory device context is created, GDI automatically selects a 1-by-1 monochrome stock bitmap for it. GDI output functions can be used with a memory device context only if a bitmap has been created and selected into that context.
Here TempDC is not attached to any Bitmap, and therefore GDI function StretchBlt will not draw to TempDC.
You have to create a Bitmap compatible to your DC, and attach the same to temperory memory DC.
CSize sizeDoc = pDoc->GetBitmapSize();
CDC MemDC, TempDC;
MemDC.CreateCompatibleDC(pDC);
TempDC.CreateCompatibleDC(pDC);
CBitmap* pOldBitmap = MemDC.SelectObject(&pDoc->GetBitmap());
pDC->SetStretchBltMode(HALFTONE);
HDC hdc = ::GetDC(NULL);
HBITMAP hScreenBmp = CreateCompatibleBitmap( hdc , nWidth, m_nImageHeight );
TempDC.SelectObject( hScreenBmp );
TempDC.StretchBlt(0, 0, sizeLog.cx, sizeLog.cy, &MemDC, 0, 0, sizeDoc.cx, sizeDoc.cy, SRCCOPY);
pDC->StretchBlt(0, 0, sizeLog.cx, sizeLog.cy, &TempDC, 0, 0, sizeDoc.cx, sizeDoc.cy, SRCCOPY);
pDC->SelectObject(pOldBitmap);
|
|
|
|
|
Thank you so much, is working now.
|
|
|
|
|
private:
PROCESSENTRY32 * m_proc;
char * m_filename;
bool m_stringupdated;
Process::Process()
{
m_proc = new PROCESSENTRY32;
m_proc->dwSize = sizeof(PROCESSENTRY32);
m_stringupdated = false;
m_filename = NULL;
}
Process::~Process()
{
delete m_proc;
if(m_filename)
delete [] m_filename;
}
Process * allo = new Process();
allo->~Process();
VLD reports:
Visual Leak Detector Version 2.2.3 installed.
WARNING: Visual Leak Detector detected memory leaks!
---------- Block 1 at 0x005A2100: 12 bytes ----------
Call Stack:
c:\users\jean\documents\visual studio 2012\projects\procenum\procenum\procenum.cpp (26): ProcEnum.exe!wmain + 0x7 bytes
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (533): ProcEnum.exe!__tmainCRTStartup + 0x19 bytes
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (377): ProcEnum.exe!wmainCRTStartup
0x760A33AA (File and line number not available): kernel32.dll!BaseThreadInitThunk + 0x12 bytes
0x76CF9EF2 (File and line number not available): ntdll.dll!RtlInitializeExceptionChain + 0x63 bytes
0x76CF9EC5 (File and line number not available): ntdll.dll!RtlInitializeExceptionChain + 0x36 bytes
Data:
48 21 5A 00 00 00 00 00 00 CD CD CD H!Z..... ........
Visual Leak Detector detected 1 memory leak (48 bytes).
Largest number used: 640 bytes.
Total allocations: 640 bytes.
Visual Leak Detector is now exiting.
The program '[10680] ProcEnum.exe' has exited with code 0 (0x0).
I'm freaking out guys I just don't see the leak ,Thanks in advance .
|
|
|
|
|
How many bytes allocated and pointed by m_filename?
|
|
|
|
|
it's not used ,its deallocating it anyway...
|
|
|
|
|
If the sizeof(PROCESSENTRY32) == 48, then I have found your leak.
|
|
|
|
|
not that either it's around 500~ bytes and I'm deallocating that too :/
|
|
|
|
|
I cant see any memory leak in the given code.
Please check memory leak without allocating memory Process.
|
|
|
|
|
Visual Leak Detector Version 2.2.3 installed.
No memory leaks detected.
Visual Leak Detector is now exiting.
The program '[9248] ProcEnum.exe' has exited with code 0 (0x0).
Not a false positive.
|
|
|
|
|
You are explicitly calling the destructor. This will free the allocated memory for the members but not the object itself. You should use delete instead:
delete allo;
Or you may use auto delete (using an additional member var):
Process::~Process()
{
delete m_proc;
if(m_filename) delete [] m_filename;
if (m_bAutoDelete)
delete this;
}
|
|
|
|
|
that pretty much solved me the problem
something to note
delete still calls the destructor.
so the auto delete code that you provided will cause an exception.
Process::~Process()
{
if(m_bDeallocated)
return;
delete m_proc;
delete [] m_filename;
m_bDeallocated = true;
if (m_bAutoDelete)
delete this;
}
|
|
|
|
|
Yes, you are right. That would result in a recursion. My code lacks resetting the m_bAutoDelete variable. It must be:
Process::~Process()
{
if (m_bAutoDelete)
{
m_bAutoDelete = false;
delete this;
}
else
{
delete m_proc;
delete [] m_filename;
m_proc = NULL;
m_filename = NULL;
}
}
However, this is not a good solution because the destructor is called twice and this will fail if the object wasn't allocated using new .
|
|
|
|
|
thank you and the reply, I learned something for this question. thanks again!
|
|
|
|
|