diff --git a/Cereal/Cereal/src/Database.h b/Cereal/Cereal/src/Database.h index f4818a9..e3f6837 100644 --- a/Cereal/Cereal/src/Database.h +++ b/Cereal/Cereal/src/Database.h @@ -73,7 +73,7 @@ namespace Cereal { } default: - __debugbreak(); break; + throw new std::invalid_argument("The version is not valid!"); break; } } @@ -101,7 +101,7 @@ namespace Cereal { break; default: - __debugbreak(); break; + throw new std::invalid_argument("The version is not valid!"); break; } return true; @@ -117,7 +117,7 @@ namespace Cereal { ret += sizeof(short) + name.length() + sizeof(int) + sizeof(short); break; default: - __debugbreak(); break; // Invalid version + throw new std::invalid_argument("The version is not valid!"); break; // Invalid version } for (const Object* obj : objects) diff --git a/Cereal/Cereal/src/Field.h b/Cereal/Cereal/src/Field.h index 8ece136..c9ece99 100644 --- a/Cereal/Cereal/src/Field.h +++ b/Cereal/Cereal/src/Field.h @@ -125,7 +125,7 @@ namespace Cereal { case DataType::DATA_FLOAT: setData(dataType, buffer.readBytes()); break; case DataType::DATA_DOUBLE: setData(dataType, buffer.readBytes()); break; case DataType::DATA_STRING: setData(dataType, buffer.readBytes()); break; - default: __debugbreak(); break; + default: throw new std::invalid_argument("The data type is not valid!"); break; } } diff --git a/Cereal/Cereal/src/Header.h b/Cereal/Cereal/src/Header.h index c4bd272..3955c7b 100644 --- a/Cereal/Cereal/src/Header.h +++ b/Cereal/Cereal/src/Header.h @@ -80,7 +80,7 @@ namespace Cereal { buffer.writeBytes(MAGIC_NUMBER); buffer.writeBytes((byte)databases.size()); - unsigned int offset = sizeof(short) + sizeof(byte) + (sizeof(unsigned int) * databases.size()); + unsigned int offset = sizeof(unsigned short) + sizeof(byte) + (sizeof(unsigned int) * databases.size()); for (unsigned int i = 0; i < databases.size(); i++) { diff --git a/Cereal/Cereal/src/Internal.h b/Cereal/Cereal/src/Internal.h index a770008..2a7e447 100644 --- a/Cereal/Cereal/src/Internal.h +++ b/Cereal/Cereal/src/Internal.h @@ -20,6 +20,22 @@ namespace Cereal { typedef unsigned char byte; + static_assert(sizeof(byte) == 1, "Invalid byte size!"); + + static_assert(sizeof(char) == 1, "Invalid char size!"); + static_assert(sizeof(short) == 2, "Invalid short size!"); + static_assert(sizeof(int) == 4, "Invalid int size!"); + static_assert(sizeof(long) == 4, "Invalid long size!"); + static_assert(sizeof(float) == 4, "Invalid float size!"); + static_assert(sizeof(double) == 8, "Invalid double size!"); + + static_assert(sizeof(unsigned char) == 1, "Invalid unsigned char size!"); + static_assert(sizeof(unsigned short) == 2, "Invalid unsigned short size!"); + static_assert(sizeof(unsigned int) == 4, "Invalid unsigned int size!"); + static_assert(sizeof(unsigned long) == 4, "Invalid unsigned long size!"); + static_assert(sizeof(unsigned long long) == 8, "Invalid unsigned long long size!"); + + enum Version { VERSION_1_0 = 0x0100, // first byte = major version, second = minor (revision)