[protobuf] VC++ 2008 : Run-Time Check Failure #1

2010-03-23 Thread Nathan McDaniel

I am getting the following run-time check failure in coded_stream.h at
the following function:


inline uint8* CodedOutputStream::WriteLittleEndian32ToArray(uint32
value,
uint8*
target) {
#if !defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST)  \
defined(__BYTE_ORDER)  __BYTE_ORDER == __LITTLE_ENDIAN
  memcpy(target, value, sizeof(value));
#else
  target[0] = static_castuint8(value);   
This is where the error hits.
  target[1] = static_castuint8(value   8);
  target[2] = static_castuint8(value  16);
  target[3] = static_castuint8(value  24);
#endif
  return target + sizeof(value);
}



Visual Studio Error:

Run-Time Check Failure #1 - A cast to a smaller data type has caused a
loss of data. If this was intentional, you should mask the source of
the cast with the appropriate bitmask. For example:
char c = (i  0xFF);
Changing the code in this way will not affect the quality of the
resulting optimized code.


Has anyone seen this? Did I do something wrong or is this something
that needs to change in the library? I think--but have not yet
verified--that I can disable this when compiling the protocol buffer
library.

Screenshot here:
http://www.postimage.org/image.php?v=gxpNWti

This post is similar to the problem I'm having:
http://stackoverflow.com/questions/161369/switch-off-run-time-check-in-visual-studio



Thank you,

Nathan

-- 
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To post to this group, send email to proto...@googlegroups.com.
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.



[protobuf] Re: VC++ 2008 : Run-Time Check Failure #1

2010-03-23 Thread Nathan McDaniel

Well I added this to common.h, which doesn't fix the problem but it
gets around it by enabling the little-endian-assumption optimizations
for windows:


patch
Index: common.h

===
--- common.h(revision 4984)
+++ common.h(working copy)
@@ -76,6 +76,13 @@
   #define LIBPROTOC_EXPORT
 #endif

+
+// __BYTE_ORDER is not defined on Windows, so set it here:
+#if defined(_MSC_VER)  !defined(__BYTE_ORDER)  defined(_M_IX86)
+  #define __BYTE_ORDER __LITTLE_ENDIAN
+#endif
+
+
 namespace internal {

 // Some of these constants are macros rather than const ints so that
they can

/patch


On Mar 23, 11:47 am, Nathan McDaniel nmcdanie...@gmail.com wrote:
 I am getting the following run-time check failure in coded_stream.h at
 the following function:

 

-- 
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To post to this group, send email to proto...@googlegroups.com.
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.



Re: [protobuf] VC++ 2008 : Run-Time Check Failure #1

2010-03-23 Thread Kenton Varda
The loss of data is intentional.  I've never seen MSVC or any other compiler
complain about this before.  Feel free to send a patch adding the bit masks
it asks for.

On Tue, Mar 23, 2010 at 8:47 AM, Nathan McDaniel nmcdanie...@gmail.comwrote:


 I am getting the following run-time check failure in coded_stream.h at
 the following function:

 
 inline uint8* CodedOutputStream::WriteLittleEndian32ToArray(uint32
 value,
uint8*
 target) {
 #if !defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST)  \
defined(__BYTE_ORDER)  __BYTE_ORDER == __LITTLE_ENDIAN
  memcpy(target, value, sizeof(value));
 #else
  target[0] = static_castuint8(value);   
 This is where the error hits.
  target[1] = static_castuint8(value   8);
  target[2] = static_castuint8(value  16);
  target[3] = static_castuint8(value  24);
 #endif
  return target + sizeof(value);
 }
 


 Visual Studio Error:
 
 Run-Time Check Failure #1 - A cast to a smaller data type has caused a
 loss of data. If this was intentional, you should mask the source of
 the cast with the appropriate bitmask. For example:
char c = (i  0xFF);
 Changing the code in this way will not affect the quality of the
 resulting optimized code.
 

 Has anyone seen this? Did I do something wrong or is this something
 that needs to change in the library? I think--but have not yet
 verified--that I can disable this when compiling the protocol buffer
 library.

 Screenshot here:
 http://www.postimage.org/image.php?v=gxpNWti

 This post is similar to the problem I'm having:

 http://stackoverflow.com/questions/161369/switch-off-run-time-check-in-visual-studio



 Thank you,

 Nathan

 --
 You received this message because you are subscribed to the Google Groups
 Protocol Buffers group.
 To post to this group, send email to proto...@googlegroups.com.
 To unsubscribe from this group, send email to
 protobuf+unsubscr...@googlegroups.comprotobuf%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/protobuf?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To post to this group, send email to proto...@googlegroups.com.
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.