denver2020 (222) Hi all The program below executes OK but getting one warning C6386 as shown below: "warning C6386: Buffer overrun while writing to 'df.m_Dats': the writable size is '(unsigned __int64 size_t)*32' bytes, but '64' bytes might be written." Any idea how to fix this? Is this vs2019 compiler bug and a known issue?
Last edited on Ganado (6812) I doubt it's a vs2019 compiler bug, especially without more evidence. <Edit: As seeplus mentioned, sometimes intellisense can show errors, and it may be strict or give false positives, but it still might point to a possible improvement.> You need to show a minimal reproducible example. The following uses your code verbatim, but produces no warnings at warning level 4:
#include <cstdint> #include <map> using std::uint32_t; using UID = int; struct Data { UID m_UID; }; struct Key { Key& operator=(const Data& data) { return *this; } }; struct Dataframe { Key* m_Dats; uint32_t m_NumDats; }; int main() { int dataidx = 0; std::map<UID, Data> uidToDraw; uidToDraw[0] = { 0 }; ////////////////// Dataframe df; df.m_Dats = new Key[uidToDraw.size()]; df.m_NumDats = (uint32_t)uidToDraw.size(); uint32_t keyid = 0; for (auto ti = uidToDraw.begin(); ti != uidToDraw.end(); ++ti) { Data frame; frame.m_UID = ti->first; df.m_Dats[dataidx++] = frame; } //////////////////// }
If I had to guess? It's that cast to (uint32_t) from size_t (64-bit). Or, it's complaining about how dataidx is only 32-bit. Last edited on seeplus (6594) Is this a build warning or an intellisense warning? denver2020 (222) I was Running Code Analysis for C/C++ from VS2019 and ended up with this warning message, though my program executes OK. i am trying to figure out what went wrong in my code. Have updated above code and warning message occured at line 27: df.m_Dats[ dataidx++ ] = frame; Last edited on AbstractionAnon (6954) To make any kind of intelligent guess at what' might be the problem, you should include the following in your code snippet: - Declaration of Dataframe. - Declaration of Key - Declaration of uidToDraw - Declaration of Data denver2020 (222) I have added those declarations in the code above. Please check it. salem c (3700) Still a rubbish attempt at http://sscce.org/
12345678
for ( uint32_t f=0;f<NumFrames;f++ ) { df.m_Dats = new Data[ uidToDraw.size() ]; for ( auto ti = uidToDraw.begin(); ti != uidToDraw.end(); ++ti ) { df.m_Dats[ dataidx++ ] = frame; } }