Compiler errors with Visual Studio 2017
Cross22 opened this issue · 3 comments
It looks like VS2017 does not like the pointer casts. E.g. for the 16-bit case I get
Error C4789 buffer 'n' of size 1 bytes will be overrun; 1 bytes will be written starting at offset 1
case 2: //16-bit
((uint8_t*)&n)[0] = ((uint8_t*)&b)[1];
((uint8_t*)&n)[1] = ((uint8_t*)&b)[0]; // <--
Hmm… thanks for the heads-up.
I did a search on C4789 and it looks like Visual Studio trying to detect buffer overruns, and in this case we get a false positive.
Their suggestion is to write #pragma
statements to get around it, so that's what I'll suggest here…
So try adding the following code before the Swap
method in tEndianBase
:
#pragma(push)
#pragma warning ( disable : 4789 )
And add the following code after the Swap
method:
#pragma(pop)
And let me know if that works. (I don't currently have a Windows / Visual Studio environment in front of me to check.)
I think I'd have to wrap those with #if _MSC_VER
/ #endif
to ensure it compiles on other platforms, so I'll wait until I can test this before I make a new commit.
That's what I did and it seems to work.
Okay, this is fixed in the repo with the latest commit. Thanks for reporting it.