I like my code to be free for VS.NET and GCC, and I like to prepare 64-bit code.
Today I wrote a small module that deals with memory buffers and provides access to data through a file-style interface (for example, you can read bytes, write bytes, search, etc.).
I used size_t as the data type for the current position and reading size, since this is apparently the most natural choice. I review warnings, and it should work in 64-bit mode.
Just in case: My structure looks like this:
typedef struct { unsigned char * m_Data; size_t m_CurrentReadPosition; size_t m_DataSize; } MyMemoryFile;
The signature size_t apparently not defined in practice. Google code-search has proven this.
Now I have a dilemma: I want to check on add-ons with size_t for overflow, because I have to deal with user-provided data, and third-party libraries will use my code. However, to check for overflow, I must know the sign. This significantly affects the implementation.
So - how should I write such code in the platform and regardless of the compiler?
Is it possible to verify the signature of size_t at runtime or compile time? That would solve my problem. Or maybe size_t not a better idea in the first place.
Any ideas?
EDIT : I am looking for a solution for the C-language!
c integer-overflow size-t
Nils pipenbrinck
source share