Skip to content

Commit

Permalink
Merge pull request assimp#2664 from assimp/new_aistringsize
Browse files Browse the repository at this point in the history
Ensure that the aiString lenght is 4 bytes independent which platform…
  • Loading branch information
kimkulling authored Sep 22, 2019
2 parents aeecc17 + 06eb199 commit 87004aa
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 20 deletions.
4 changes: 4 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ matrix:
image:
- Visual Studio 2015
- Visual Studio 2017
- MinGW

platform:
- Win32
Expand All @@ -26,10 +27,13 @@ configuration: Release
install:
- set PATH=C:\Ruby24-x64\bin;%PATH%
- set CMAKE_DEFINES -DASSIMP_WERROR=ON
- if [%COMPILER%]==[MinGW] set PATH=C:\MinGW\bin;%PATH%
- if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2015" set CMAKE_GENERATOR_NAME=Visual Studio 14 2015
- if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2017" set CMAKE_GENERATOR_NAME=Visual Studio 15 2017
- if "%platform%"=="x64" set CMAKE_GENERATOR_NAME=%CMAKE_GENERATOR_NAME% Win64
- cmake %CMAKE_DEFINES% -G "%CMAKE_GENERATOR_NAME%" .
# Rename sh.exe as sh.exe in PATH interferes with MinGW
- rename "C:\Program Files\Git\usr\bin\sh.exe" "sh2.exe"
- set PATH=%PATH%;"C:\\Program Files (x86)\\Inno Setup 5"
- ps: Invoke-WebRequest -Uri https://download.microsoft.com/download/5/7/b/57b2947c-7221-4f33-b35e-2fc78cb10df4/vc_redist.x64.exe -OutFile .\packaging\windows-innosetup\vc_redist.x64.exe
- ps: Invoke-WebRequest -Uri https://download.microsoft.com/download/1/d/8/1d8137db-b5bb-4925-8c5d-927424a2e4de/vc_redist.x86.exe -OutFile .\packaging\windows-innosetup\vc_redist.x86.exe
Expand Down
18 changes: 1 addition & 17 deletions code/Material/MaterialSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,23 +545,7 @@ aiReturn aiMaterial::AddProperty (const aiString* pInput,
unsigned int type,
unsigned int index)
{
// We don't want to add the whole buffer .. write a 32 bit length
// prefix followed by the zero-terminated UTF8 string.
// (HACK) I don't want to break the ABI now, but we definitely
// ought to change aiString::mLength to uint32_t one day.
if (sizeof(size_t) == 8) {
aiString copy = *pInput;
uint32_t* s = reinterpret_cast<uint32_t*>(&copy.length);
s[1] = static_cast<uint32_t>(pInput->length);

return AddBinaryProperty(s+1,
static_cast<unsigned int>(pInput->length+1+4),
pKey,
type,
index,
aiPTI_String);
}
ai_assert(sizeof(size_t)==4);
ai_assert(sizeof(ai_uint32)==4);
return AddBinaryProperty(pInput,
static_cast<unsigned int>(pInput->length+1+4),
pKey,
Expand Down
2 changes: 1 addition & 1 deletion code/glTF/glTFImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ void glTFImporter::ImportMeshes(glTF::Asset& r)

aim->mName = mesh.id;
if (mesh.primitives.size() > 1) {
size_t& len = aim->mName.length;
ai_uint32& len = aim->mName.length;
aim->mName.data[len] = '-';
len += 1 + ASSIMP_itoa10(aim->mName.data + len + 1, unsigned(MAXLEN - len - 1), p);
}
Expand Down
2 changes: 1 addition & 1 deletion code/glTF2/glTF2Importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ void glTF2Importer::ImportMeshes(glTF2::Asset& r)
aim->mName = mesh.name.empty() ? mesh.id : mesh.name;

if (mesh.primitives.size() > 1) {
size_t& len = aim->mName.length;
ai_uint32& len = aim->mName.length;
aim->mName.data[len] = '-';
len += 1 + ASSIMP_itoa10(aim->mName.data + len + 1, unsigned(MAXLEN - len - 1), p);
}
Expand Down
7 changes: 6 additions & 1 deletion include/assimp/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <stddef.h>
#include <string.h>
#include <limits.h>
#include <stdint.h>

// Our compile configuration
#include "defs.h"
Expand All @@ -65,11 +66,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "matrix4x4.h"
#include "quaternion.h"

typedef int32_t ai_int32;
typedef uint32_t ai_uint32 ;

#ifdef __cplusplus
#include <cstring>
#include <new> // for std::nothrow_t
#include <string> // for aiString::Set(const std::string&)


namespace Assimp {
//! @cond never
namespace Intern {
Expand Down Expand Up @@ -379,7 +384,7 @@ struct aiString
/** Binary length of the string excluding the terminal 0. This is NOT the
* logical length of strings containing UTF-8 multi-byte sequences! It's
* the number of bytes from the beginning of the string to its end.*/
size_t length;
ai_uint32 length;

/** String buffer. Size limit is MAXLEN */
char data[MAXLEN];
Expand Down

0 comments on commit 87004aa

Please sign in to comment.