@@ -146,14 +146,20 @@ int
146
146
pcl::MTLReader::read (const std::string& obj_file_name,
147
147
const std::string& mtl_file_name)
148
148
{
149
- if (obj_file_name.empty () || !boost::filesystem::exists (obj_file_name))
149
+ if (obj_file_name.empty ())
150
+ {
151
+ PCL_ERROR (" [pcl::MTLReader::read] No OBJ file name given!\n " );
152
+ return (-1 );
153
+ }
154
+
155
+ if (!boost::filesystem::exists (obj_file_name))
150
156
{
151
157
PCL_ERROR (" [pcl::MTLReader::read] Could not find file '%s'!\n " ,
152
158
obj_file_name.c_str ());
153
159
return (-1 );
154
160
}
155
161
156
- if (mtl_file_name.empty ())
162
+ if (mtl_file_name.empty ())
157
163
{
158
164
PCL_ERROR (" [pcl::MTLReader::read] MTL file name is empty!\n " );
159
165
return (-1 );
@@ -168,14 +174,23 @@ pcl::MTLReader::read (const std::string& obj_file_name,
168
174
int
169
175
pcl::MTLReader::read (const std::string& mtl_file_path)
170
176
{
171
- if (mtl_file_path.empty () || ! boost::filesystem::exists (mtl_file_path ))
177
+ if (mtl_file_path.empty ( ))
172
178
{
173
- PCL_ERROR (" [pcl::MTLReader::read] Could not find file '%s'. \n " , mtl_file_path. c_str () );
179
+ PCL_ERROR (" [pcl::MTLReader::read] No file name given! \n " );
174
180
return (-1 );
175
181
}
176
182
183
+ // Open file in binary mode to avoid problem of
184
+ // std::getline() corrupting the result of ifstream::tellg()
177
185
std::ifstream mtl_file;
178
186
mtl_file.open (mtl_file_path.c_str (), std::ios::binary);
187
+
188
+ if (!mtl_file.good ())
189
+ {
190
+ PCL_ERROR (" [pcl::MTLReader::read] Could not find file '%s'.\n " , mtl_file_path.c_str ());
191
+ return (-1 );
192
+ }
193
+
179
194
if (!mtl_file.is_open () || mtl_file.fail ())
180
195
{
181
196
PCL_ERROR (" [pcl::MTLReader::read] Could not open file '%s'! Error : %s\n " ,
@@ -340,18 +355,25 @@ pcl::OBJReader::readHeader (const std::string &file_name, pcl::PCLPointCloud2 &c
340
355
data_type = 0 ;
341
356
data_idx = offset;
342
357
343
- std::ifstream fs;
344
358
std::string line;
345
359
346
- if (file_name.empty () || ! boost::filesystem::exists (file_name ))
360
+ if (file_name.empty ( ))
347
361
{
348
- PCL_ERROR (" [pcl::OBJReader::readHeader] Could not find file '%s'. \n " , file_name. c_str () );
362
+ PCL_ERROR (" [pcl::OBJReader::readHeader] No file name given! \n " );
349
363
return (-1 );
350
364
}
351
365
352
366
// Open file in binary mode to avoid problem of
353
367
// std::getline() corrupting the result of ifstream::tellg()
368
+ std::ifstream fs;
354
369
fs.open (file_name.c_str (), std::ios::binary);
370
+
371
+ if (!fs.good ())
372
+ {
373
+ PCL_ERROR (" [pcl::OBJReader::readHeader] Could not find file '%s'.\n " , file_name.c_str ());
374
+ return (-1 );
375
+ }
376
+
355
377
if (!fs.is_open () || fs.fail ())
356
378
{
357
379
PCL_ERROR (" [pcl::OBJReader::readHeader] Could not open file '%s'! Error : %s\n " , file_name.c_str (), strerror (errno));
0 commit comments