@@ -633,39 +633,37 @@ namespace pcpp
633633 {
634634 std::vector<uint8_t > result;
635635
636- #if !(defined(__MINGW64_VERSION_MAJOR) || defined(__MINGW32_MAJOR_VERSION))
637- result.reserve (m_ValueLength);
638- #endif
636+ result.resize (m_ValueLength);
639637
640638 switch (m_ValueLength)
641639 {
642640 case 1 :
643641 {
644- result. push_back ( static_cast <uint8_t >(m_Value) );
642+ result[ 0 ] = static_cast <uint8_t >(m_Value);
645643 break ;
646644 }
647645 case 2 :
648646 {
649- uint8_t tempArr[sizeof (uint16_t )];
650647 auto hostValue = htobe16 (static_cast <uint16_t >(m_Value));
651- memcpy (tempArr, &hostValue, m_ValueLength );
652- std::copy (tempArr, tempArr + m_ValueLength, std::back_inserter (result) );
648+ result[ 0 ] = static_cast < uint8_t >(hostValue & 0xFF );
649+ result[ 1 ] = static_cast < uint8_t >((hostValue >> 8 ) & 0xFF );
653650 break ;
654651 }
655652 case 3 :
656653 {
657- uint8_t tempArr[sizeof (uint32_t )];
658654 auto hostValue = htobe32 (static_cast <uint32_t >(m_Value));
659- memcpy (tempArr, &hostValue, m_ValueLength + 1 );
660- std::copy (tempArr + 1 , tempArr + m_ValueLength + 1 , std::back_inserter (result));
655+ result[0 ] = static_cast <uint8_t >((hostValue >> 8 ) & 0xFF );
656+ result[1 ] = static_cast <uint8_t >((hostValue >> 16 ) & 0xFF );
657+ result[2 ] = static_cast <uint8_t >((hostValue >> 24 ) & 0xFF );
661658 break ;
662659 }
663660 case 4 :
664661 {
665- uint8_t tempArr[sizeof (uint32_t )];
666662 auto hostValue = htobe32 (static_cast <uint32_t >(m_Value));
667- memcpy (tempArr, &hostValue, m_ValueLength);
668- std::copy (tempArr, tempArr + m_ValueLength, std::back_inserter (result));
663+ result[0 ] = static_cast <uint8_t >(hostValue & 0xFF );
664+ result[1 ] = static_cast <uint8_t >((hostValue >> 8 ) & 0xFF );
665+ result[2 ] = static_cast <uint8_t >((hostValue >> 16 ) & 0xFF );
666+ result[3 ] = static_cast <uint8_t >((hostValue >> 24 ) & 0xFF );
669667 break ;
670668 }
671669 default :
0 commit comments