Initialized unitialized variables.
Test: tested compilation.
Change-Id: Ia5e5c0b9e52244ac49e02be873c65722efb1e733
diff --git a/common/utils.cc b/common/utils.cc
index 0b76eea..e3ffa1c 100644
--- a/common/utils.cc
+++ b/common/utils.cc
@@ -56,7 +56,6 @@
#include "update_engine/common/constants.h"
#include "update_engine/common/platform_constants.h"
-#include "update_engine/common/prefs_interface.h"
#include "update_engine/common/subprocess.h"
#include "update_engine/payload_consumer/file_descriptor.h"
@@ -359,7 +358,7 @@
}
off_t BlockDevSize(int fd) {
- uint64_t dev_size;
+ uint64_t dev_size{};
int rc = ioctl(fd, BLKGETSIZE64, &dev_size);
if (rc == -1) {
dev_size = -1;
@@ -369,7 +368,7 @@
}
off_t FileSize(int fd) {
- struct stat stbuf;
+ struct stat stbuf {};
int rc = fstat(fd, &stbuf);
CHECK_EQ(rc, 0);
if (rc < 0) {
@@ -491,17 +490,17 @@
}
bool FileExists(const char* path) {
- struct stat stbuf;
+ struct stat stbuf {};
return 0 == lstat(path, &stbuf);
}
bool IsSymlink(const char* path) {
- struct stat stbuf;
+ struct stat stbuf {};
return lstat(path, &stbuf) == 0 && S_ISLNK(stbuf.st_mode) != 0;
}
bool IsRegFile(const char* path) {
- struct stat stbuf;
+ struct stat stbuf {};
return lstat(path, &stbuf) == 0 && S_ISREG(stbuf.st_mode) != 0;
}
@@ -539,7 +538,7 @@
}
ScopedFdCloser fd_closer(&fd);
// We take no action if not needed.
- int read_only_flag;
+ int read_only_flag{};
int expected_flag = read_only ? 1 : 0;
int rc = ioctl(fd, BLKROGET, &read_only_flag);
// In case of failure reading the setting we will try to set it anyway.
@@ -607,7 +606,8 @@
}
bool IsMountpoint(const std::string& mountpoint) {
- struct stat stdir, stparent;
+ struct stat stdir {
+ }, stparent{};
// Check whether the passed mountpoint is a directory and the /.. is in the
// same device or not. If mountpoint/.. is in a different device it means that
@@ -678,7 +678,7 @@
// and size is the same for both 32 and 64 bits.
if (size < offsetof(Elf32_Ehdr, e_machine) + sizeof(hdr->e_machine))
return true;
- uint16_t e_machine;
+ uint16_t e_machine{};
// Fix endianness regardless of the host endianness.
if (ei_data == ELFDATA2LSB)
e_machine = le16toh(hdr->e_machine);
@@ -766,7 +766,7 @@
}
string ToString(const Time utc_time) {
- Time::Exploded exp_time;
+ Time::Exploded exp_time{};
utc_time.UTCExplode(&exp_time);
return base::StringPrintf("%d/%d/%d %d:%02d:%02d GMT",
exp_time.month,
@@ -1004,7 +1004,7 @@
}
vector<string> tokens = base::SplitString(
version, ".", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL);
- int value;
+ int value{};
if (tokens.empty() || !base::StringToInt(tokens[0], &value))
return -1; // Target version is invalid.
return value;
@@ -1025,8 +1025,8 @@
return;
}
- int high;
- int low;
+ int high{};
+ int low{};
if (!(base::StringToInt(parts[0], &high) &&
base::StringToInt(parts[1], &low))) {
// Both parts of the version could not be parsed correctly.
@@ -1051,7 +1051,7 @@
}
string GetTimeAsString(time_t utime) {
- struct tm tm;
+ struct tm tm {};
CHECK_EQ(localtime_r(&utime, &tm), &tm);
char str[16];
CHECK_EQ(strftime(str, sizeof(str), "%Y%m%d-%H%M%S", &tm), 15u);