@@ -629,22 +629,25 @@ bot_synonymlist_t *BotLoadSynonyms(const char *filename) {
629629 numsynonyms = 0 ;
630630 lastsynonym = NULL ;
631631 while (1 ) {
632+ size_t len ;
632633 if (!PC_ExpectTokenString (source , "(" ) || !PC_ExpectTokenType (source , TT_STRING , 0 , & token )) {
633634 FreeSource (source );
634635 return NULL ;
635636 } // end if
636637 StripDoubleQuotes (token .string );
637- if (strlen (token .string ) <= 0 ) {
638- SourceError (source , "empty string" , token .string );
638+ len = (int )strlen (token .string );
639+ if (len == 0 ) {
640+ SourceError (source , "empty string" );
639641 FreeSource (source );
640642 return NULL ;
641643 } // end if
642- size += sizeof (bot_synonym_t ) + strlen (token .string ) + 1 ;
643- if (pass ) {
644+ len = PAD (len + 1 , sizeof (long ));
645+ size += sizeof (bot_synonym_t ) + len ;
646+ if (pass && ptr ) {
644647 synonym = (bot_synonym_t * )ptr ;
645648 ptr += sizeof (bot_synonym_t );
646649 synonym -> string = ptr ;
647- ptr += strlen ( token . string ) + 1 ;
650+ ptr += len ;
648651 strcpy (synonym -> string , token .string );
649652 //
650653 if (lastsynonym )
@@ -917,17 +920,20 @@ bot_randomlist_t *BotLoadRandomStrings(const char *filename) {
917920 lastrandom = NULL ; // last
918921 //
919922 while (PC_ReadToken (source , & token )) {
923+ size_t len ;
920924 if (token .type != TT_NAME ) {
921925 SourceError (source , "unknown random %s" , token .string );
922926 FreeSource (source );
923927 return NULL ;
924928 } // end if
925- size += sizeof (bot_randomlist_t ) + strlen (token .string ) + 1 ;
926- if (pass ) {
929+ len = strlen (token .string ) + 1 ;
930+ len = PAD (len , sizeof (long ));
931+ size += sizeof (bot_randomlist_t ) + len ;
932+ if (pass && ptr ) {
927933 random = (bot_randomlist_t * )ptr ;
928934 ptr += sizeof (bot_randomlist_t );
929935 random -> string = ptr ;
930- ptr += strlen ( token . string ) + 1 ;
936+ ptr += len ;
931937 strcpy (random -> string , token .string );
932938 random -> firstrandomstring = NULL ;
933939 random -> numstrings = 0 ;
@@ -947,12 +953,14 @@ bot_randomlist_t *BotLoadRandomStrings(const char *filename) {
947953 FreeSource (source );
948954 return NULL ;
949955 } // end if
950- size += sizeof (bot_randomstring_t ) + strlen (chatmessagestring ) + 1 ;
951- if (pass ) {
956+ len = strlen (chatmessagestring ) + 1 ;
957+ len = PAD (len , sizeof (long ));
958+ size += sizeof (bot_randomstring_t ) + len ;
959+ if (pass && ptr ) {
952960 randomstring = (bot_randomstring_t * )ptr ;
953961 ptr += sizeof (bot_randomstring_t );
954962 randomstring -> string = ptr ;
955- ptr += strlen ( chatmessagestring ) + 1 ;
963+ ptr += len ;
956964 strcpy (randomstring -> string , chatmessagestring );
957965 //
958966 random -> numstrings ++ ;
@@ -1950,11 +1958,14 @@ bot_chat_t *BotLoadInitialChat(char *chatfile, char *chatname) {
19501958 size += sizeof (bot_chattype_t );
19511959 // read the chat messages
19521960 while (!PC_CheckTokenString (source , "}" )) {
1961+ size_t len ;
19531962 if (!BotLoadChatMessage (source , chatmessagestring )) {
19541963 FreeSource (source );
19551964 return NULL ;
19561965 } // end if
1957- if (pass ) {
1966+ len = strlen (chatmessagestring ) + 1 ;
1967+ len = PAD (len , sizeof (long ));
1968+ if (pass && ptr ) {
19581969 chatmessage = (bot_chatmessage_t * )ptr ;
19591970 chatmessage -> time = -2 * CHATMESSAGE_RECENTTIME ;
19601971 // put the chat message in the list
@@ -1964,11 +1975,11 @@ bot_chat_t *BotLoadInitialChat(char *chatfile, char *chatname) {
19641975 ptr += sizeof (bot_chatmessage_t );
19651976 chatmessage -> chatmessage = ptr ;
19661977 strcpy (chatmessage -> chatmessage , chatmessagestring );
1967- ptr += strlen ( chatmessagestring ) + 1 ;
1978+ ptr += len ;
19681979 // the number of chat messages increased
19691980 chattype -> numchatmessages ++ ;
19701981 } // end if
1971- size += sizeof (bot_chatmessage_t ) + strlen ( chatmessagestring ) + 1 ;
1982+ size += sizeof (bot_chatmessage_t ) + len ;
19721983 } // end if
19731984 } // end while
19741985 } // end if
0 commit comments