Unverified Commit 7540645b by 0x0916 Committed by Stéphane Graber

fix some cppcheck warnings

use cppcheck tools `cppcheck --enable=warning .` on lxc source directory. This patch fix the following warnning ``` [src/lxc/cgroups/cgfs.c:794]: (warning) %ld in format string (no. 3) requires 'long' but the argument type is 'unsigned long'. [src/lxc/confile.c:4441]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'unsigned int'. [src/lxc/confile.c:4502]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'unsigned int'. [src/lxc/confile_legacy.c:921]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'unsigned int'. [src/lxc/confile_legacy.c:938]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'unsigned int'. [src/lxc/lxclock.c:63]: (warning) %zd in format string (no. 1) requires 'ssize_t' but the argument type is 'size_t {aka unsigned long}'. [src/lxc/tools/lxc_info.c:118]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'signed int'. [src/lxc/tools/lxc_info.c:118]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. [src/lxc/tools/lxc_info.c:123]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'signed int'. [src/lxc/tools/lxc_info.c:127]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'signed int'. [src/lxc/tools/lxc_info.c:130]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'signed int'. [src/lxc/tools/lxc_top.c:212]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'signed int'. [src/lxc/tools/lxc_top.c:212]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. [src/lxc/tools/lxc_top.c:217]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'signed int'. [src/lxc/tools/lxc_top.c:221]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'signed int'. [src/lxc/tools/lxc_top.c:224]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'signed int'. ``` Signed-off-by: 's avatarLong Wang <w@laoqinren.net>
parent 84ae4b69
...@@ -791,7 +791,7 @@ static char *cgroup_rename_nsgroup(const char *mountpath, const char *oldname, p ...@@ -791,7 +791,7 @@ static char *cgroup_rename_nsgroup(const char *mountpath, const char *oldname, p
len = strlen(oldname) + strlen(mountpath) + 22; len = strlen(oldname) + strlen(mountpath) + 22;
fulloldpath = alloca(len); fulloldpath = alloca(len);
ret = snprintf(fulloldpath, len, "%s/%s/%ld", mountpath, oldname, (unsigned long)pid); ret = snprintf(fulloldpath, len, "%s/%s/%lu", mountpath, oldname, (unsigned long)pid);
if (ret < 0 || ret >= len) if (ret < 0 || ret >= len)
return NULL; return NULL;
......
...@@ -55,7 +55,7 @@ static inline void dump_stacktrace(void) ...@@ -55,7 +55,7 @@ static inline void dump_stacktrace(void)
strings = backtrace_symbols(array, size); strings = backtrace_symbols(array, size);
// Using fprintf here as our logging module is not thread safe // Using fprintf here as our logging module is not thread safe
fprintf(stderr, "\tObtained %zd stack frames.\n", size); fprintf(stderr, "\tObtained %zu stack frames.\n", size);
for (i = 0; i < size; i++) for (i = 0; i < size; i++)
fprintf(stderr, "\t\t%s\n", strings[i]); fprintf(stderr, "\t\t%s\n", strings[i]);
......
...@@ -116,18 +116,18 @@ static void size_humanize(unsigned long long val, char *buf, size_t bufsz) ...@@ -116,18 +116,18 @@ static void size_humanize(unsigned long long val, char *buf, size_t bufsz)
{ {
if (val > 1 << 30) { if (val > 1 << 30) {
snprintf(buf, bufsz, "%u.%2.2u GiB", snprintf(buf, bufsz, "%u.%2.2u GiB",
(int)(val >> 30), (unsigned int)(val >> 30),
(int)(val & ((1 << 30) - 1)) / 10737419); (unsigned int)(val & ((1 << 30) - 1)) / 10737419);
} else if (val > 1 << 20) { } else if (val > 1 << 20) {
int x = val + 5243; /* for rounding */ unsigned int x = val + 5243; /* for rounding */
snprintf(buf, bufsz, "%u.%2.2u MiB", snprintf(buf, bufsz, "%u.%2.2u MiB",
x >> 20, ((x & ((1 << 20) - 1)) * 100) >> 20); x >> 20, ((x & ((1 << 20) - 1)) * 100) >> 20);
} else if (val > 1 << 10) { } else if (val > 1 << 10) {
int x = val + 5; /* for rounding */ unsigned int x = val + 5; /* for rounding */
snprintf(buf, bufsz, "%u.%2.2u KiB", snprintf(buf, bufsz, "%u.%2.2u KiB",
x >> 10, ((x & ((1 << 10) - 1)) * 100) >> 10); x >> 10, ((x & ((1 << 10) - 1)) * 100) >> 10);
} else { } else {
snprintf(buf, bufsz, "%u bytes", (int)val); snprintf(buf, bufsz, "%u bytes", (unsigned int)val);
} }
} }
......
...@@ -189,19 +189,19 @@ static void sig_handler(int sig) ...@@ -189,19 +189,19 @@ static void sig_handler(int sig)
static void size_humanize(unsigned long long val, char *buf, size_t bufsz) static void size_humanize(unsigned long long val, char *buf, size_t bufsz)
{ {
if (val > 1 << 30) { if (val > 1 << 30) {
snprintf(buf, bufsz, "%u.%2.2u GB", snprintf(buf, bufsz, "%u.%2.2u GiB",
(int)(val >> 30), (unsigned int)(val >> 30),
(int)(val & ((1 << 30) - 1)) / 10737419); (unsigned int)(val & ((1 << 30) - 1)) / 10737419);
} else if (val > 1 << 20) { } else if (val > 1 << 20) {
int x = val + 5243; /* for rounding */ unsigned int x = val + 5243; /* for rounding */
snprintf(buf, bufsz, "%u.%2.2u MB", snprintf(buf, bufsz, "%u.%2.2u MiB",
x >> 20, ((x & ((1 << 20) - 1)) * 100) >> 20); x >> 20, ((x & ((1 << 20) - 1)) * 100) >> 20);
} else if (val > 1 << 10) { } else if (val > 1 << 10) {
int x = val + 5; /* for rounding */ unsigned int x = val + 5; /* for rounding */
snprintf(buf, bufsz, "%u.%2.2u KB", snprintf(buf, bufsz, "%u.%2.2u KiB",
x >> 10, ((x & ((1 << 10) - 1)) * 100) >> 10); x >> 10, ((x & ((1 << 10) - 1)) * 100) >> 10);
} else { } else {
snprintf(buf, bufsz, "%3u.00 ", (int)val); snprintf(buf, bufsz, "%3u.00 ", (unsigned int)val);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment