Review variables initialization
- All variables are initialized on declaration, some arrays were not properly initialized - Static array buffers require memset() for re-initialization on every function call
This commit is contained in:
parent
8ec5b2dc2f
commit
21ec8c38ae
4 changed files with 27 additions and 24 deletions
|
@ -2013,7 +2013,7 @@ static ma_uint32 ReadAudioBufferFramesInInternalFormat(AudioBuffer *audioBuffer,
|
||||||
|
|
||||||
// Another thread can update the processed state of buffers so
|
// Another thread can update the processed state of buffers so
|
||||||
// we just take a copy here to try and avoid potential synchronization problems
|
// we just take a copy here to try and avoid potential synchronization problems
|
||||||
bool isSubBufferProcessed[2];
|
bool isSubBufferProcessed[2] = { 0 };
|
||||||
isSubBufferProcessed[0] = audioBuffer->isSubBufferProcessed[0];
|
isSubBufferProcessed[0] = audioBuffer->isSubBufferProcessed[0];
|
||||||
isSubBufferProcessed[1] = audioBuffer->isSubBufferProcessed[1];
|
isSubBufferProcessed[1] = audioBuffer->isSubBufferProcessed[1];
|
||||||
|
|
||||||
|
@ -2096,7 +2096,7 @@ static ma_uint32 ReadAudioBufferFramesInMixingFormat(AudioBuffer *audioBuffer, f
|
||||||
// should be defined by the output format of the data converter. We do this until frameCount frames have been output. The important
|
// should be defined by the output format of the data converter. We do this until frameCount frames have been output. The important
|
||||||
// detail to remember here is that we never, ever attempt to read more input data than is required for the specified number of output
|
// detail to remember here is that we never, ever attempt to read more input data than is required for the specified number of output
|
||||||
// frames. This can be achieved with ma_data_converter_get_required_input_frame_count().
|
// frames. This can be achieved with ma_data_converter_get_required_input_frame_count().
|
||||||
ma_uint8 inputBuffer[4096];
|
ma_uint8 inputBuffer[4096] = { 0 };
|
||||||
ma_uint32 inputBufferFrameCap = sizeof(inputBuffer)/ma_get_bytes_per_frame(audioBuffer->converter.config.formatIn, audioBuffer->converter.config.channelsIn);
|
ma_uint32 inputBufferFrameCap = sizeof(inputBuffer)/ma_get_bytes_per_frame(audioBuffer->converter.config.formatIn, audioBuffer->converter.config.channelsIn);
|
||||||
|
|
||||||
ma_uint32 totalOutputFramesProcessed = 0;
|
ma_uint32 totalOutputFramesProcessed = 0;
|
||||||
|
@ -2165,7 +2165,7 @@ static void OnSendAudioDataToDevice(ma_device *pDevice, void *pFramesOut, const
|
||||||
|
|
||||||
while (framesToRead > 0)
|
while (framesToRead > 0)
|
||||||
{
|
{
|
||||||
float tempBuffer[1024]; // 512 frames for stereo
|
float tempBuffer[1024] = { 0 }; // Frames for stereo
|
||||||
|
|
||||||
ma_uint32 framesToReadRightNow = framesToRead;
|
ma_uint32 framesToReadRightNow = framesToRead;
|
||||||
if (framesToReadRightNow > sizeof(tempBuffer)/sizeof(tempBuffer[0])/AUDIO_DEVICE_CHANNELS)
|
if (framesToReadRightNow > sizeof(tempBuffer)/sizeof(tempBuffer[0])/AUDIO_DEVICE_CHANNELS)
|
||||||
|
|
|
@ -5633,8 +5633,8 @@ static void ProcessKeyboard(void)
|
||||||
#define MAX_KEYBUFFER_SIZE 32 // Max size in bytes to read
|
#define MAX_KEYBUFFER_SIZE 32 // Max size in bytes to read
|
||||||
|
|
||||||
// Keyboard input polling (fill keys[256] array with status)
|
// Keyboard input polling (fill keys[256] array with status)
|
||||||
int bufferByteCount = 0; // Bytes available on the buffer
|
int bufferByteCount = 0; // Bytes available on the buffer
|
||||||
char keysBuffer[MAX_KEYBUFFER_SIZE]; // Max keys to be read at a time
|
char keysBuffer[MAX_KEYBUFFER_SIZE] = { 0 }; // Max keys to be read at a time
|
||||||
|
|
||||||
// Read availables keycodes from stdin
|
// Read availables keycodes from stdin
|
||||||
bufferByteCount = read(STDIN_FILENO, keysBuffer, MAX_KEYBUFFER_SIZE); // POSIX system call
|
bufferByteCount = read(STDIN_FILENO, keysBuffer, MAX_KEYBUFFER_SIZE); // POSIX system call
|
||||||
|
|
|
@ -4547,8 +4547,8 @@ static unsigned char *rlGenNextMipmapData(unsigned char *srcData, int srcWidth,
|
||||||
{
|
{
|
||||||
int x2 = 0;
|
int x2 = 0;
|
||||||
int y2 = 0;
|
int y2 = 0;
|
||||||
unsigned char prow[4];
|
unsigned char prow[4] = { 0 };
|
||||||
unsigned char pcol[4];
|
unsigned char pcol[4] = { 0 };
|
||||||
|
|
||||||
int width = srcWidth/2;
|
int width = srcWidth/2;
|
||||||
int height = srcHeight/2;
|
int height = srcHeight/2;
|
||||||
|
|
37
src/rtext.c
37
src/rtext.c
|
@ -1142,12 +1142,11 @@ bool TextIsEqual(const char *text1, const char *text2)
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
if (text1 == NULL || text2 == NULL) {
|
if ((text1 != NULL) && (text2 != NULL))
|
||||||
return false;
|
{
|
||||||
|
if (strcmp(text1, text2) == 0) result = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(text1, text2) == 0) result = true;
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1155,6 +1154,7 @@ bool TextIsEqual(const char *text1, const char *text2)
|
||||||
const char *TextSubtext(const char *text, int position, int length)
|
const char *TextSubtext(const char *text, int position, int length)
|
||||||
{
|
{
|
||||||
static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
||||||
|
memset(buffer, 0, MAX_TEXT_BUFFER_LENGTH);
|
||||||
|
|
||||||
int textLength = TextLength(text);
|
int textLength = TextLength(text);
|
||||||
|
|
||||||
|
@ -1178,21 +1178,21 @@ const char *TextSubtext(const char *text, int position, int length)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace text string
|
// Replace text string
|
||||||
// REQUIRES: strstr(), strncpy(), strcpy()
|
// REQUIRES: strlen(), strstr(), strncpy(), strcpy()
|
||||||
// WARNING: Returned buffer must be freed by the user (if return != NULL)
|
// WARNING: Returned buffer must be freed by the user (if return != NULL)
|
||||||
char *TextReplace(char *text, const char *replace, const char *by)
|
char *TextReplace(char *text, const char *replace, const char *by)
|
||||||
{
|
{
|
||||||
// Sanity checks and initialization
|
// Sanity checks and initialization
|
||||||
if (!text || !replace || !by) return NULL;
|
if (!text || !replace || !by) return NULL;
|
||||||
|
|
||||||
char *result;
|
char *result = NULL;
|
||||||
|
|
||||||
char *insertPoint; // Next insert point
|
char *insertPoint = NULL; // Next insert point
|
||||||
char *temp; // Temp pointer
|
char *temp = NULL; // Temp pointer
|
||||||
int replaceLen; // Replace string length of (the string to remove)
|
int replaceLen = 0; // Replace string length of (the string to remove)
|
||||||
int byLen; // Replacement length (the string to replace replace by)
|
int byLen = 0; // Replacement length (the string to replace replace by)
|
||||||
int lastReplacePos; // Distance between replace and end of last replace
|
int lastReplacePos = 0; // Distance between replace and end of last replace
|
||||||
int count; // Number of replacements
|
int count = 0; // Number of replacements
|
||||||
|
|
||||||
replaceLen = TextLength(replace);
|
replaceLen = TextLength(replace);
|
||||||
if (replaceLen == 0) return NULL; // Empty replace causes infinite loop during count
|
if (replaceLen == 0) return NULL; // Empty replace causes infinite loop during count
|
||||||
|
@ -1249,9 +1249,9 @@ char *TextInsert(const char *text, const char *insert, int position)
|
||||||
// REQUIRES: memset(), memcpy()
|
// REQUIRES: memset(), memcpy()
|
||||||
const char *TextJoin(const char **textList, int count, const char *delimiter)
|
const char *TextJoin(const char **textList, int count, const char *delimiter)
|
||||||
{
|
{
|
||||||
static char text[MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
||||||
memset(text, 0, MAX_TEXT_BUFFER_LENGTH);
|
memset(buffer, 0, MAX_TEXT_BUFFER_LENGTH);
|
||||||
char *textPtr = text;
|
char *textPtr = buffer;
|
||||||
|
|
||||||
int totalLength = 0;
|
int totalLength = 0;
|
||||||
int delimiterLen = TextLength(delimiter);
|
int delimiterLen = TextLength(delimiter);
|
||||||
|
@ -1276,7 +1276,7 @@ const char *TextJoin(const char **textList, int count, const char *delimiter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return text;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Split string into multiple strings
|
// Split string into multiple strings
|
||||||
|
@ -1346,6 +1346,7 @@ int TextFindIndex(const char *text, const char *find)
|
||||||
const char *TextToUpper(const char *text)
|
const char *TextToUpper(const char *text)
|
||||||
{
|
{
|
||||||
static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
||||||
|
memset(buffer, 0, MAX_TEXT_BUFFER_LENGTH);
|
||||||
|
|
||||||
for (int i = 0; i < MAX_TEXT_BUFFER_LENGTH; i++)
|
for (int i = 0; i < MAX_TEXT_BUFFER_LENGTH; i++)
|
||||||
{
|
{
|
||||||
|
@ -1368,6 +1369,7 @@ const char *TextToUpper(const char *text)
|
||||||
const char *TextToLower(const char *text)
|
const char *TextToLower(const char *text)
|
||||||
{
|
{
|
||||||
static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
||||||
|
memset(buffer, 0, MAX_TEXT_BUFFER_LENGTH);
|
||||||
|
|
||||||
for (int i = 0; i < MAX_TEXT_BUFFER_LENGTH; i++)
|
for (int i = 0; i < MAX_TEXT_BUFFER_LENGTH; i++)
|
||||||
{
|
{
|
||||||
|
@ -1387,6 +1389,7 @@ const char *TextToLower(const char *text)
|
||||||
const char *TextToPascal(const char *text)
|
const char *TextToPascal(const char *text)
|
||||||
{
|
{
|
||||||
static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
||||||
|
memset(buffer, 0, MAX_TEXT_BUFFER_LENGTH);
|
||||||
|
|
||||||
buffer[0] = (char)toupper(text[0]);
|
buffer[0] = (char)toupper(text[0]);
|
||||||
|
|
||||||
|
@ -1666,7 +1669,7 @@ static Font LoadBMFont(const char *fileName)
|
||||||
|
|
||||||
int imWidth = 0;
|
int imWidth = 0;
|
||||||
int imHeight = 0;
|
int imHeight = 0;
|
||||||
char imFileName[129];
|
char imFileName[129] = { 0 };
|
||||||
|
|
||||||
int base = 0; // Useless data
|
int base = 0; // Useless data
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue