Changed from bzero to memset

- All instances of bzero have been replaced in an effort to make SilverMUD slightly easier to port.
This commit is contained in:
Barra Ó Catháin 2023-02-25 19:51:47 +00:00
parent 26a5496594
commit 0add957224
3 changed files with 15 additions and 13 deletions

View File

@ -7,6 +7,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <getopt.h>
#include <stdbool.h> #include <stdbool.h>
#include <pthread.h> #include <pthread.h>
#include <ncurses.h> #include <ncurses.h>
@ -73,7 +74,7 @@ void * messageSender(void * parameters)
// Send the message off to the server: // Send the message off to the server:
messageSend(tlsSession, &sendBuffer); messageSend(tlsSession, &sendBuffer);
bzero(&sendBuffer, sizeof(char) * MAX); memset(&sendBuffer, 0, sizeof(char) * MAX);
} }
// Rejoin the main thread: // Rejoin the main thread:

View File

@ -108,7 +108,7 @@ void * gameLogicHandler(void * parameters)
free(recipients); free(recipients);
} }
} }
bzero(currentInput, sizeof(inputMessage)); memset(currentInput, 0, sizeof(inputMessage));
currentInput = NULL; currentInput = NULL;
threadParameters->inputQueue->lock = false; threadParameters->inputQueue->lock = false;
popQueue(threadParameters->inputQueue); popQueue(threadParameters->inputQueue);
@ -204,7 +204,7 @@ int evaluateNextCommand(gameLogicParameters * parameters, queue * queue)
pushQueue(parameters->outputQueue, lookOutputMessage, OUTPUT_MESSAGE); pushQueue(parameters->outputQueue, lookOutputMessage, OUTPUT_MESSAGE);
//queueTargetedOutputMessage(parameters->outputQueue, lookMessage, &currentCommand->caller, 1); //queueTargetedOutputMessage(parameters->outputQueue, lookMessage, &currentCommand->caller, 1);
bzero(lookMessage, sizeof(userMessage)); memset(lookMessage, 0, sizeof(userMessage));
// Loop through the paths and send the appropriate amount of messages: // Loop through the paths and send the appropriate amount of messages:
int charCount = 13; int charCount = 13;
@ -221,7 +221,7 @@ int evaluateNextCommand(gameLogicParameters * parameters, queue * queue)
// Queue the outputMessage: // Queue the outputMessage:
pushQueue(parameters->outputQueue, lookOutputMessage, OUTPUT_MESSAGE); pushQueue(parameters->outputQueue, lookOutputMessage, OUTPUT_MESSAGE);
bzero(lookMessage, sizeof(userMessage)); memset(lookMessage, 0, sizeof(userMessage));
charCount = 0; charCount = 0;
} }
snprintf(formattedString, 64, "\n\t%ld. %s", index + 1, snprintf(formattedString, 64, "\n\t%ld. %s", index + 1,
@ -278,7 +278,7 @@ int evaluateNextCommand(gameLogicParameters * parameters, queue * queue)
// Queue the outputMessage: // Queue the outputMessage:
pushQueue(parameters->outputQueue, statOutputMessage, OUTPUT_MESSAGE); pushQueue(parameters->outputQueue, statOutputMessage, OUTPUT_MESSAGE);
bzero(statMessage->messageContent, sizeof(char) * MAX); memset(statMessage->messageContent, 0, sizeof(char) * MAX);
if (currentCommand->caller->skills->head != NULL) if (currentCommand->caller->skills->head != NULL)
{ {
size_t skillIndex = 0; size_t skillIndex = 0;
@ -299,7 +299,7 @@ int evaluateNextCommand(gameLogicParameters * parameters, queue * queue)
// Queue the outputMessage: // Queue the outputMessage:
pushQueue(parameters->outputQueue, statOutputMessage, OUTPUT_MESSAGE); pushQueue(parameters->outputQueue, statOutputMessage, OUTPUT_MESSAGE);
bzero(statMessage, sizeof(userMessage)); memset(statMessage, 0, sizeof(userMessage));
charCount = 0; charCount = 0;
break; break;
} }
@ -519,7 +519,7 @@ int evaluateNextCommand(gameLogicParameters * parameters, queue * queue)
// Queue the outputMessage: // Queue the outputMessage:
pushQueue(parameters->outputQueue, listOutputMessage, OUTPUT_MESSAGE); pushQueue(parameters->outputQueue, listOutputMessage, OUTPUT_MESSAGE);
bzero(listMessage, sizeof(userMessage)); memset(listMessage, 0, sizeof(userMessage));
charCount = 0; charCount = 0;
addNewline = false; addNewline = false;
} }
@ -695,8 +695,8 @@ int evaluateNextCommand(gameLogicParameters * parameters, queue * queue)
} }
// Remove the current command and unlock the queue: // Remove the current command and unlock the queue:
bzero(currentCommand->command, sizeof(char) * 16); memset(currentCommand->command, 0, sizeof(char) * 16);
bzero(currentCommand->arguments, sizeof(char) * MAX); memset(currentCommand->arguments, 0, sizeof(char) * MAX);
currentCommand = NULL; currentCommand = NULL;
queue->lock = false; queue->lock = false;
popQueue(queue); popQueue(queue);
@ -747,7 +747,7 @@ outcome statCheck(playerInfo * player, int chance, coreStat statToCheck)
return ERROR; return ERROR;
} }
} }
int attempt = (random() % 100) + modifier; int attempt = (rand() % 100) + modifier;
if (attempt >= chance) if (attempt >= chance)
{ {
if (attempt >= 98) if (attempt >= 98)
@ -820,7 +820,7 @@ outcome skillCheck(playerInfo * player, int chance, char * skillName, size_t ski
} }
// Attempt the check: // Attempt the check:
int attempt = (random() % 100) + modifier; int attempt = (rand() % 100) + modifier;
if (attempt >= chance) if (attempt >= chance)
{ {
if (attempt >= 98) if (attempt >= 98)

View File

@ -9,6 +9,7 @@
#include <string.h> #include <string.h>
#include <signal.h> #include <signal.h>
#include <unistd.h> #include <unistd.h>
#include <getopt.h>
#include <ncurses.h> #include <ncurses.h>
#include <pthread.h> #include <pthread.h>
#include <sys/types.h> #include <sys/types.h>
@ -131,7 +132,7 @@ int main(int argc, char ** argv)
slowPrint("\n--==== \033[33;40mSILVERKIN INDUSTRIES\033[0m COMM-LINK SERVER ====--\nVersion Alpha 0.5\n", delay); slowPrint("\n--==== \033[33;40mSILVERKIN INDUSTRIES\033[0m COMM-LINK SERVER ====--\nVersion Alpha 0.5\n", delay);
// Seed random number generator from the current time: // Seed random number generator from the current time:
srandom((unsigned)time(&currentTime)); srand((unsigned)time(&currentTime));
// Initialize the sockets to 0, so we don't crash. // Initialize the sockets to 0, so we don't crash.
for (int index = 0; index < PLAYERCOUNT; index++) for (int index = 0; index < PLAYERCOUNT; index++)
@ -152,7 +153,7 @@ int main(int argc, char ** argv)
slowPrint("\tSocket Creation is:\t\033[32;40mGREEN.\033[0m\n", delay); slowPrint("\tSocket Creation is:\t\033[32;40mGREEN.\033[0m\n", delay);
} }
bzero(&serverAddress, sizeof(serverAddress)); memset(&serverAddress, 0, sizeof(serverAddress));
// Assign IP and port: // Assign IP and port:
serverAddress.sin_family = AF_INET; serverAddress.sin_family = AF_INET;