Skip to content

Commit

Permalink
Fixed float and double reading/writing bug in Buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
marcizhu committed Dec 9, 2016
1 parent fd29317 commit 27f0d5f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Cereal/Cereal/src/Buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ namespace Cereal {
{
unsigned int x;

*(unsigned int*)&x = (unsigned int)data;
*(unsigned int*)&x = *(unsigned int*)&data;

writeBytes<unsigned int>(x);

Expand All @@ -159,7 +159,7 @@ namespace Cereal {
{
unsigned long long x;

*(unsigned long long*)&x = (unsigned long long)data;
*(unsigned long long*)&x = *(unsigned long long*)&data;

writeBytes<unsigned long long>(x);

Expand Down
6 changes: 3 additions & 3 deletions Cereal/Cereal/src/Reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace Cereal {

float result;

memcpy_s(&result, 4, &value, 4);
memcpy_s(&result, sizeof(float), &value, sizeof(float));

return result;
}
Expand All @@ -63,13 +63,13 @@ namespace Cereal {
{
unsigned long long value = src[pointer] << (sizeof(int) * 8 - 8);

for (int i = pointer; i < (int)pointer + (int) sizeof(float); i++)
for (int i = 0; i < (int) sizeof(double); i++)
{
value |= (src[pointer + i] << ((sizeof(int) * 8 - 8) - (i * 8)));
}

double result;
memcpy_s(&result, 4, &value, 4);
memcpy_s(&result, sizeof(double), &value, sizeof(double));

return result;
}
Expand Down
2 changes: 2 additions & 0 deletions Sandbox/Sandbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include <Cereal.h>

#include <src/Writer.h>

void gotoxy(int x, int y)
{
CONSOLE_SCREEN_BUFFER_INFO SBInfo;
Expand Down

0 comments on commit 27f0d5f

Please sign in to comment.