@@ -504,7 +504,8 @@ void BuddyThreadClass::errorCallback( GPConnection *con, GPErrorArg *arg )
504504static void getNickForMessage ( GPConnection *con, GPGetInfoResponseArg *arg, void *param )
505505{
506506 BuddyResponse *resp = (BuddyResponse *)param;
507- strlcpy (resp->arg .message .nick , arg->nick , ARRAY_SIZE (resp->arg .message .nick ));
507+ static_assert (ARRAY_SIZE (arg->nick ) <= ARRAY_SIZE (resp->arg .message .nick ), " Incorrect array size" );
508+ strcpy (resp->arg .message .nick , arg->nick );
508509}
509510
510511void BuddyThreadClass::messageCallback ( GPConnection *con, GPRecvBuddyMessageArg *arg )
@@ -557,9 +558,12 @@ void BuddyThreadClass::connectCallback( GPConnection *con, GPConnectResponseArg
557558 DEBUG_LOG ((" User Error: Create Account instead of Login. Fixing them..." ));
558559 BuddyRequest req;
559560 req.buddyRequestType = BuddyRequest::BUDDYREQUEST_LOGIN;
560- strlcpy (req.arg .login .nick , m_nick.c_str (), ARRAY_SIZE (req.arg .login .nick ));
561- strlcpy (req.arg .login .email , m_email.c_str (), ARRAY_SIZE (req.arg .login .email ));
562- strlcpy (req.arg .login .password , m_pass.c_str (), ARRAY_SIZE (req.arg .login .password ));
561+ static_assert (ARRAY_SIZE (req.arg .login .nick ) > 0 , " Array size too small" );
562+ strcpy (req.arg .login .nick , m_nick.c_str ());
563+ static_assert (ARRAY_SIZE (req.arg .login .email ) > 0 , " Array size too small" );
564+ strcpy (req.arg .login .email , m_email.c_str ());
565+ static_assert (ARRAY_SIZE (req.arg .login .password ) > 0 , " Array size too small" );
566+ strcpy (req.arg .login .password , m_pass.c_str ());
563567 req.arg .login .hasFirewall = true ;
564568 TheGameSpyBuddyMessageQueue->addRequest ( req );
565569 return ;
@@ -618,9 +622,12 @@ static void getInfoResponseForRequest( GPConnection *con, GPGetInfoResponseArg *
618622{
619623 BuddyResponse *resp = (BuddyResponse *)param;
620624 resp->profile = arg->profile ;
621- strlcpy (resp->arg .request .nick , arg->nick , ARRAY_SIZE (resp->arg .request .nick ));
622- strlcpy (resp->arg .request .email , arg->email , ARRAY_SIZE (resp->arg .request .email ));
623- strlcpy (resp->arg .request .countrycode , arg->countrycode , ARRAY_SIZE (resp->arg .request .countrycode ));
625+ static_assert (ARRAY_SIZE (arg->nick ) <= ARRAY_SIZE (resp->arg .request .nick ), " Incorrect array size" );
626+ strcpy (resp->arg .request .nick , arg->nick );
627+ static_assert (ARRAY_SIZE (arg->email ) <= ARRAY_SIZE (resp->arg .request .email ), " Incorrect array size" );
628+ strcpy (resp->arg .request .email , arg->email );
629+ static_assert (ARRAY_SIZE (arg->countrycode ) <= ARRAY_SIZE (resp->arg .request .countrycode ), " Incorrect array size" );
630+ strcpy (resp->arg .request .countrycode , arg->countrycode );
624631}
625632
626633void BuddyThreadClass::requestCallback ( GPConnection *con, GPRecvBuddyRequestArg *arg )
@@ -644,9 +651,12 @@ static void getInfoResponseForStatus(GPConnection * connection, GPGetInfoRespons
644651{
645652 BuddyResponse *resp = (BuddyResponse *)param;
646653 resp->profile = arg->profile ;
647- strlcpy (resp->arg .status .nick , arg->nick , ARRAY_SIZE (resp->arg .status .nick ));
648- strlcpy (resp->arg .status .email , arg->email , ARRAY_SIZE (resp->arg .status .email ));
649- strlcpy (resp->arg .status .countrycode , arg->countrycode , ARRAY_SIZE (resp->arg .status .countrycode ));
654+ static_assert (ARRAY_SIZE (arg->nick ) <= ARRAY_SIZE (resp->arg .status .nick ), " Incorrect array size" );
655+ strcpy (resp->arg .status .nick , arg->nick );
656+ static_assert (ARRAY_SIZE (arg->email ) <= ARRAY_SIZE (resp->arg .status .email ), " Incorrect array size" );
657+ strcpy (resp->arg .status .email , arg->email );
658+ static_assert (ARRAY_SIZE (arg->countrycode ) <= ARRAY_SIZE (resp->arg .status .countrycode ), " Incorrect array size" );
659+ strcpy (resp->arg .status .countrycode , arg->countrycode );
650660}
651661
652662void BuddyThreadClass::statusCallback ( GPConnection *con, GPRecvBuddyStatusArg *arg )
@@ -660,8 +670,11 @@ void BuddyThreadClass::statusCallback( GPConnection *con, GPRecvBuddyStatusArg *
660670 // get user's status
661671 GPBuddyStatus status;
662672 gpGetBuddyStatus ( con, arg->index , &status );
663- strlcpy (response.arg .status .location , status.locationString , ARRAY_SIZE (response.arg .status .location ));
664- strlcpy (response.arg .status .statusString , status.statusString , ARRAY_SIZE (response.arg .status .statusString ));
673+
674+ static_assert (ARRAY_SIZE (status.locationString ) <= ARRAY_SIZE (response.arg .status .location ), " Incorrect array size" );
675+ strcpy (response.arg .status .location , status.locationString );
676+ static_assert (ARRAY_SIZE (status.statusString ) <= ARRAY_SIZE (response.arg .status .statusString ), " Incorrect array size" );
677+ strcpy (response.arg .status .statusString , status.statusString );
665678 response.arg .status .status = status.status ;
666679 DEBUG_LOG ((" Got buddy status for %d(%s) - status %d" , status.profile , response.arg .status .nick , status.status ));
667680
0 commit comments