Skip to content

Commit d87f9ae

Browse files
authored
Initialize pointer variables to NULL in ModelicaInternal.c
Pointer variables initialized at definition.
1 parent b756f9d commit d87f9ae

1 file changed

Lines changed: 15 additions & 15 deletions

File tree

Modelica/Resources/C-Sources/ModelicaInternal.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ _Ret_z_ const char* ModelicaInternal_fullPathName(_In_z_ const char* name) {
755755

756756
_Ret_z_ const char* ModelicaInternal_temporaryFileName(void) {
757757
/* Get full path name of a temporary file name which does not exist */
758-
char* fullName;
758+
char* fullName = NULL;
759759

760760
char* tempName = tmpnam(NULL);
761761
if (tempName == NULL) {
@@ -834,7 +834,7 @@ static void G2_FUNCNAME(ModelicaInternal_deleteCS)(void) {
834834
#endif
835835

836836
static void CacheFileForReading(FILE* fp, const char* fileName, int lineNumber, char* buf, int bufLen) {
837-
FileCache* fv;
837+
FileCache* fv = NULL;
838838
size_t len;
839839
if (fileName == NULL) {
840840
/* Do not add, close file */
@@ -878,7 +878,7 @@ static void CacheFileForReading(FILE* fp, const char* fileName, int lineNumber,
878878
}
879879

880880
static void CloseCachedFile(const char* fileName) {
881-
FileCache* fv;
881+
FileCache* fv = NULL;
882882
size_t len = strlen(fileName);
883883
MUTEX_LOCK();
884884
HASH_FIND(hh, fileCache, fileName, (unsigned)len, fv);
@@ -896,8 +896,8 @@ static void CloseCachedFile(const char* fileName) {
896896

897897
static FILE* ModelicaStreams_openFileForReading(const char* fileName, int lineNumber, int* lineNumberOffset, char** buf, int* bufLen) {
898898
/* Open text file for reading */
899-
FILE* fp;
900-
FileCache* fv;
899+
FILE* fp = NULL;
900+
FileCache* fv = NULL;
901901
size_t len = strlen(fileName);
902902
*lineNumberOffset = 0;
903903
*buf = NULL;
@@ -954,7 +954,7 @@ void ModelicaStreams_closeFile(_In_z_ const char* fileName) {
954954

955955
static FILE* ModelicaStreams_openFileForWriting(const char* fileName) {
956956
/* Open text file for writing (with append) */
957-
FILE* fp;
957+
FILE* fp = NULL;
958958

959959
/* Check fileName */
960960
if ( fileName[0] == '\0' ) {
@@ -973,8 +973,8 @@ static FILE* ModelicaStreams_openFileForWriting(const char* fileName) {
973973
}
974974

975975
static int readLine(_In_ char** buf, _In_ int* bufLen, _In_ FILE* fp) {
976-
char* offset;
977-
int oldBufLen;
976+
char* offset = NULL;
977+
int oldBufLen = 0;
978978

979979
if (fgets(*buf, *bufLen, fp) == NULL) {
980980
return EOF;
@@ -1041,7 +1041,7 @@ int ModelicaInternal_countLines(_In_z_ const char* fileName) {
10411041
/* Get number of lines of a file */
10421042
int lineNumberOffset;
10431043
int bufLen;
1044-
char* buf;
1044+
char* buf = NULL;
10451045
int c;
10461046
int nLines = 0;
10471047
int start_of_line = 1;
@@ -1068,9 +1068,9 @@ void ModelicaInternal_readFile(_In_z_ const char* fileName,
10681068
/* Read file into string vector string[nLines] */
10691069
int lineNumberOffset;
10701070
int bufLen;
1071-
char* buf;
1071+
char* buf = NULL;
10721072
FILE* fp = ModelicaStreams_openFileForReading(fileName, 0, &lineNumberOffset, &buf, &bufLen);
1073-
char* line;
1073+
char* line = NULL;
10741074
size_t iLines = 1;
10751075

10761076
if (buf == NULL) {
@@ -1184,8 +1184,8 @@ void ModelicaInternal_chdir(_In_z_ const char* directoryName) {
11841184
}
11851185

11861186
_Ret_z_ const char* ModelicaInternal_getcwd(int dummy) {
1187-
const char* cwd;
1188-
char* directory;
1187+
const char* cwd = NULL;
1188+
char* directory = NULL;
11891189

11901190
#if defined(__WATCOMC__) || defined(__BORLANDC__) || defined(_POSIX_) || defined(__GNUC__)
11911191
char localbuf[BUFFER_LENGTH];
@@ -1212,9 +1212,9 @@ _Ret_z_ const char* ModelicaInternal_getcwd(int dummy) {
12121212
void ModelicaInternal_getenv(_In_z_ const char* name, int convertToSlash,
12131213
_Out_ const char** content, _Out_ int* exist) {
12141214
/* Get content of environment variable */
1215-
char* result;
1215+
char* result = NULL;
12161216
#if defined(_MSC_VER) && _MSC_VER >= 1400
1217-
char* value;
1217+
char* value = NULL;
12181218
size_t len = 0;
12191219
errno_t err = _dupenv_s(&value, &len, name);
12201220
if (err) {

0 commit comments

Comments
 (0)