Skip to content

Commit

Permalink
Endian fixes for the shape attribute getter functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
isojalka authored Feb 8, 2023
1 parent 9ac94ac commit 51e3349
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions common/getshape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

#include "wwstd.h"
#include "shape.h"
#include "endianness.h"

/***************************************************************************
* Get_Shape_Size -- Fetch the size of the shape in memory. *
Expand Down Expand Up @@ -81,7 +82,7 @@ int Get_Shape_Size(void const* shape)
/*
-------------------------- Returns shape's size --------------------------
*/
return (shp->ShapeSize);
return le16toh(shp->ShapeSize);

} /* end of Get_Shape_Size */

Expand All @@ -106,7 +107,7 @@ int Get_Shape_Uncomp_Size(void const* shape)
{
Shape_Type* shp = (Shape_Type*)shape;

return (shp->DataLength);
return le16toh(shp->DataLength);

} /* end of Get_Shape_Uncomp_Size */

Expand Down Expand Up @@ -170,7 +171,7 @@ int Extract_Shape_Count(void const* buffer)
char const* bbuffer = (char const*)buffer;
uint16_t numshapes;
memcpy(&numshapes, bbuffer + offsetof(ShapeBlock_Type, NumShapes), sizeof(numshapes));
return (int)numshapes;
return (int)le16toh(numshapes);
} /* end of Extract_Shape_Count */

/***************************************************************************
Expand Down Expand Up @@ -214,6 +215,7 @@ void* Extract_Shape(void const* buffer, int shape)
/* Same as offset = block->Offsets[shape]; on arch that unaligned access
behaves well. */
memcpy(&offset, bytebuf + offsetof(ShapeBlock_Type, Offsets) + shape * sizeof(uint32_t), sizeof(uint32_t));
offset = le32toh(offset);

return (bytebuf + 2 + offset);

Expand All @@ -240,7 +242,7 @@ int Get_Shape_Width(void const* shape)
{
Shape_Type* shp = (Shape_Type*)shape;

return (shp->Width);
return le16toh(shp->Width);

} /* end of Get_Shape_Width */

Expand Down

0 comments on commit 51e3349

Please sign in to comment.