@@ -312,7 +312,9 @@ void Message::append( const std::string& v )
312312 mIsCached = false ;
313313 auto trailingZeros = getTrailingZeros ( v.size () );
314314 auto size = v.size () + trailingZeros;
315- mDataViews .emplace_back ( this , ArgType::STRING , getCurrentOffset (), size );
315+ CI_ASSERT_MSG ( size <= std::numeric_limits<uint32_t >::max (),
316+ " Argument size must fit in uint32_t" );
317+ mDataViews .emplace_back ( this , ArgType::STRING , getCurrentOffset (), static_cast <uint32_t >( size ) );
316318 appendDataBuffer ( v.data (), v.size (), trailingZeros );
317319}
318320
@@ -322,7 +324,9 @@ void Message::append( const char *v )
322324 auto stringLength = strlen ( v );
323325 auto trailingZeros = getTrailingZeros ( stringLength );
324326 auto size = stringLength + trailingZeros;
325- mDataViews .emplace_back ( this , ArgType::STRING , getCurrentOffset (), size );
327+ CI_ASSERT_MSG ( size <= std::numeric_limits<uint32_t >::max (),
328+ " Argument size must fit in uint32_t" );
329+ mDataViews .emplace_back ( this , ArgType::STRING , getCurrentOffset (), static_cast <uint32_t >( size ) );
326330 appendDataBuffer ( v, stringLength, trailingZeros );
327331}
328332
@@ -337,7 +341,9 @@ void Message::appendBlob( void* blob, uint32_t size )
337341
338342void Message::append ( const ci::Buffer &buffer )
339343{
340- appendBlob ( (void *)buffer.getData (), buffer.getSize () );
344+ CI_ASSERT_MSG ( buffer.getSize () <= std::numeric_limits<uint32_t >::max (),
345+ " Blob size must fit in uint32_t" );
346+ appendBlob ( (void *)buffer.getData (), static_cast <uint32_t >( buffer.getSize () ) );
341347}
342348
343349void Message::appendTimeTag ( uint64_t v )
@@ -418,7 +424,9 @@ void Message::createCache() const
418424
419425 size_t typesArrayLen = typesArray.size ();
420426 ByteArray<4 > sizeArray;
421- int32_t messageSize = addressLen + typesArrayLen + mDataBuffer .size ();
427+ CI_ASSERT_MSG ( addressLen + typesArrayLen + mDataBuffer .size () <= std::numeric_limits<int32_t >::max (),
428+ " Message size must fit in int32_t" );
429+ int32_t messageSize = static_cast <int32_t >(addressLen + typesArrayLen + mDataBuffer .size ());
422430 auto endianSize = htonl ( messageSize );
423431 memcpy ( sizeArray.data (), reinterpret_cast <uint8_t *>( &endianSize ), 4 );
424432
@@ -455,7 +463,7 @@ const Argument& Message::getDataView( uint32_t index ) const
455463 return mDataViews [index];
456464}
457465
458- void Message::appendDataBuffer ( const void *begin, uint32_t size, uint32_t trailingZeros )
466+ void Message::appendDataBuffer ( const void *begin, size_t size, uint32_t trailingZeros )
459467{
460468 auto ptr = reinterpret_cast <const uint8_t *>( begin );
461469 mDataBuffer .insert ( mDataBuffer .end (), ptr, ptr + size );
@@ -1363,7 +1371,9 @@ void ReceiverUdp::listen( OnSocketErrorFn onSocketErrorFn )
13631371 data[ bytesTransferred ] = 0 ;
13641372 istream stream ( &mBuffer );
13651373 stream.read ( reinterpret_cast <char *>( data.get () ), bytesTransferred );
1366- dispatchMethods ( data.get (), bytesTransferred, uniqueEndpoint->address (), uniqueEndpoint->port () );
1374+ CI_ASSERT_MSG ( bytesTransferred <= std::numeric_limits<uint32_t >::max (),
1375+ " Dispatch size must fit in uint32_t" );
1376+ dispatchMethods ( data.get (), static_cast <uint32_t >( bytesTransferred ), uniqueEndpoint->address (), uniqueEndpoint->port () );
13671377 }
13681378 listen ( std::move ( onSocketErrorFn ) );
13691379 });
@@ -1468,7 +1478,9 @@ void ReceiverTcp::Connection::read()
14681478 dataSize = data->size () - 4 ;
14691479 }
14701480
1471- receiver->dispatchMethods ( dataPtr, dataSize, mSocket ->remote_endpoint ().address (), mSocket ->remote_endpoint ().port () );
1481+ CI_ASSERT_MSG ( dataSize <= std::numeric_limits<uint32_t >::max (),
1482+ " Dispatch size must fit in uint32_t" );
1483+ receiver->dispatchMethods ( dataPtr, static_cast <uint32_t >( dataSize ), mSocket ->remote_endpoint ().address (), mSocket ->remote_endpoint ().port () );
14721484
14731485 read ();
14741486 }
@@ -1740,7 +1752,13 @@ void getDate( uint64_t ntpTime, uint32_t *year, uint32_t *month, uint32_t *day,
17401752 // Convert to unix timestamp.
17411753 std::time_t sec_since_epoch = ( ntpTime - ( uint64_t ( 0x83AA7E80 ) << 32 ) ) >> 32 ;
17421754
1743- auto tm = std::localtime ( &sec_since_epoch );
1755+ #ifdef CINDER_MSW
1756+ struct tm tm_buf{};
1757+ localtime_s ( &tm_buf, &sec_since_epoch );
1758+ auto tm = &tm_buf;
1759+ #else
1760+ auto tm = std::localtime (&sec_since_epoch);
1761+ #endif // CINDER_MSW
17441762 if ( year ) *year = tm->tm_year + 1900 ;
17451763 if ( month ) *month = tm->tm_mon + 1 ;
17461764 if ( day ) *day = tm->tm_mday ;
@@ -1756,10 +1774,16 @@ std::string getClockString( uint64_t ntpTime, bool includeDate )
17561774
17571775 char buffer[128 ];
17581776
1777+ #ifdef CINDER_MSW
1778+ #define SPRINTF sprintf_s
1779+ #else
1780+ #define SPRINTF sprintf
1781+ #endif // CINDER_MSW
1782+
17591783 if ( includeDate )
1760- sprintf ( buffer, " %d/%d/%d %02d:%02d:%02d" , month, day, year, hours, minutes, seconds );
1784+ SPRINTF ( buffer, " %d/%d/%d %02d:%02d:%02d" , month, day, year, hours, minutes, seconds );
17611785 else
1762- sprintf ( buffer, " %02d:%02d:%02d" , hours, minutes, seconds );
1786+ SPRINTF ( buffer, " %02d:%02d:%02d" , hours, minutes, seconds );
17631787
17641788 return std::string ( buffer );
17651789}
0 commit comments