microsoft / DirectXMath

DirectXMath is an all inline SIMD C++ linear algebra library for use in games and graphics apps

Home Page:https://walbourn.github.io/introducing-directxmath/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Replace malloc.h with stdlib.h

Cryru opened this issue · comments

In DirectXMath.h on line 103 malloc.h is imported. However this header is not present on all systems, causing compilation to fail. I'd like to suggest swapping it out for stdlib.h which being a standard header should make the library more portable.

Opinions?

Well the "sal.h" header already makes the library non-portable, so this change won't do all that much. Also I can't find why it's being imported in the first case - it seems it isn't being used at all.

SAL annotation is required by Microsoft's Security Development Lifecycle.

The lack of a 'sal.h' header is easily resolved: You just need a header that defines those symbols to blank somewhere in your system path:

#define _In_
#define _Out_
#define _Out_opt_
#define _In_reads_(a)
#define _In_reads_bytes_(a)
#define _Out_writes_
#define _Out_writes_bytes_(a)
#define _Use_decl_annotations_
#define _Analysis_assume_(a)

This is what the Windows SDK sal.h header is already doing if you are building with __PREFAST__ defined (i.e. not using /analyze).

Note that I exclusively use SAL2 annotation, not the older "VS-style" SAL or the original SAL (__in). See Microsoft Docs.

I'm looking at the malloc.h issue. I'm not sure that header or stdlib is needed at all, but I have to make sure all contexts where my header is used isn't broken by removing it.

The malloc.h include dates back to Visual Studio .NET 2002 :)