Fix uninitialized var compiler warnings
Test: th
Bug: 293313353
Change-Id: I87420a21a9c2ce1987179bf70767ea15b26cd5a5
diff --git a/init/first_stage_init.cpp b/init/first_stage_init.cpp
index 7fabbac..88300cb 100644
--- a/init/first_stage_init.cpp
+++ b/init/first_stage_init.cpp
@@ -67,7 +67,7 @@
void FreeRamdisk(DIR* dir, dev_t dev) {
int dfd = dirfd(dir);
- dirent* de;
+ dirent* de = nullptr;
while ((de = readdir(dir)) != nullptr) {
if (de->d_name == "."s || de->d_name == ".."s) {
continue;
@@ -76,7 +76,7 @@
bool is_dir = false;
if (de->d_type == DT_DIR || de->d_type == DT_UNKNOWN) {
- struct stat info;
+ struct stat info {};
if (fstatat(dfd, de->d_name, &info, AT_SYMLINK_NOFOLLOW) != 0) {
continue;
}
@@ -171,7 +171,7 @@
}
if (module_load_file != "modules.load") {
- struct stat fileStat;
+ struct stat fileStat {};
std::string load_path = dir_path + "/" + module_load_file;
// Fall back to modules.load if the other files aren't accessible
if (stat(load_path.c_str(), &fileStat)) {
@@ -185,11 +185,11 @@
#define MODULE_BASE_DIR "/lib/modules"
bool LoadKernelModules(BootMode boot_mode, bool want_console, bool want_parallel,
int& modules_loaded) {
- struct utsname uts;
+ struct utsname uts {};
if (uname(&uts)) {
LOG(FATAL) << "Failed to get kernel version.";
}
- int major, minor;
+ int major = 0, minor = 0;
if (sscanf(uts.release, "%d.%d", &major, &minor) != 2) {
LOG(FATAL) << "Failed to parse kernel version " << uts.release;
}
@@ -199,13 +199,13 @@
LOG(INFO) << "Unable to open /lib/modules, skipping module loading.";
return true;
}
- dirent* entry;
+ dirent* entry = nullptr;
std::vector<std::string> module_dirs;
while ((entry = readdir(base_dir.get()))) {
if (entry->d_type != DT_DIR) {
continue;
}
- int dir_major, dir_minor;
+ int dir_major = 0, dir_minor = 0;
if (sscanf(entry->d_name, "%d.%d", &dir_major, &dir_minor) != 2 || dir_major != major ||
dir_minor != minor) {
continue;
@@ -374,7 +374,7 @@
PLOG(ERROR) << "Could not opendir(\"/\"), not freeing ramdisk";
}
- struct stat old_root_info;
+ struct stat old_root_info {};
if (stat("/", &old_root_info) != 0) {
PLOG(ERROR) << "Could not stat(\"/\"), not freeing ramdisk";
old_root_dir.reset();
@@ -483,7 +483,7 @@
}
}
- struct stat new_root_info;
+ struct stat new_root_info {};
if (stat("/", &new_root_info) != 0) {
PLOG(ERROR) << "Could not stat(\"/\"), not freeing ramdisk";
old_root_dir.reset();