P
P
Pavel Kaptur2016-02-18 14:31:54
C++ / C#
Pavel Kaptur, 2016-02-18 14:31:54

Why does warning C6386 occur?

there is this code that creates its own thread for each object from folderList

DWORD hThreadArraySize = sizeof(HANDLE);
  hThreadArraySize*=folderList.size();
  hThreadArray = (HANDLE*)VirtualAlloc(NULL, hThreadArraySize, MEM_COMMIT, PAGE_READWRITE);
        for (std::list<FOLDERDESCRIPTOR>::iterator it = folderList.begin(); it != folderList.end(); it++, i++)
  {
               hThreadArray[i] = (*it).hThread = CreateThread();
  }

And a code analyzer warning is issued on it
Warning C6386 Buffer overrun while writing to 'hThreadArray': the writable size is 'hThreadArraySize' bytes, but '8' bytes might be written.

Why does it occur and how to fix it? I checked all sizes, everything is fine. But what does he not like?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AtomKrieg, 2016-02-19
@AtomKrieg

LPVOID WINAPI VirtualAlloc(
  _In_opt_ LPVOID lpAddress,
  _In_     SIZE_T dwSize,     //Почему dwSize (hThreadArraySize) у вас тип DWORD, а не SIZE_T
  _In_     DWORD  flAllocationType,
  _In_     DWORD  flProtect
);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question