@@ -779,23 +779,26 @@ bool DB::updateFields(const JSON::Property &p, const AIS::Message *msg, Ship &v,
779779 case AIS::KEY_MANEUVER:
780780 v.setManeuver (p.Get ().getInt ()); // 0=not available, 1=no special, 2=special (direct value)
781781 break ;
782+ #pragma GCC diagnostic push
783+ #pragma GCC diagnostic ignored "-Wstringop-truncation"
782784 case AIS::KEY_NAME:
783785 case AIS::KEY_SHIPNAME:
784- std::strncpy (v.shipname , p.Get ().getString ().c_str (), 20 );
785- v.shipname [20 ] = ' \0 ' ;
786+ std::strncpy (v.shipname , p.Get ().getString ().c_str (), sizeof (v. shipname ) - 1 );
787+ v.shipname [sizeof (v. shipname ) - 1 ] = ' \0 ' ;
786788 break ;
787789 case AIS::KEY_CALLSIGN:
788- std::strncpy (v.callsign , p.Get ().getString ().c_str (), 7 );
789- v.callsign [7 ] = ' \0 ' ;
790+ std::strncpy (v.callsign , p.Get ().getString ().c_str (), sizeof (v. callsign ) - 1 );
791+ v.callsign [sizeof (v. callsign ) - 1 ] = ' \0 ' ;
790792 break ;
791793 case AIS::KEY_COUNTRY_CODE:
792- std::strncpy (v.country_code , p.Get ().getString ().c_str (), 2 );
793- v.country_code [2 ] = ' \0 ' ;
794+ std::strncpy (v.country_code , p.Get ().getString ().c_str (), sizeof (v. country_code ) - 1 );
795+ v.country_code [sizeof (v. country_code ) - 1 ] = ' \0 ' ;
794796 break ;
795797 case AIS::KEY_DESTINATION:
796- std::strncpy (v.destination , p.Get ().getString ().c_str (), 20 );
797- v.destination [20 ] = ' \0 ' ;
798+ std::strncpy (v.destination , p.Get ().getString ().c_str (), sizeof (v. destination ) - 1 );
799+ v.destination [sizeof (v. destination ) - 1 ] = ' \0 ' ;
798800 break ;
801+ #pragma GCC diagnostic pop
799802 }
800803 return position_updated;
801804}
0 commit comments