@@ -323,7 +323,7 @@ void BotRemoveConsoleMessage(int chatstate, int handle)
323
323
// Returns: -
324
324
// Changes Globals: -
325
325
//===========================================================================
326
- void BotQueueConsoleMessage (int chatstate , int type , char * message )
326
+ void BotQueueConsoleMessage (int chatstate , int type , const char * message )
327
327
{
328
328
bot_consolemessage_t * m ;
329
329
bot_chatstate_t * cs ;
@@ -474,7 +474,7 @@ void UnifyWhiteSpaces(char *string)
474
474
// Returns: -
475
475
// Changes Globals: -
476
476
//===========================================================================
477
- int StringContains (char * str1 , char * str2 , int casesensitive )
477
+ int StringContains (const char * str1 , const char * str2 , int casesensitive )
478
478
{
479
479
int len , i , j , index ;
480
480
@@ -505,7 +505,7 @@ int StringContains(char *str1, char *str2, int casesensitive)
505
505
// Returns: -
506
506
// Changes Globals: -
507
507
//===========================================================================
508
- char * StringContainsWord (char * str1 , char * str2 , int casesensitive )
508
+ const char * StringContainsWord (const char * str1 , const char * str2 , int casesensitive )
509
509
{
510
510
int len , i , j ;
511
511
@@ -547,22 +547,27 @@ char *StringContainsWord(char *str1, char *str2, int casesensitive)
547
547
// Returns: -
548
548
// Changes Globals: -
549
549
//===========================================================================
550
- void StringReplaceWords (char * string , char * synonym , char * replacement )
550
+ void StringReplaceWords (char * string , int stringSize , const char * synonym , const char * replacement )
551
551
{
552
552
char * str , * str2 ;
553
553
554
+ int stringCurrentSize = strlen (string );
555
+ int stringMaxSize = stringSize - 1 ;
556
+ int extraLength = (int )strlen (replacement ) - (int )strlen (synonym );
557
+ string [stringMaxSize ] = '\0' ;
558
+
554
559
//find the synonym in the string
555
- str = StringContainsWord (string , synonym , qfalse );
560
+ str = ( char * ) StringContainsWord (string , synonym , qfalse );
556
561
//if the synonym occurred in the string
557
- while (str )
562
+ while (str && ( stringMaxSize - stringCurrentSize >= extraLength ) )
558
563
{
559
564
//if the synonym isn't part of the replacement which is already in the string
560
565
//useful for abbreviations
561
- str2 = StringContainsWord (string , replacement , qfalse );
566
+ str2 = ( char * ) StringContainsWord (string , replacement , qfalse );
562
567
while (str2 )
563
568
{
564
569
if (str2 <= str && str < str2 + strlen (replacement )) break ;
565
- str2 = StringContainsWord (str2 + 1 , replacement , qfalse );
570
+ str2 = ( char * ) StringContainsWord (str2 + 1 , replacement , qfalse );
566
571
} //end while
567
572
if (!str2 )
568
573
{
@@ -571,7 +576,7 @@ void StringReplaceWords(char *string, char *synonym, char *replacement)
571
576
Com_Memcpy (str , replacement , strlen (replacement ));
572
577
} //end if
573
578
//find the next synonym in the string
574
- str = StringContainsWord (str + strlen (replacement ), synonym , qfalse );
579
+ str = ( char * ) StringContainsWord (str + strlen (replacement ), synonym , qfalse );
575
580
} //end if
576
581
} //end of the function StringReplaceWords
577
582
//===========================================================================
@@ -774,7 +779,7 @@ bot_synonymlist_t *BotLoadSynonyms(char *filename)
774
779
// Returns: -
775
780
// Changes Globals: -
776
781
//===========================================================================
777
- void BotReplaceSynonyms (char * string , unsigned long int context )
782
+ void BotReplaceSynonyms (char * string , int stringSize , unsigned long int context )
778
783
{
779
784
bot_synonymlist_t * syn ;
780
785
bot_synonym_t * synonym ;
@@ -784,7 +789,7 @@ void BotReplaceSynonyms(char *string, unsigned long int context)
784
789
if (!(syn -> context & context )) continue ;
785
790
for (synonym = syn -> firstsynonym -> next ; synonym ; synonym = synonym -> next )
786
791
{
787
- StringReplaceWords (string , synonym -> string , syn -> firstsynonym -> string );
792
+ StringReplaceWords (string , stringSize , synonym -> string , syn -> firstsynonym -> string );
788
793
} //end for
789
794
} //end for
790
795
} //end of the function BotReplaceSynonyms
@@ -794,7 +799,7 @@ void BotReplaceSynonyms(char *string, unsigned long int context)
794
799
// Returns: -
795
800
// Changes Globals: -
796
801
//===========================================================================
797
- void BotReplaceWeightedSynonyms (char * string , unsigned long int context )
802
+ void BotReplaceWeightedSynonyms (char * string , int stringSize , unsigned long int context )
798
803
{
799
804
bot_synonymlist_t * syn ;
800
805
bot_synonym_t * synonym , * replacement ;
@@ -817,7 +822,7 @@ void BotReplaceWeightedSynonyms(char *string, unsigned long int context)
817
822
for (synonym = syn -> firstsynonym ; synonym ; synonym = synonym -> next )
818
823
{
819
824
if (synonym == replacement ) continue ;
820
- StringReplaceWords (string , synonym -> string , replacement -> string );
825
+ StringReplaceWords (string , stringSize , synonym -> string , replacement -> string );
821
826
} //end for
822
827
} //end for
823
828
} //end of the function BotReplaceWeightedSynonyms
@@ -827,12 +832,15 @@ void BotReplaceWeightedSynonyms(char *string, unsigned long int context)
827
832
// Returns: -
828
833
// Changes Globals: -
829
834
//===========================================================================
830
- void BotReplaceReplySynonyms (char * string , unsigned long int context )
835
+ void BotReplaceReplySynonyms (char * string , int stringSize , unsigned long int context )
831
836
{
832
837
char * str1 , * str2 , * replacement ;
833
838
bot_synonymlist_t * syn ;
834
839
bot_synonym_t * synonym ;
835
840
841
+ int stringMaxSize = stringSize - 1 ;
842
+ string [stringMaxSize ] = '\0' ;
843
+
836
844
for (str1 = string ; * str1 ; )
837
845
{
838
846
//go to the start of the next word
@@ -845,12 +853,12 @@ void BotReplaceReplySynonyms(char *string, unsigned long int context)
845
853
for (synonym = syn -> firstsynonym -> next ; synonym ; synonym = synonym -> next )
846
854
{
847
855
//if the synonym is not at the front of the string continue
848
- str2 = StringContainsWord (str1 , synonym -> string , qfalse );
856
+ str2 = ( char * ) StringContainsWord (str1 , synonym -> string , qfalse );
849
857
if (!str2 || str2 != str1 ) continue ;
850
858
//
851
859
replacement = syn -> firstsynonym -> string ;
852
860
//if the replacement IS in front of the string continue
853
- str2 = StringContainsWord (str1 , replacement , qfalse );
861
+ str2 = ( char * ) StringContainsWord (str1 , replacement , qfalse );
854
862
if (str2 && str2 == str1 ) continue ;
855
863
//
856
864
memmove (str1 + strlen (replacement ), str1 + strlen (synonym -> string ),
@@ -1451,7 +1459,7 @@ int StringsMatch(bot_matchpiece_t *pieces, bot_match_t *match)
1451
1459
// Returns: -
1452
1460
// Changes Globals: -
1453
1461
//===========================================================================
1454
- int BotFindMatch (char * str , bot_match_t * match , unsigned long int context )
1462
+ int BotFindMatch (const char * str , bot_match_t * match , unsigned long int context )
1455
1463
{
1456
1464
int i ;
1457
1465
bot_matchtemplate_t * ms ;
@@ -2029,7 +2037,7 @@ void BotDumpInitialChat(bot_chat_t *chat)
2029
2037
// Returns: -
2030
2038
// Changes Globals: -
2031
2039
//===========================================================================
2032
- bot_chat_t * BotLoadInitialChat (char * chatfile , char * chatname )
2040
+ bot_chat_t * BotLoadInitialChat (const char * chatfile , const char * chatname )
2033
2041
{
2034
2042
int pass , foundchat , indent , size ;
2035
2043
char * ptr = NULL ;
@@ -2219,7 +2227,7 @@ void BotFreeChatFile(int chatstate)
2219
2227
// Returns: -
2220
2228
// Changes Globals: -
2221
2229
//===========================================================================
2222
- int BotLoadChatFile (int chatstate , char * chatfile , char * chatname )
2230
+ int BotLoadChatFile (int chatstate , const char * chatfile , const char * chatname )
2223
2231
{
2224
2232
bot_chatstate_t * cs ;
2225
2233
int n , avail = 0 ;
@@ -2277,11 +2285,12 @@ int BotLoadChatFile(int chatstate, char *chatfile, char *chatname)
2277
2285
// Returns: -
2278
2286
// Changes Globals: -
2279
2287
//===========================================================================
2280
- int BotExpandChatMessage (char * outmessage , char * message , unsigned long mcontext ,
2288
+ int BotExpandChatMessage (char * outmessage , const char * message , unsigned long mcontext ,
2281
2289
bot_match_t * match , unsigned long vcontext , int reply )
2282
2290
{
2283
2291
int num , len , i , expansion ;
2284
- char * outputbuf , * ptr , * msgptr ;
2292
+ char * outputbuf , * ptr ;
2293
+ const char * msgptr ;
2285
2294
char temp [MAX_MESSAGE_SIZE ];
2286
2295
2287
2296
expansion = qfalse ;
@@ -2324,12 +2333,12 @@ int BotExpandChatMessage(char *outmessage, char *message, unsigned long mcontext
2324
2333
if (reply )
2325
2334
{
2326
2335
//replace the reply synonyms in the variables
2327
- BotReplaceReplySynonyms (temp , vcontext );
2336
+ BotReplaceReplySynonyms (temp , sizeof ( temp ) - 1 , vcontext );
2328
2337
} //end if
2329
2338
else
2330
2339
{
2331
2340
//replace synonyms in the variable context
2332
- BotReplaceSynonyms (temp , vcontext );
2341
+ BotReplaceSynonyms (temp , MAX_MESSAGE_SIZE , vcontext );
2333
2342
} //end else
2334
2343
//
2335
2344
if (len + strlen (temp ) >= MAX_MESSAGE_SIZE )
@@ -2388,7 +2397,7 @@ int BotExpandChatMessage(char *outmessage, char *message, unsigned long mcontext
2388
2397
} //end while
2389
2398
outputbuf [len ] = '\0' ;
2390
2399
//replace synonyms weighted in the message context
2391
- BotReplaceWeightedSynonyms (outputbuf , mcontext );
2400
+ BotReplaceWeightedSynonyms (outputbuf , MAX_MESSAGE_SIZE , mcontext );
2392
2401
//return true if a random was expanded
2393
2402
return expansion ;
2394
2403
} //end of the function BotExpandChatMessage
@@ -2398,13 +2407,13 @@ int BotExpandChatMessage(char *outmessage, char *message, unsigned long mcontext
2398
2407
// Returns: -
2399
2408
// Changes Globals: -
2400
2409
//===========================================================================
2401
- void BotConstructChatMessage (bot_chatstate_t * chatstate , char * message , unsigned long mcontext ,
2410
+ void BotConstructChatMessage (bot_chatstate_t * chatstate , const char * message , unsigned long mcontext ,
2402
2411
bot_match_t * match , unsigned long vcontext , int reply )
2403
2412
{
2404
2413
int i ;
2405
2414
char srcmessage [MAX_MESSAGE_SIZE ];
2406
2415
2407
- strcpy (srcmessage , message );
2416
+ Q_strncpyz (srcmessage , message , MAX_MESSAGE_SIZE );
2408
2417
for (i = 0 ; i < 10 ; i ++ )
2409
2418
{
2410
2419
if (!BotExpandChatMessage (chatstate -> chatmessage , srcmessage , mcontext , match , vcontext , reply ))
@@ -2426,7 +2435,7 @@ void BotConstructChatMessage(bot_chatstate_t *chatstate, char *message, unsigned
2426
2435
// Returns: -
2427
2436
// Changes Globals: -
2428
2437
//===========================================================================
2429
- char * BotChooseInitialChatMessage (bot_chatstate_t * cs , char * type )
2438
+ char * BotChooseInitialChatMessage (bot_chatstate_t * cs , const char * type )
2430
2439
{
2431
2440
int n , numchatmessages ;
2432
2441
float besttime ;
@@ -2484,7 +2493,7 @@ char *BotChooseInitialChatMessage(bot_chatstate_t *cs, char *type)
2484
2493
// Returns: -
2485
2494
// Changes Globals: -
2486
2495
//===========================================================================
2487
- int BotNumInitialChats (int chatstate , char * type )
2496
+ int BotNumInitialChats (int chatstate , const char * type )
2488
2497
{
2489
2498
bot_chatstate_t * cs ;
2490
2499
bot_chattype_t * t ;
@@ -2511,7 +2520,7 @@ int BotNumInitialChats(int chatstate, char *type)
2511
2520
// Returns: -
2512
2521
// Changes Globals: -
2513
2522
//===========================================================================
2514
- void BotInitialChat (int chatstate , char * type , int mcontext , char * var0 , char * var1 , char * var2 , char * var3 , char * var4 , char * var5 , char * var6 , char * var7 )
2523
+ void BotInitialChat (int chatstate , const char * type , int mcontext , const char * var0 , const char * var1 , const char * var2 , const char * var3 , const char * var4 , const char * var5 , const char * var6 , const char * var7 )
2515
2524
{
2516
2525
char * message ;
2517
2526
int index ;
@@ -2632,7 +2641,7 @@ void BotPrintReplyChatKeys(bot_replychat_t *replychat)
2632
2641
// Returns: -
2633
2642
// Changes Globals: -
2634
2643
//===========================================================================
2635
- int BotReplyChat (int chatstate , char * message , int mcontext , int vcontext , char * var0 , char * var1 , char * var2 , char * var3 , char * var4 , char * var5 , char * var6 , char * var7 )
2644
+ int BotReplyChat (int chatstate , const char * message , int mcontext , int vcontext , const char * var0 , const char * var1 , const char * var2 , const char * var3 , const char * var4 , const char * var5 , const char * var6 , const char * var7 )
2636
2645
{
2637
2646
bot_replychat_t * rchat , * bestrchat ;
2638
2647
bot_replychatkey_t * key ;
@@ -2876,7 +2885,7 @@ void BotSetChatGender(int chatstate, int gender)
2876
2885
// Returns: -
2877
2886
// Changes Globals: -
2878
2887
//===========================================================================
2879
- void BotSetChatName (int chatstate , char * name , int client )
2888
+ void BotSetChatName (int chatstate , const char * name , int client )
2880
2889
{
2881
2890
bot_chatstate_t * cs ;
2882
2891
0 commit comments