From 565710d4c9ad45a63f6a7906bee9f48ae92fa9c9 Mon Sep 17 00:00:00 2001 From: vladislavbelov Date: Sat, 13 Feb 2021 23:25:41 +0000 Subject: [PATCH] Fixes UB in shared_ptr usage of an array. Refs #5288 Reported By: PVS-Studio This was SVN commit r24905. --- source/graphics/MapIO.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/source/graphics/MapIO.cpp b/source/graphics/MapIO.cpp index 26bff06db0..66c24df687 100644 --- a/source/graphics/MapIO.cpp +++ b/source/graphics/MapIO.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2021 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -20,6 +20,7 @@ #include "MapIO.h" #include "graphics/Patch.h" +#include "lib/allocators/shared_ptr.h" #include "lib/file/file.h" #include "lib/file/vfs/vfs_path.h" #include "lib/os_path.h" @@ -51,7 +52,9 @@ Status LoadHeightmapImageOs(const OsPath& filepath, std::vector& heightmap) size_t fileSize = lseek(file.Descriptor(), 0, SEEK_END); lseek(file.Descriptor(), 0, SEEK_SET); - shared_ptr fileData = shared_ptr(new u8[fileSize]); + shared_ptr fileData; + RETURN_STATUS_IF_ERR(AllocateAligned(fileData, fileSize, maxSectorSize)); + Status readvalue = read(file.Descriptor(), fileData.get(), fileSize); file.Close();