msvcp90/msvcp90.h: right-hand operand of comma expression has no effect

Gerald Pfeifer gerald at pfeifer.com
Sat May 17 20:08:09 CDT 2014


On Wed, 16 Apr 2014, Paul Chitescu wrote:
>> Digging into this in more detail I see
>>
>>   ../msvcp90/ios.c: In function 'basic_streambuf_char__Xsgetn_s':
>>   ../msvcp90/msvcp90.h:529:75: warning: right-hand operand of comma
>> expression has no effect [-Wunused-value]
>>   #define memcpy_s( dst, size, src, count ) (memcpy( (dst), (src), (count)
>> ), 0) ^ ../msvcp90/ios.c:1218:13: note: in expansion of macro 'memcpy_s'
>> memcpy_s(ptr+copied, size, *this->prpos, chunk);
>>              ^
> memcpy_s() returns an errno_t so the author tried to force returning 
> zero (no error).
> 
> A simple replacement (still without any checks memcpy_s does) would be:
> 
> #define memcpy_s( dst, size, src, count ) (!memcpy( (dst), (src), (count) ))

I tried to make this change, but that now gets:

  ../msvcp90/msvcp90.h:529:44: warning: value computed is not used [-Wunused-value]
  #define memcpy_s( dst, size, src, count ) (!memcpy( (dst), (src), (count) ))
                                             ^

Since, clearly, the result is never intended to be used, we can as
well simply cast the result away instead of using ", 0".

This is what the patch below does.  Tested successfully with GCC 4.9.0.

Gerald

diff --git a/dlls/msvcp90/msvcp90.h b/dlls/msvcp90/msvcp90.h
index 0d5e124..0691141 100644
--- a/dlls/msvcp90/msvcp90.h
+++ b/dlls/msvcp90/msvcp90.h
@@ -526,7 +526,7 @@ typedef struct {
 } complex_double;
 
 #if _MSVCP_VER < 80
-#define memcpy_s( dst, size, src, count ) (memcpy( (dst), (src), (count) ), 0)
+#define memcpy_s( dst, size, src, count ) ((void)memcpy( (dst), (src), (count) ))
 #define memmove_s( dst, size, src, count ) (memmove( (dst), (src), (count) ), 0)
 #define mbstowcs_s( ret, wcs, size, mbs, count ) (mbstowcs( (wcs), (mbs), (count) ), 0)
 #define hypotf( x, y ) ((float)hypot( (double)(x), (double)(y) ))



More information about the wine-devel mailing list