identity/Util: Fix file write check
The results of TEMP_FAILURE_RETRY can be negative in an error
case. But we were assigning it to an unsigned size_t, and
thus our check to see if it was negative would always be false.
We switch to storing this result in a signed ssize_t, so we'll
properly handle a negative return value. As long as we're
never writing more than 2GB (ssize_t max on a 32-bit system),
this shouldn't be a problem.
Test: TreeHugger
Change-Id: I3d417fab7c3ee7557221f9757567379d1b8cb6da
diff --git a/identity/Util.cpp b/identity/Util.cpp
index c397913..70e7105 100644
--- a/identity/Util.cpp
+++ b/identity/Util.cpp
@@ -60,7 +60,7 @@
uint8_t* p = data.data();
size_t remaining = data.size();
while (remaining > 0) {
- size_t numRead = TEMP_FAILURE_RETRY(read(fd, p, remaining));
+ ssize_t numRead = TEMP_FAILURE_RETRY(read(fd, p, remaining));
if (numRead <= 0) {
PLOG(ERROR) << "Failed reading from '" << path << "'";
close(fd);
@@ -94,7 +94,7 @@
const uint8_t* p = data.data();
size_t remaining = data.size();
while (remaining > 0) {
- size_t numWritten = TEMP_FAILURE_RETRY(write(fd, p, remaining));
+ ssize_t numWritten = TEMP_FAILURE_RETRY(write(fd, p, remaining));
if (numWritten <= 0) {
PLOG(ERROR) << "Failed writing into temp file for '" << path << "'";
close(fd);