Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libuuu/bmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ static const std::map<std::string, bool (*)(bmap_t &, const tinyxml2::XMLElement
{ "BlockMap", parse_block_map },
};

void send_info(std::string msg)
void send_info(const std::string &msg)
{
uuu_notify nt;
nt.type = uuu_notify::NOTIFY_CMD_INFO;
Expand Down
18 changes: 9 additions & 9 deletions libuuu/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ static class FSHttp : public FSNetwork
};
int for_each_ls(uuu_ls_file /*fn*/, const string &/*backfile*/, const string &/*filename*/, void * /*p*/) override { return 0; };
int get_file_timesample(const string &/*filename*/, uint64_t * /*ptime*/) override { return 0; };
int http_load(shared_ptr<HttpStream> http, shared_ptr<FileBuffer> p, string filename);
int http_load(shared_ptr<HttpStream> http, shared_ptr<FileBuffer> p, const string &filename);
}g_fshttp;

static class FSHttps : public FSHttp
Expand All @@ -370,7 +370,7 @@ static class FSHttps : public FSHttp
FSHttps() { m_Prefix = "HTTPS://"; m_Port = 443; }
}g_fshttps;

int FSHttp::http_load(shared_ptr<HttpStream> http, shared_ptr<FileBuffer> p, string filename)
int FSHttp::http_load(shared_ptr<HttpStream> http, shared_ptr<FileBuffer> p, const string &filename)
{
size_t max = 0x10000;

Expand Down Expand Up @@ -570,7 +570,7 @@ static class FSGz : public FSCompressStream
{
public:
FSGz() { m_ext = ".GZ"; };
virtual std::shared_ptr<CommonStream> create_stream() { return std::make_shared<Gzstream>(); }
virtual std::shared_ptr<CommonStream> create_stream() override { return std::make_shared<Gzstream>(); }
}g_fsgz;

class ZstdStream:public CommonStream
Expand Down Expand Up @@ -642,7 +642,7 @@ static class FSzstd : public FSCompressStream
{
public:
FSzstd() { m_ext = ".ZST"; };
virtual std::shared_ptr<CommonStream> create_stream() { return make_shared<ZstdStream>(); };
virtual std::shared_ptr<CommonStream> create_stream() override { return make_shared<ZstdStream>(); };
}g_FSzstd;

static class FS_DATA
Expand Down Expand Up @@ -679,7 +679,7 @@ static class FS_DATA
return -1;
}

int for_each_ls(uuu_ls_file fn, string path, void *p)
int for_each_ls(uuu_ls_file fn, const string &path, void *p)
{
for (int i = m_pFs.size() -1; i >= 0; i--)
{
Expand Down Expand Up @@ -774,7 +774,7 @@ int FSZip::for_each_ls(uuu_ls_file fn, const string &backfile, const string &fil
return 0;
}

int zip_async_load(string zipfile, string fn, shared_ptr<FileBuffer> buff)
int zip_async_load(const string &zipfile, const string &fn, shared_ptr<FileBuffer> buff)
{
std::lock_guard<mutex> lock(buff->m_async_mutex);

Expand Down Expand Up @@ -1168,7 +1168,7 @@ int FSCompressStream::Decompress(const string& backfile, shared_ptr<FileBuffer>o
return 0;
}

uint64_t get_file_timesample(string filename)
uint64_t get_file_timesample(const string &filename)
{
uint64_t time=0;
g_fs_data.get_file_timesample(filename, &time);
Expand Down Expand Up @@ -1803,7 +1803,7 @@ int FileBuffer::unmapfile()
return 0;
}

bool check_file_exist(string filename, bool /*start_async_load*/)
bool check_file_exist(const string &filename, bool /*start_async_load*/)
{
string_ex fn;
fn += remove_quota(filename);
Expand All @@ -1828,7 +1828,7 @@ bool check_file_exist(string filename, bool /*start_async_load*/)

#ifdef WIN32

int file_overwrite_monitor(string filename, FileBuffer *p)
int file_overwrite_monitor(const string &filename, FileBuffer *p)
{
WaitForSingleObject(p->m_OverLapped.hEvent, INFINITE);

Expand Down
4 changes: 2 additions & 2 deletions libuuu/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

#ifdef WIN32
class FileBuffer;
int file_overwrite_monitor(std::string filename, FileBuffer *p);
int file_overwrite_monitor(const std::string &filename, FileBuffer *p);
#endif

//bit 0, data loaded
Expand Down Expand Up @@ -340,7 +340,7 @@ class FileBuffer: public std::enable_shared_from_this<FileBuffer>
};

std::shared_ptr<FileBuffer> get_file_buffer(std::string filename, bool async=false);
bool check_file_exist(std::string filename, bool start_async_load=true);
bool check_file_exist(const std::string &filename, bool start_async_load=true);

void set_current_dir(const std::string &dir);

Expand Down
10 changes: 5 additions & 5 deletions libuuu/cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static string g_cmd_list_file;

static map<thread::id, map<string, string>> g_environment;

int insert_env_variable(string key, string value)
int insert_env_variable(const string &key, const string &value)
{
g_environment[std::this_thread::get_id()][key] = value;
return 0;
Expand Down Expand Up @@ -253,7 +253,6 @@ int CmdBase::dump()
int CmdList::run_all(CmdCtx *p, bool dry)
{
CmdList::iterator it;
int ret;

uuu_notify nt;
nt.type = uuu_notify::NOTIFY_CMD_TOTAL;
Expand All @@ -262,6 +261,7 @@ int CmdList::run_all(CmdCtx *p, bool dry)

int i = 0;

int ret = -1;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(In theory) ret could return an uninitialized value. To avoid this it is initialized explicitly and for following best practises its scope is being reduced additionally.

for (it = begin(); it != end(); it++, i++)
{
uuu_notify nt;
Expand Down Expand Up @@ -314,7 +314,7 @@ string get_next_param(const string &cmd, size_t &pos, char separate)
return str;

//trim left space
while (cmd[pos] == separate && pos < cmd.size())
while (pos < cmd.size() && cmd[pos] == separate)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LLVM rightly hinted that pos should be checked for its validity before using it to access the string.

pos++;

bool quote = false;
Expand Down Expand Up @@ -496,7 +496,7 @@ CmdObjCreateMap::CmdObjCreateMap()

}

shared_ptr<CmdBase> create_cmd_obj(string cmd)
shared_ptr<CmdBase> create_cmd_obj(const string &cmd)
{
string param;
size_t pos = 0;
Expand Down Expand Up @@ -828,7 +828,7 @@ int CmdIf::parser(char *p)
{
string err = "Unknown command: ";
err += s;
set_last_err_string(s);
set_last_err_string(err);
return -1;
}
size_t lc = pos;
Expand Down
16 changes: 8 additions & 8 deletions libuuu/cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class CmdBase
{
public:
CmdBase() = default;
CmdBase(char *p) { if (p) m_cmd = p; }
CmdBase(const char *p) { if (p) m_cmd = p; }
virtual ~CmdBase();

virtual int dump();
Expand Down Expand Up @@ -123,15 +123,15 @@ class CmdObjCreateMap:public std::map<std::string, CreateCmdObj>
class CmdDone :public CmdBase
{
public:
CmdDone(char *p) :CmdBase(p) { m_lastcmd = true; }
CmdDone(const char *p) :CmdBase(p) { m_lastcmd = true; }

int run(CmdCtx *p) override;
};

class CmdDelay :public CmdBase
{
public:
CmdDelay(char *p) :CmdBase(p) {}
CmdDelay(const char *p) :CmdBase(p) {}

int parser(char *p = nullptr) override;
int run(CmdCtx *p) override;
Expand All @@ -143,7 +143,7 @@ class CmdDelay :public CmdBase
class CmdError : public CmdBase
{
public:
CmdError(char *p) :CmdBase(p) {}
CmdError(const char *p) :CmdBase(p) {}
int parser(char *p = nullptr) override;
int run(CmdCtx *p) override;

Expand All @@ -154,7 +154,7 @@ class CmdError : public CmdBase
class CmdShell : public CmdBase
{
public:
CmdShell(char *p) : CmdBase(p) {}
CmdShell(const char *p) : CmdBase(p) {}

int parser(char *p = nullptr) override;
int run(CmdCtx *p) override;
Expand All @@ -168,7 +168,7 @@ class CmdShell : public CmdBase
class CmdIf : public CmdBase
{
public:
CmdIf(char *p) : CmdBase(p) {}
CmdIf(const char *p) : CmdBase(p) {}

int parser(char *p = nullptr) override;
int run(CmdCtx *p) override;
Expand Down Expand Up @@ -207,7 +207,7 @@ class CmdMap : public std::map<std::string, std::shared_ptr<CmdList>>
class CfgCmd :public CmdBase
{
public:
CfgCmd(char *cmd) :CmdBase(cmd) {}
CfgCmd(const char *cmd) :CmdBase(cmd) {}

int parser(char * /*p*/) override { return 0; }
int run(CmdCtx *p) override;
Expand All @@ -216,7 +216,7 @@ class CfgCmd :public CmdBase
int run_cmds(const char *protocol, CmdCtx *p);
int run_cmd(CmdCtx *pCtx, const char * cmd, int dry);

int insert_env_variable(std::string key, std::string value);
int insert_env_variable(const std::string &key, const std::string &value);
std::string get_env_variable(std::string key);
int clear_env();
bool is_evn_exist(std::string key);
10 changes: 5 additions & 5 deletions libuuu/fastboot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
#include "zlib.h"
#include "libusb.h"

int FastBoot::Transport(string cmd, void *p, size_t size, vector<uint8_t> *input)
int FastBoot::Transport(const string &cmd, void *p, size_t size, vector<uint8_t> *input)
{
if (m_pTrans->write((void*)cmd.data(), cmd.size()))
return -1;
Expand Down Expand Up @@ -178,7 +178,7 @@ int FBCmd::parser(char *p)
{
string err = "Unknown command: ";
err += s;
set_last_err_string(s);
set_last_err_string(err);
return -1;
}

Expand Down Expand Up @@ -304,7 +304,7 @@ int FBCopy::parser(char *p)
{
string err = "Unknown command: ";
err += s;
set_last_err_string(s);
set_last_err_string(err);
return -1;
}

Expand Down Expand Up @@ -1069,7 +1069,7 @@ int FBFlashCmd::flash_ffu(FastBoot *fb, shared_ptr<FileBuffer> pin)
return 0;
}

FBLoop::FBLoop(char* p): CmdBase(p)
FBLoop::FBLoop(const char* p): CmdBase(p)
{
insert_param_info("-f", &m_filename, Param::Type::e_string_filename);
insert_param_info("-format", &m_uboot_cmd, Param::Type::e_string);
Expand All @@ -1080,7 +1080,7 @@ FBLoop::FBLoop(char* p): CmdBase(p)
insert_param_info("-nostop", &m_nostop, Param::Type::e_bool);
}

string FBLoop::build_cmd(string& cmd, size_t off, size_t sz)
string FBLoop::build_cmd(const string& cmd, size_t off, size_t sz)
{
string ucmd="UCmd: ";
ucmd += cmd;
Expand Down
Loading
Loading