Skip to content

Commit

Permalink
Avoid unaligned access to Shape_Type->width
Browse files Browse the repository at this point in the history
  • Loading branch information
th-otto committed Mar 24, 2024
1 parent 77e2da0 commit 984febc
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions common/getshape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ int Extract_Shape_Count(void const* buffer)
*=========================================================================*/
void* Extract_Shape(void const* buffer, int shape)
{
ShapeBlock_Type* block = (ShapeBlock_Type*)buffer;
// PG int numshapes; // Number of shapes
uint32_t offset; // Offset of shape data, from start of block
char* bytebuf = (char*)buffer;
Expand Down Expand Up @@ -242,7 +241,9 @@ int Get_Shape_Width(void const* shape)
{
Shape_Type* shp = (Shape_Type*)shape;

return le16toh(shp->Width);
uint16_t width;
memcpy(&width, &shp->Width, sizeof(width));
return le16toh(width);

} /* end of Get_Shape_Width */

Expand Down

0 comments on commit 984febc

Please sign in to comment.