@@ -24,6 +24,7 @@ static const char *default_mpqs[] = {"d2exp.mpq", "d2xmusic.mpq", "d2xtalk.mpq"
24
24
free(X); \
25
25
} \
26
26
(X) = malloc(sizeof(char) * (strlen(Y) + 1)); \
27
+ FAIL_IF_NULL(X); \
27
28
memset(X, 0, sizeof(char) * (strlen(Y) + 1)); \
28
29
strcat(X, Y);
29
30
@@ -207,6 +208,8 @@ void config_set(char *category, char *key, char *value) {
207
208
208
209
void config_load (const char * file_path ) {
209
210
config = malloc (sizeof (config_t ));
211
+ FAIL_IF_NULL (config );
212
+
210
213
memset (config , 0 , sizeof (config_t ));
211
214
config -> mpqs = calloc (0 , sizeof (char * ));
212
215
config -> num_mpqs = 0 ;
@@ -218,6 +221,11 @@ void config_load(const char *file_path) {
218
221
char * value = malloc (sizeof (char ) * MAX_LINE_LEN );
219
222
char * line = malloc (sizeof (char ) * MAX_LINE_LEN );
220
223
224
+ FAIL_IF_NULL (category );
225
+ FAIL_IF_NULL (key );
226
+ FAIL_IF_NULL (value );
227
+ FAIL_IF_NULL (line );
228
+
221
229
memset (category , 0 , sizeof (char ) * MAX_LINE_LEN );
222
230
memset (key , 0 , sizeof (char ) * MAX_LINE_LEN );
223
231
memset (value , 0 , sizeof (char ) * MAX_LINE_LEN );
@@ -286,20 +294,22 @@ void config_free() {
286
294
287
295
void config_add_mpq (const char * mpq_file ) {
288
296
config -> num_mpqs ++ ;
289
- config -> mpqs = realloc (config -> mpqs , config -> num_mpqs * sizeof (char * ));
290
297
291
- if (config -> mpqs == NULL ) {
292
- LOG_FATAL ("Could not allocate memory for MPQs!" );
293
- }
298
+ config -> mpqs = realloc (config -> mpqs , config -> num_mpqs * sizeof (char * ));
299
+ FAIL_IF_NULL (config -> mpqs );
294
300
295
301
config -> mpqs [config -> num_mpqs - 1 ] = malloc (sizeof (char ) * MAX_LINE_LEN );
302
+ FAIL_IF_NULL (config -> mpqs [config -> num_mpqs - 1 ]);
303
+
296
304
memset (config -> mpqs [config -> num_mpqs - 1 ], 0 , sizeof (char ) * MAX_LINE_LEN );
297
305
strcat (config -> mpqs [config -> num_mpqs - 1 ], config -> base_path );
298
306
strcat (config -> mpqs [config -> num_mpqs - 1 ], mpq_file );
299
307
}
300
308
301
309
void config_set_sane_defaults () {
302
310
char * base_path = malloc (sizeof (char ) * 4096 );
311
+ FAIL_IF_NULL (base_path );
312
+
303
313
memset (base_path , 0 , sizeof (char ) * 4096 );
304
314
getcwd (base_path , 4096 );
305
315
SET_PARAM_STR (config -> base_path , base_path );
0 commit comments