diff options
-rw-r--r-- | code/botlib/be_ai_chat.c | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/code/botlib/be_ai_chat.c b/code/botlib/be_ai_chat.c index c21292f..ab4bf5f 100644 --- a/code/botlib/be_ai_chat.c +++ b/code/botlib/be_ai_chat.c @@ -20,6 +20,18 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA =========================================================================== */ +#if 0 +#define ALIGN(x) \ + do { \ + size_t oldx = x; \ + x = (x+sizeof(void*)-1) & ~(sizeof(void*)-1L); \ + if(x != oldx) \ + botimport.Print(PRT_MESSAGE, "size %zd -> %zd\n", oldx, x); \ + } while(0) +#else +#define ALIGN(x) +#endif + /***************************************************************************** * name: be_ai_chat.c * @@ -689,7 +701,8 @@ bot_synonymlist_t *BotLoadSynonyms(char *filename) FreeSource(source); return NULL; } //end if - len = (strlen(token.string) + 1 +sizeof(void*)-1) & ~(sizeof(void*)-1); + len = strlen(token.string) + 1; + ALIGN(len); size += sizeof(bot_synonym_t) + len; if (pass) { @@ -987,7 +1000,8 @@ bot_randomlist_t *BotLoadRandomStrings(char *filename) FreeSource(source); return NULL; } //end if - len = (strlen(token.string) + 1 +sizeof(void*)-1) & ~(sizeof(void*)-1); + len = strlen(token.string) + 1; + ALIGN(len); size += sizeof(bot_randomlist_t) + len; if (pass) { @@ -1017,7 +1031,8 @@ bot_randomlist_t *BotLoadRandomStrings(char *filename) FreeSource(source); return NULL; } //end if - len = (strlen(chatmessagestring) + 1 +sizeof(void*)-1) & ~(sizeof(void*)-1); + len = strlen(chatmessagestring) + 1; + ALIGN(len); size += sizeof(bot_randomstring_t) + len; if (pass) { @@ -2120,6 +2135,7 @@ bot_chat_t *BotLoadInitialChat(char *chatfile, char *chatname) } //end if if (pass) { + size_t len; chatmessage = (bot_chatmessage_t *) ptr; chatmessage->time = -2*CHATMESSAGE_RECENTTIME; //put the chat message in the list @@ -2129,7 +2145,9 @@ bot_chat_t *BotLoadInitialChat(char *chatfile, char *chatname) ptr += sizeof(bot_chatmessage_t); chatmessage->chatmessage = ptr; strcpy(chatmessage->chatmessage, chatmessagestring); - ptr += (strlen(chatmessagestring) + 1 +sizeof(void*)-1) & ~(sizeof(void*)-1); + len = strlen(chatmessagestring) + 1; + ALIGN(len); + ptr += len; //the number of chat messages increased chattype->numchatmessages++; } //end if |