@@ -115,25 +115,22 @@ pcl::PCDWriter::writeBinary (const std::string &file_name,
115
115
{
116
116
PCL_WARN (" [pcl::PCDWriter::writeBinary] Input point cloud has no data!\n " );
117
117
}
118
- int data_idx = 0 ;
119
118
std::ostringstream oss;
120
119
oss << generateHeader<PointT> (cloud) << " DATA binary\n " ;
121
120
oss.flush ();
122
- data_idx = static_cast <int > (oss.tellp ());
121
+ const auto data_idx = static_cast <unsigned int > (oss.tellp ());
123
122
124
123
#ifdef _WIN32
125
124
HANDLE h_native_file = CreateFileA (file_name.c_str (), GENERIC_READ | GENERIC_WRITE, 0 , NULL , CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
126
125
if (h_native_file == INVALID_HANDLE_VALUE)
127
126
{
128
127
throw pcl::IOException (" [pcl::PCDWriter::writeBinary] Error during CreateFile!" );
129
- return (-1 );
130
128
}
131
129
#else
132
130
int fd = io::raw_open (file_name.c_str (), O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
133
131
if (fd < 0 )
134
132
{
135
133
throw pcl::IOException (" [pcl::PCDWriter::writeBinary] Error during open!" );
136
- return (-1 );
137
134
}
138
135
#endif
139
136
// Mandatory lock file
@@ -162,13 +159,17 @@ pcl::PCDWriter::writeBinary (const std::string &file_name,
162
159
163
160
// Prepare the map
164
161
#ifdef _WIN32
165
- HANDLE fm = CreateFileMappingA (h_native_file, NULL , PAGE_READWRITE, 0 , (DWORD) (data_idx + data_size), NULL );
162
+ HANDLE fm = CreateFileMappingA (h_native_file, NULL , PAGE_READWRITE, (DWORD) ((data_idx + data_size) >> 32 ) , (DWORD) (data_idx + data_size), NULL );
166
163
if (fm == NULL )
167
164
{
168
165
throw pcl::IOException (" [pcl::PCDWriter::writeBinary] Error during memory map creation ()!" );
169
- return (-1 );
170
166
}
171
167
char *map = static_cast <char *>(MapViewOfFile (fm, FILE_MAP_READ | FILE_MAP_WRITE, 0 , 0 , data_idx + data_size));
168
+ if (map == NULL )
169
+ {
170
+ CloseHandle (fm);
171
+ throw pcl::IOException (" [pcl::PCDWriter::writeBinary] Error mapping view of file!" );
172
+ }
172
173
CloseHandle (fm);
173
174
174
175
#else
@@ -182,7 +183,6 @@ pcl::PCDWriter::writeBinary (const std::string &file_name,
182
183
data_idx + data_size, allocate_res, errno, strerror (errno));
183
184
184
185
throw pcl::IOException (" [pcl::PCDWriter::writeBinary] Error during raw_fallocate ()!" );
185
- return (-1 );
186
186
}
187
187
188
188
char *map = static_cast <char *> (::mmap (nullptr , data_idx + data_size, PROT_WRITE, MAP_SHARED, fd, 0 ));
@@ -191,7 +191,6 @@ pcl::PCDWriter::writeBinary (const std::string &file_name,
191
191
io::raw_close (fd);
192
192
resetLockingPermissions (file_name, file_lock);
193
193
throw pcl::IOException (" [pcl::PCDWriter::writeBinary] Error during mmap ()!" );
194
- return (-1 );
195
194
}
196
195
#endif
197
196
@@ -225,7 +224,6 @@ pcl::PCDWriter::writeBinary (const std::string &file_name,
225
224
io::raw_close (fd);
226
225
resetLockingPermissions (file_name, file_lock);
227
226
throw pcl::IOException (" [pcl::PCDWriter::writeBinary] Error during munmap ()!" );
228
- return (-1 );
229
227
}
230
228
#endif
231
229
// Close file
@@ -247,25 +245,22 @@ pcl::PCDWriter::writeBinaryCompressed (const std::string &file_name,
247
245
{
248
246
PCL_WARN (" [pcl::PCDWriter::writeBinaryCompressed] Input point cloud has no data!\n " );
249
247
}
250
- int data_idx = 0 ;
251
248
std::ostringstream oss;
252
249
oss << generateHeader<PointT> (cloud) << " DATA binary_compressed\n " ;
253
250
oss.flush ();
254
- data_idx = static_cast <int > (oss.tellp ());
251
+ const auto data_idx = static_cast <unsigned int > (oss.tellp ());
255
252
256
253
#ifdef _WIN32
257
254
HANDLE h_native_file = CreateFileA (file_name.c_str (), GENERIC_READ | GENERIC_WRITE, 0 , NULL , CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
258
255
if (h_native_file == INVALID_HANDLE_VALUE)
259
256
{
260
257
throw pcl::IOException (" [pcl::PCDWriter::writeBinaryCompressed] Error during CreateFile!" );
261
- return (-1 );
262
258
}
263
259
#else
264
260
int fd = io::raw_open (file_name.c_str (), O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
265
261
if (fd < 0 )
266
262
{
267
263
throw pcl::IOException (" [pcl::PCDWriter::writeBinaryCompressed] Error during open!" );
268
- return (-1 );
269
264
}
270
265
#endif
271
266
@@ -392,7 +387,6 @@ pcl::PCDWriter::writeBinaryCompressed (const std::string &file_name,
392
387
compressed_final_size, allocate_res, errno, strerror (errno));
393
388
394
389
throw pcl::IOException (" [pcl::PCDWriter::writeBinaryCompressed] Error during raw_fallocate ()!" );
395
- return (-1 );
396
390
}
397
391
398
392
char *map = static_cast <char *> (::mmap (nullptr , compressed_final_size, PROT_WRITE, MAP_SHARED, fd, 0 ));
@@ -401,7 +395,6 @@ pcl::PCDWriter::writeBinaryCompressed (const std::string &file_name,
401
395
io::raw_close (fd);
402
396
resetLockingPermissions (file_name, file_lock);
403
397
throw pcl::IOException (" [pcl::PCDWriter::writeBinaryCompressed] Error during mmap ()!" );
404
- return (-1 );
405
398
}
406
399
#endif
407
400
@@ -425,7 +418,6 @@ pcl::PCDWriter::writeBinaryCompressed (const std::string &file_name,
425
418
io::raw_close (fd);
426
419
resetLockingPermissions (file_name, file_lock);
427
420
throw pcl::IOException (" [pcl::PCDWriter::writeBinaryCompressed] Error during munmap ()!" );
428
- return (-1 );
429
421
}
430
422
#endif
431
423
@@ -455,7 +447,6 @@ pcl::PCDWriter::writeASCII (const std::string &file_name, const pcl::PointCloud<
455
447
if (cloud.width * cloud.height != cloud.size ())
456
448
{
457
449
throw pcl::IOException (" [pcl::PCDWriter::writeASCII] Number of points different than width * height!" );
458
- return (-1 );
459
450
}
460
451
461
452
std::ofstream fs;
@@ -464,7 +455,6 @@ pcl::PCDWriter::writeASCII (const std::string &file_name, const pcl::PointCloud<
464
455
if (!fs.is_open () || fs.fail ())
465
456
{
466
457
throw pcl::IOException (" [pcl::PCDWriter::writeASCII] Could not open file for writing!" );
467
- return (-1 );
468
458
}
469
459
470
460
// Mandatory lock file
@@ -625,25 +615,22 @@ pcl::PCDWriter::writeBinary (const std::string &file_name,
625
615
{
626
616
PCL_WARN (" [pcl::PCDWriter::writeBinary] Input point cloud has no data or empty indices given!\n " );
627
617
}
628
- int data_idx = 0 ;
629
618
std::ostringstream oss;
630
619
oss << generateHeader<PointT> (cloud, static_cast <int > (indices.size ())) << " DATA binary\n " ;
631
620
oss.flush ();
632
- data_idx = static_cast <int > (oss.tellp ());
621
+ const auto data_idx = static_cast <unsigned int > (oss.tellp ());
633
622
634
623
#ifdef _WIN32
635
624
HANDLE h_native_file = CreateFileA (file_name.c_str (), GENERIC_READ | GENERIC_WRITE, 0 , NULL , CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
636
625
if (h_native_file == INVALID_HANDLE_VALUE)
637
626
{
638
627
throw pcl::IOException (" [pcl::PCDWriter::writeBinary] Error during CreateFile!" );
639
- return (-1 );
640
628
}
641
629
#else
642
630
int fd = io::raw_open (file_name.c_str (), O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
643
631
if (fd < 0 )
644
632
{
645
633
throw pcl::IOException (" [pcl::PCDWriter::writeBinary] Error during open!" );
646
- return (-1 );
647
634
}
648
635
#endif
649
636
// Mandatory lock file
@@ -672,7 +659,7 @@ pcl::PCDWriter::writeBinary (const std::string &file_name,
672
659
673
660
// Prepare the map
674
661
#ifdef _WIN32
675
- HANDLE fm = CreateFileMapping (h_native_file, NULL , PAGE_READWRITE, 0 , data_idx + data_size, NULL );
662
+ HANDLE fm = CreateFileMapping (h_native_file, NULL , PAGE_READWRITE, (DWORD) ((data_idx + data_size) >> 32 ), (DWORD) ( data_idx + data_size) , NULL );
676
663
char *map = static_cast <char *>(MapViewOfFile (fm, FILE_MAP_READ | FILE_MAP_WRITE, 0 , 0 , data_idx + data_size));
677
664
CloseHandle (fm);
678
665
@@ -687,7 +674,6 @@ pcl::PCDWriter::writeBinary (const std::string &file_name,
687
674
data_idx + data_size, allocate_res, errno, strerror (errno));
688
675
689
676
throw pcl::IOException (" [pcl::PCDWriter::writeBinary] Error during raw_fallocate ()!" );
690
- return (-1 );
691
677
}
692
678
693
679
char *map = static_cast <char *> (::mmap (nullptr , data_idx + data_size, PROT_WRITE, MAP_SHARED, fd, 0 ));
@@ -696,7 +682,6 @@ pcl::PCDWriter::writeBinary (const std::string &file_name,
696
682
io::raw_close (fd);
697
683
resetLockingPermissions (file_name, file_lock);
698
684
throw pcl::IOException (" [pcl::PCDWriter::writeBinary] Error during mmap ()!" );
699
- return (-1 );
700
685
}
701
686
#endif
702
687
@@ -730,7 +715,6 @@ pcl::PCDWriter::writeBinary (const std::string &file_name,
730
715
io::raw_close (fd);
731
716
resetLockingPermissions (file_name, file_lock);
732
717
throw pcl::IOException (" [pcl::PCDWriter::writeBinary] Error during munmap ()!" );
733
- return (-1 );
734
718
}
735
719
#endif
736
720
// Close file
@@ -759,15 +743,13 @@ pcl::PCDWriter::writeASCII (const std::string &file_name,
759
743
if (cloud.width * cloud.height != cloud.size ())
760
744
{
761
745
throw pcl::IOException (" [pcl::PCDWriter::writeASCII] Number of points different than width * height!" );
762
- return (-1 );
763
746
}
764
747
765
748
std::ofstream fs;
766
749
fs.open (file_name.c_str (), std::ios::binary); // Open file
767
750
if (!fs.is_open () || fs.fail ())
768
751
{
769
752
throw pcl::IOException (" [pcl::PCDWriter::writeASCII] Could not open file for writing!" );
770
- return (-1 );
771
753
}
772
754
773
755
// Mandatory lock file
0 commit comments