Static analysis fixes

This commit is contained in:
BernardoGiordano 2019-07-09 23:13:23 +02:00
parent 727b00edcc
commit d75c79c666
9 changed files with 24 additions and 64 deletions

View file

@ -248,7 +248,7 @@ void MainScreen::updateSelector(void)
{
if (!g_bottomScrollEnabled) {
if (getTitleCount() > 0) {
size_t count = getTitleCount();
size_t count = getTitleCount();
hid.update(count);
// change page
if (hidKeysDown() & KEY_L) {

View file

@ -16,6 +16,6 @@ format:
@for dir in $(SUBDIRS); do $(MAKE) -C $$dir format; done
cppcheck:
cppcheck . --enable=all 2> cppcheck.log
cppcheck . --enable=all --force 2> cppcheck.log
.PHONY: $(SUBDIRS) clean format cppcheck

View file

@ -28,27 +28,21 @@
std::string DateTime::timeStr(void)
{
time_t unixTime = time(NULL);
struct tm* timeStruct = gmtime((const time_t*)&unixTime);
return StringUtils::format("%02i:%02i:%02i", timeStruct->tm_hour, timeStruct->tm_min, timeStruct->tm_sec);
time_t unixTime;
struct tm timeStruct;
time(&unixTime);
localtime_r(&unixTime, &timeStruct);
return StringUtils::format("%02i:%02i:%02i", timeStruct.tm_hour, timeStruct.tm_min, timeStruct.tm_sec);
}
std::string DateTime::dateTimeStr(void)
{
time_t unixTime = time(NULL);
struct tm* timeStruct = gmtime((const time_t*)&unixTime);
return StringUtils::format("%04i%02i%02i-%02i%02i%02i", timeStruct->tm_year + 1900, timeStruct->tm_mon + 1, timeStruct->tm_mday,
timeStruct->tm_hour, timeStruct->tm_min, timeStruct->tm_sec);
}
std::string DateTime::logDateTime(void)
{
time_t unixTime;
struct tm* timeStruct;
struct tm timeStruct;
time(&unixTime);
timeStruct = localtime(&unixTime);
return StringUtils::format("%04i-%02i-%02i %02i:%02i:%02i ", timeStruct->tm_year + 1900, timeStruct->tm_mon + 1, timeStruct->tm_mday,
timeStruct->tm_hour, timeStruct->tm_min, timeStruct->tm_sec);
localtime_r(&unixTime, &timeStruct);
return StringUtils::format("%04i%02i%02i-%02i%02i%02i", timeStruct.tm_year + 1900, timeStruct.tm_mon + 1, timeStruct.tm_mday, timeStruct.tm_hour,
timeStruct.tm_min, timeStruct.tm_sec);
}
std::string StringUtils::UTF16toUTF8(const std::u16string& src)
@ -86,17 +80,6 @@ std::string StringUtils::format(const std::string fmt_str, ...)
return std::string(formatted.get());
}
std::string StringUtils::sizeString(double size)
{
int i = 0;
static const char* units[] = {"B", "kB", "MB", "GB"};
while (size > 1024) {
size /= 1024;
i++;
}
return StringUtils::format("%.*f %s", i, size, units[i]);
}
bool StringUtils::containsInvalidChar(const std::string& str)
{
for (size_t i = 0, sz = str.length(); i < sz; i++) {

View file

@ -44,7 +44,6 @@
namespace DateTime {
std::string timeStr(void);
std::string dateTimeStr(void);
std::string logDateTime(void);
}
namespace StringUtils {
@ -52,7 +51,6 @@ namespace StringUtils {
std::string escapeJson(const std::string& s);
std::string format(const std::string fmt_str, ...);
std::string removeForbiddenCharacters(std::string src);
std::string sizeString(double size);
std::string UTF16toUTF8(const std::u16string& src);
void ltrim(std::string& s);
void rtrim(std::string& s);

View file

@ -43,7 +43,7 @@ public:
void log(const std::string& format, Args... args)
{
if (mFile != NULL) {
fprintf(mFile, (DateUtils::logDateTime() + format + "\n").c_str(), args);
fprintf(mFile, (DateUtils::logDateTime() + format + "\n").c_str(), args...);
}
}

View file

@ -127,9 +127,6 @@ void FC_GetUTF8FromCodepoint(char* result, Uint32 codepoint);
/*! Allocates a copy of the given string. */
char* U8_strdup(const char* string);
/*! Returns the number of UTF-8 characters in the given string. */
int U8_strlen(const char* string);
/*! Returns the number of bytes in the UTF-8 multibyte character pointed at by 'character'. */
int U8_charsize(const char* character);

View file

@ -303,20 +303,6 @@ char* U8_strdup(const char* string)
return result;
}
int U8_strlen(const char* string)
{
int length = 0;
if (string == NULL)
return 0;
while (*string != '\0') {
string = U8_next(string);
++length;
}
return length;
}
int U8_charsize(const char* character)
{
if (character == NULL)

View file

@ -146,8 +146,8 @@ std::tuple<bool, Result, std::string> io::backup(size_t index, u128 uid, size_t
FsFileSystem fileSystem;
res = FileSystem::mount(&fileSystem, title.id(), title.userId());
if (R_SUCCEEDED(res)) {
int ret = FileSystem::mount(fileSystem);
if (ret == -1) {
int rc = FileSystem::mount(fileSystem);
if (rc == -1) {
FileSystem::unmount();
return std::make_tuple(false, -2, "Failed to mount save.");
}
@ -191,10 +191,10 @@ std::tuple<bool, Result, std::string> io::backup(size_t index, u128 uid, size_t
}
if (!isNewFolder || io::directoryExists(dstPath)) {
int ret = io::deleteFolderRecursively((dstPath + "/").c_str());
if (ret != 0) {
int rc = io::deleteFolderRecursively((dstPath + "/").c_str());
if (rc != 0) {
FileSystem::unmount();
return std::make_tuple(false, (Result)ret, "Failed to delete the existing backup\ndirectory recursively.");
return std::make_tuple(false, (Result)rc, "Failed to delete the existing backup\ndirectory recursively.");
}
}
@ -231,8 +231,8 @@ std::tuple<bool, Result, std::string> io::restore(size_t index, u128 uid, size_t
FsFileSystem fileSystem;
res = title.systemSave() ? FileSystem::mount(&fileSystem, title.id()) : FileSystem::mount(&fileSystem, title.id(), title.userId());
if (R_SUCCEEDED(res)) {
int ret = FileSystem::mount(fileSystem);
if (ret == -1) {
int rc = FileSystem::mount(fileSystem);
if (rc == -1) {
FileSystem::unmount();
return std::make_tuple(false, -2, "Failed to mount save.");
}

View file

@ -74,8 +74,8 @@ std::tuple<bool, Result, std::string> sendToPKSMBrigde(size_t index, u128 uid, s
int fd;
struct sockaddr_in servaddr;
if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
return std::make_tuple(false, errno, "Socket creation failed.");
delete[] data;
return std::make_tuple(false, errno, "Socket creation failed.");
}
memset(&servaddr, 0, sizeof(servaddr));
servaddr.sin_family = AF_INET;
@ -90,11 +90,9 @@ std::tuple<bool, Result, std::string> sendToPKSMBrigde(size_t index, u128 uid, s
size_t total = 0;
size_t chunk = 1024;
int n;
size_t tosend;
while (total < size) {
tosend = size - total > chunk ? chunk : size - total;
n = send(fd, data + total, tosend, 0);
size_t tosend = size - total > chunk ? chunk : size - total;
int n = send(fd, data + total, tosend, 0);
if (n == -1) {
break;
}
@ -157,11 +155,9 @@ std::tuple<bool, Result, std::string> recvFromPKSMBridge(size_t index, u128 uid,
size_t total = 0;
size_t chunk = 1024;
int n;
size_t torecv;
while (total < size) {
torecv = size - total > chunk ? chunk : size - total;
n = recv(fdconn, data + total, torecv, 0);
size_t torecv = size - total > chunk ? chunk : size - total;
int n = recv(fdconn, data + total, torecv, 0);
if (n == -1) {
break;
}