@@ -2941,7 +2941,7 @@ static void parse_ship_values(ship_info* sip, const bool is_template, const bool
29412941
29422942 // Goober5000 - if this is a modular table, and we're replacing an existing file name, and the file doesn't exist, don't replace it
29432943 if (replace)
2944- if (sip->cockpit_pof_file[0] != '\0' )
2944+ if (VALID_FNAME( sip->cockpit_pof_file) )
29452945 if (!model_exists(temp))
29462946 valid = false;
29472947
@@ -3021,7 +3021,7 @@ static void parse_ship_values(ship_info* sip, const bool is_template, const bool
30213021
30223022 // Goober5000 - if this is a modular table, and we're replacing an existing file name, and the file doesn't exist, don't replace it
30233023 if (replace)
3024- if (sip->pof_file[0] != '\0' )
3024+ if (VALID_FNAME( sip->pof_file) )
30253025 if (!model_exists(temp))
30263026 valid = false;
30273027
@@ -3041,7 +3041,7 @@ static void parse_ship_values(ship_info* sip, const bool is_template, const bool
30413041
30423042 // if this is a modular table, and we're replacing an existing file name, and the file doesn't exist, don't replace it
30433043 if (replace)
3044- if (sip->pof_file_tech[0] != '\0' )
3044+ if (VALID_FNAME( sip->pof_file_tech) )
30453045 if (!cf_exists_full(temp, CF_TYPE_MODELS))
30463046 valid = false;
30473047
@@ -3102,7 +3102,7 @@ static void parse_ship_values(ship_info* sip, const bool is_template, const bool
31023102
31033103 // Goober5000 - if this is a modular table, and we're replacing an existing file name, and the file doesn't exist, don't replace it
31043104 if (replace)
3105- if (sip->pof_file_hud[0] != '\0' )
3105+ if (VALID_FNAME( sip->pof_file_hud) )
31063106 if (!cf_exists_full(temp, CF_TYPE_MODELS))
31073107 valid = false;
31083108
@@ -3380,7 +3380,7 @@ static void parse_ship_values(ship_info* sip, const bool is_template, const bool
33803380 bool valid = true;
33813381
33823382 if (replace)
3383- if (sip->generic_debris_pof_file[0] != '\0' )
3383+ if (VALID_FNAME( sip->generic_debris_pof_file) )
33843384 if (!cf_exists_full(temp, CF_TYPE_MODELS))
33853385 valid = false;
33863386
@@ -4346,7 +4346,7 @@ static void parse_ship_values(ship_info* sip, const bool is_template, const bool
43464346 {
43474347 stuff_vec3d(&sip->closeup_pos);
43484348 }
4349- else if (first_time && strlen (sip->pof_file))
4349+ else if (first_time && VALID_FNAME (sip->pof_file))
43504350 {
43514351 //Calculate from the model file. This is inefficient, but whatever
43524352 int model_idx = model_load(sip->pof_file, 0, NULL);
@@ -10797,15 +10797,20 @@ int ship_create(matrix* orient, vec3d* pos, int ship_type, const char* ship_name
1079710797 shipp->clear();
1079810798 shipp->orders_allowed_against = ship_set_default_orders_against();
1079910799
10800+ if (!VALID_FNAME(sip->pof_file))
10801+ {
10802+ Error(LOCATION, "Cannot create ship %s; pof file is not valid", sip->name);
10803+ return -1;
10804+ }
1080010805 sip->model_num = model_load(sip->pof_file, sip->n_subsystems, &sip->subsystems[0]); // use the highest detail level
1080110806
10802- if(strlen (sip->cockpit_pof_file))
10807+ if(VALID_FNAME (sip->cockpit_pof_file))
1080310808 {
1080410809 sip->cockpit_model_num = model_load(sip->cockpit_pof_file, 0, NULL);
1080510810 }
1080610811
1080710812 // maybe load an optional hud target model
10808- if(strlen (sip->pof_file_hud)){
10813+ if(VALID_FNAME (sip->pof_file_hud)){
1080910814 // check to see if a "real" ship uses this model. if so, load it up for him so that subsystems are setup properly
1081010815 for(auto it = Ship_info.begin(); it != Ship_info.end(); ++it){
1081110816 if(!stricmp(it->pof_file, sip->pof_file_hud)){
@@ -10817,7 +10822,7 @@ int ship_create(matrix* orient, vec3d* pos, int ship_type, const char* ship_name
1081710822 sip->model_num_hud = model_load(sip->pof_file_hud, 0, NULL);
1081810823 }
1081910824
10820- if (strlen (sip->generic_debris_pof_file)) {
10825+ if (VALID_FNAME (sip->generic_debris_pof_file)) {
1082110826 sip->generic_debris_model_num = model_load(sip->generic_debris_pof_file, 0, nullptr);
1082210827 if (sip->generic_debris_model_num >= 0) {
1082310828 polymodel* pm = model_get(sip->generic_debris_model_num);
@@ -11048,7 +11053,7 @@ static void ship_model_change(int n, int ship_type)
1104811053 }
1104911054
1105011055 if ( sip->cockpit_model_num == -1 ) {
11051- if ( strlen (sip->cockpit_pof_file) ) {
11056+ if ( VALID_FNAME (sip->cockpit_pof_file) ) {
1105211057 sip->cockpit_model_num = model_load(sip->cockpit_pof_file, 0, NULL);
1105311058 }
1105411059 }
0 commit comments