Hello,
On 11.11.2013 22:22, Kai Tietz wrote:
Hello Mity,
2013/11/11 <[email protected]>:
Hi.
I'm using the Coverity scan [1] for static source analyzes for mCtrl
project [2] on a regular basis before each release. I've recently got some
false positives resulting from each usage of the macro InlineIsEqualGUID
from mingw-w64 system headers.
It actually results in reports similar to this:
CID 1127326 (#1 of 1): Out-of-bounds access (ARRAY_VS_SINGLETON)3.
ptr_arith: Using "&IID_IUnknown.Data1" as an array. This might corrupt or
misinterpret adjacent memory locations.
Obviously it is the result of the ugly casting the macro uses; it compares
two GUIDs as arrays of four DWORDs).
Are you interested to get patches improving such kinds of problems even if
they complicate the headers? (Well, I didn't yet think how to redefine the
macro to get rid of the issue, but I guess such redefinitions would be
more complex in general.)
Thanks,
Martin
Sure, we are interested in such patches
The patch is attached.
I've changed the definition of the macro InlineIsEqualGUID when
__cplusplus is not defined as well as the C++ inline function. I've
tested the former and it indeed removes the Coverity scan complains
(It resolves 17 of 19 issues the scan finds within mCtrl build ;-).
Please note it now uses __LONG32 which is correct only if __WIDL__ is
not #defined, according to the GUID struct definition at the beginning
of <guiddef.h>. However the macro/inline function were already guarded
by such condition so I took liberty to rely on it.
Best regards,
Martin
Index: mingw-w64-headers/include/guiddef.h
===================================================================
--- mingw-w64-headers/include/guiddef.h (revision 6368)
+++ mingw-w64-headers/include/guiddef.h (working copy)
@@ -149,7 +149,7 @@
#ifdef __cplusplus
__inline int InlineIsEqualGUID (REFGUID rguid1, REFGUID rguid2) {
- return ((&rguid1.Data1)[0] == (&rguid2.Data1)[0] && (&rguid1.Data1)[1] ==
(&rguid2.Data1)[1] && (&rguid1.Data1)[2] == (&rguid2.Data1)[2] &&
(&rguid1.Data1)[3] == (&rguid2.Data1)[3]);
+ return (((__LONG32*)(rguid1))[0] == ((__LONG32*)(rguid2))[0] &&
((__LONG32*)(rguid1))[1] == ((__LONG32*)(rguid2))[1] &&
((__LONG32*)(rguid1))[2] == ((__LONG32*)(rguid2))[2] &&
((__LONG32*)(rguid1))[3] == ((__LONG32*)(rguid2))[3]);
}
__inline int IsEqualGUID (REFGUID rguid1, REFGUID rguid2) {
@@ -156,7 +156,7 @@
return !memcmp (&rguid1,&rguid2, sizeof (GUID));
}
#else
-#define InlineIsEqualGUID(rguid1, rguid2) ((&(rguid1)->Data1)[0] ==
(&(rguid2)->Data1)[0] && (&(rguid1)->Data1)[1] == (&(rguid2)->Data1)[1] &&
(&(rguid1)->Data1)[2] == (&(rguid2)->Data1)[2] && (&(rguid1)->Data1)[3] ==
(&(rguid2)->Data1)[3])
+#define InlineIsEqualGUID(rguid1, rguid2) (((__LONG32*)(rguid1))[0] ==
((__LONG32*)(rguid2))[0] && ((__LONG32*)(rguid1))[1] ==
((__LONG32*)(rguid2))[1] && ((__LONG32*)(rguid1))[2] ==
((__LONG32*)(rguid2))[2] && ((__LONG32*)(rguid1))[3] ==
((__LONG32*)(rguid2))[3])
#define IsEqualGUID(rguid1, rguid2) (!memcmp (rguid1, rguid2, sizeof (GUID)))
#endif
------------------------------------------------------------------------------
DreamFactory - Open Source REST & JSON Services for HTML5 & Native Apps
OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access
Free app hosting. Or install the open source package on any LAMP server.
Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native!
http://pubads.g.doubleclick.net/gampad/clk?id=63469471&iu=/4140/ostg.clktrk
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public