hdd_menu: improve error resilience in getFmtType()

This commit is contained in:
Stefan Seyfried
2014-03-01 21:16:29 +01:00
committed by svenhoefer
parent dbdf6b6afe
commit a25bc90d7b

View File

@@ -105,13 +105,17 @@ std::string getFmtType(const char* name, int num)
FILE* f = my_popen(pid, pcmd.c_str(), "r"); FILE* f = my_popen(pid, pcmd.c_str(), "r");
if (f != NULL) { if (f != NULL) {
char buff[512]; char buff[512];
fgets(buff, sizeof(buff), f); if (!fgets(buff, sizeof(buff), f))
buff[0] = '\0';
fclose(f); fclose(f);
ret = buff; ret = buff;
std::string search = "TYPE=\""; std::string search = "TYPE=\"";
size_t pos = ret.find(search); size_t pos = ret.find(search);
if (pos == std::string::npos)
return "";
ret = ret.substr(pos + search.length()); ret = ret.substr(pos + search.length());
pos = ret.find("\""); pos = ret.find("\"");
if (pos != std::string::npos)
ret = ret.substr(0, pos); ret = ret.substr(0, pos);
} }
return ret; return ret;