Handle platforms where off_t is not convertible to size_t
authorPeter Griess <pgriess@fb.com>
Fri, 24 Jan 2014 15:42:00 +0000 (07:42 -0800)
committerSara Golemon <sgolemon@fb.com>
Thu, 6 Feb 2014 19:50:13 +0000 (11:50 -0800)
Summary:
- On iOS, off_t is an int64_t, and as such std::min() doesn't compile
since the types don't match. Normalize to size_t and fail with an
error if this conversion can't be made

Test Plan:
- fbconfig -r folly && fbmake runtests
- Built on iOS

Reviewed By: tudorb@fb.com

FB internal diff: D1142795

folly/FileUtil.h

index 4939803341215fa78816a593ff56e15d3deffb97..d674dc2e1e4b62acbdb7d1107aec60ca9a386ff8 100644 (file)
@@ -17,6 +17,7 @@
 #ifndef FOLLY_FILEUTIL_H_
 #define FOLLY_FILEUTIL_H_
 
+#include "folly/Conv.h"
 #include "folly/Portability.h"
 #include "folly/ScopeGuard.h"
 
@@ -144,7 +145,7 @@ bool readFile(const char* file_name, Container& out,
   constexpr size_t initialAlloc = 1024 * 4;
   out.resize(
     std::min(
-      buf.st_size ? buf.st_size + 1 : initialAlloc,
+      buf.st_size > 0 ? folly::to<size_t>(buf.st_size + 1) : initialAlloc,
       num_bytes));
 
   while (soFar < out.size()) {