From 46d02b784b80df242b098ba7145f7a448f28920e Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Sat, 8 Sep 2012 20:55:43 +0200 Subject: [PATCH] Fix compile warnings in userspace programs. --- bench/benchctxswitch.cpp | 2 +- bench/benchsyscall.cpp | 2 +- games/conway.cpp | 2 +- games/pong.cpp | 4 ++-- utils/cat.cpp | 2 +- utils/clear.cpp | 2 +- utils/cp.cpp | 2 +- utils/editor.cpp | 8 ++++---- utils/help.cpp | 2 +- utils/init.cpp | 2 +- utils/memstat.cpp | 28 ++++++++++++++-------------- utils/mxsh.cpp | 6 +++--- utils/pager.cpp | 3 +-- utils/pwd.cpp | 2 +- utils/type.cpp | 3 +-- utils/uptime.cpp | 2 +- 16 files changed, 35 insertions(+), 37 deletions(-) diff --git a/bench/benchctxswitch.cpp b/bench/benchctxswitch.cpp index b74dac51..2070bbe9 100644 --- a/bench/benchctxswitch.cpp +++ b/bench/benchctxswitch.cpp @@ -25,7 +25,7 @@ #include #include -int main(int argc, char* argv[]) +int main(int /*argc*/, char* /*argv*/[]) { pid_t slavepid = fork(); if ( slavepid < 0 ) { perror("fork"); return 1; } diff --git a/bench/benchsyscall.cpp b/bench/benchsyscall.cpp index a004fc3d..4455208c 100644 --- a/bench/benchsyscall.cpp +++ b/bench/benchsyscall.cpp @@ -23,7 +23,7 @@ #include #include -int main(int argc, char* argv[]) +int main(int /*argc*/, char* /*argv*/[]) { uintmax_t start; if ( uptime(&start) ) { perror("uptime"); return 1; } diff --git a/games/conway.cpp b/games/conway.cpp index a5c63a70..f656e127 100644 --- a/games/conway.cpp +++ b/games/conway.cpp @@ -165,7 +165,7 @@ void Update() Render(); } -int usage(int argc, char* argv[]) +int usage(int /*argc*/, char* argv[]) { printf("usage: %s [OPTIONS]\n", argv[0]); printf("Options:\n"); diff --git a/games/pong.cpp b/games/pong.cpp index 21ca3022..6020ae4b 100644 --- a/games/pong.cpp +++ b/games/pong.cpp @@ -238,7 +238,7 @@ void ReadInput() } } -int usage(int argc, char* argv[]) +int usage(int /*argc*/, char* argv[]) { printf("usage: %s [OPTIONS]\n", argv[0]); printf("Options:\n"); @@ -272,7 +272,7 @@ int main(int argc, char* argv[]) Update(); UpdateUI(); FlushVGA(); - if ( soundleft < 0 ) { continue; } + if ( /*soundleft < 0*/ false ) { continue; } if ( soundleft <= 50 ) { System::Sound::SetFrequency(0); diff --git a/utils/cat.cpp b/utils/cat.cpp index bd2baf55..df7f871d 100644 --- a/utils/cat.cpp +++ b/utils/cat.cpp @@ -41,7 +41,7 @@ int docat(const char* inputname, int fd) error(0, errno, "read: %s", inputname); return 1; } - if ( writeall(1, buffer, bytesread) < bytesread ) + if ( (ssize_t) writeall(1, buffer, bytesread) < bytesread ) { error(0, errno, "write: %s", inputname); return 1; diff --git a/utils/clear.cpp b/utils/clear.cpp index d540742e..ef416858 100644 --- a/utils/clear.cpp +++ b/utils/clear.cpp @@ -22,7 +22,7 @@ #include -int main(int argc, char* argv[]) +int main(int /*argc*/, char* /*argv*/[]) { printf("\e[H\e[2J"); fflush(stdout); diff --git a/utils/cp.cpp b/utils/cp.cpp index 0af6bbcb..138b676e 100644 --- a/utils/cp.cpp +++ b/utils/cp.cpp @@ -67,7 +67,7 @@ int main(int argc, char* argv[]) ssize_t bytesread = read(fromfd, buffer, BUFFER_SIZE); if ( bytesread < 0 ) { error(1, errno, "read: %s", frompath); return 1; } if ( bytesread == 0 ) { return 0; } - if ( writeall(tofd, buffer, bytesread) < bytesread ) + if ( (ssize_t) writeall(tofd, buffer, bytesread) < bytesread ) { error(1, errno, "write: %s", topath); return 1; diff --git a/utils/editor.cpp b/utils/editor.cpp index d5b7176e..10ec9882 100644 --- a/utils/editor.cpp +++ b/utils/editor.cpp @@ -136,7 +136,7 @@ unsigned textmode() int oldcursory = -1; while ( true ) { - if ( oldcursorx != cursorx || oldcursory != cursory ) + if ( oldcursorx != (int) cursorx || oldcursory != (int) cursory ) { cursorto(cursorx, cursory); oldcursorx = cursorx; @@ -150,7 +150,7 @@ unsigned textmode() ssize_t numbytes = read(0, &codepoint, sizeof(codepoint)); if ( !numbytes ) { break; } if ( numbytes < 0 ) { error(1, errno, "read stdin"); } - if ( numbytes < sizeof(codepoint) ) { + if ( numbytes < (ssize_t) sizeof(codepoint) ) { printf("unexpectedly got %zi bytes\n", numbytes); printf("bytes: %x\n", codepoint); @@ -274,7 +274,7 @@ unsigned confirmquit() ssize_t numbytes = read(0, &codepoint, sizeof(codepoint)); if ( !numbytes ) { exit(0); } if ( numbytes < 0 ) { error(1, errno, "read stdin"); } - if ( numbytes < sizeof(codepoint) ) { fprintf(stderr, "bad stdin data\n"); exit(1); } + if ( numbytes < (ssize_t) sizeof(codepoint) ) { fprintf(stderr, "bad stdin data\n"); exit(1); } if ( !codepoint ) { continue; } int kbkey = KBKEY_DECODE(codepoint); @@ -412,7 +412,7 @@ void run() bufferchanged = false; unsigned mode = MODE_TEXT; - while ( mode != MODE_QUIT ) + while ( mode != (unsigned) MODE_QUIT ) { switch ( mode ) { diff --git a/utils/help.cpp b/utils/help.cpp index 529a647f..32ed6a94 100644 --- a/utils/help.cpp +++ b/utils/help.cpp @@ -25,7 +25,7 @@ #include #include -int main(int argc, char* argv[]) +int main(int /*argc*/, char* /*argv*/[]) { printf("Please enter the name of one of the following programs:\n"); diff --git a/utils/init.cpp b/utils/init.cpp index fa67ebee..77fed09b 100644 --- a/utils/init.cpp +++ b/utils/init.cpp @@ -63,7 +63,7 @@ int runsystem() return ret; } -int main(int argc, char* argv[]) +int main(int /*argc*/, char* /*argv*/[]) { if ( open("/dev/tty", O_RDONLY) != 0 ) { return 2; } if ( open("/dev/tty", O_WRONLY | O_APPEND) != 1 ) { return 2; } diff --git a/utils/memstat.cpp b/utils/memstat.cpp index 38353a90..6ad3e81c 100644 --- a/utils/memstat.cpp +++ b/utils/memstat.cpp @@ -35,34 +35,34 @@ void printbytes(unsigned long long bytes) const unsigned EXBI = 6; unsigned unit = BYTES; - if ( (bytes >> 10ULL) & 1023 ) { unit = KIBI; } - if ( (bytes >> 20ULL) & 1023 ) { unit = MEBI; } - if ( (bytes >> 30ULL) & 1023 ) { unit = GIBI; } - if ( (bytes >> 40ULL) & 1023 ) { unit = TEBI; } - if ( (bytes >> 50ULL) & 1023 ) { unit = PEBI; } - if ( (bytes >> 60ULL) & 1023 ) { unit = EXBI; } + if ( (bytes >> 10ULL) & 1023ULL ) { unit = KIBI; } + if ( (bytes >> 20ULL) & 1023ULL ) { unit = MEBI; } + if ( (bytes >> 30ULL) & 1023ULL ) { unit = GIBI; } + if ( (bytes >> 40ULL) & 1023ULL ) { unit = TEBI; } + if ( (bytes >> 50ULL) & 1023ULL ) { unit = PEBI; } + if ( (bytes >> 60ULL) & 1023ULL ) { unit = EXBI; } switch ( unit ) { case EXBI: - printf("%u ZiB ", (bytes >> 60ULL) & 1023); + printf("%llu ZiB ", (bytes >> 60ULL) & 1023ULL); case PEBI: - printf("%u PiB ", (bytes >> 50ULL) & 1023); + printf("%llu PiB ", (bytes >> 50ULL) & 1023ULL); case TEBI: - printf("%u TiB ", (bytes >> 40ULL) & 1023); + printf("%llu TiB ", (bytes >> 40ULL) & 1023ULL); case GIBI: - printf("%u GiB ", (bytes >> 30ULL) & 1023); + printf("%llu GiB ", (bytes >> 30ULL) & 1023ULL); case MEBI: - printf("%u MiB ", (bytes >> 20ULL) & 1023); + printf("%llu MiB ", (bytes >> 20ULL) & 1023ULL); case KIBI: - printf("%u KiB", (bytes >> 10ULL) & 1023); + printf("%llu KiB", (bytes >> 10ULL) & 1023ULL); break; case BYTES: - printf("%u B", (bytes >> 0ULL) & 1023); + printf("%llu B", (bytes >> 0ULL) & 1023ULL); } } -int main(int argc, char* argv[]) +int main(int /*argc*/, char* /*argv*/[]) { size_t memused = 0; size_t memtotal = 0; diff --git a/utils/mxsh.cpp b/utils/mxsh.cpp index 3233de6b..4648cd21 100644 --- a/utils/mxsh.cpp +++ b/utils/mxsh.cpp @@ -34,7 +34,7 @@ int status = 0; -void on_sigint(int signum) +void on_sigint(int /*signum*/) { printf("^C\n"); } @@ -229,7 +229,7 @@ readcmd: char* arg = *argp; if ( arg[0] != '$' ) { continue; } arg = getenv(arg+1); - if ( !arg ) { arg = ""; } + if ( !arg ) { arg = (char*) ""; } *argp = arg; } @@ -333,7 +333,7 @@ void get_and_run_command() return; } -int main(int argc, char* argv[]) +int main(int /*argc*/, char* argv[]) { signal(SIGINT, on_sigint); char pidstr[32]; diff --git a/utils/pager.cpp b/utils/pager.cpp index 1f40c2df..2d86a133 100644 --- a/utils/pager.cpp +++ b/utils/pager.cpp @@ -79,7 +79,6 @@ int main(int argc, char* argv[]) } for ( ssize_t i = 0; i < numbytes; i++ ) { - bool printed = false; char c = buffer[i]; if ( c == '\n' ) { charleft = WIDTH; } bool eol = (c == '\n') || !charleft; @@ -97,7 +96,7 @@ int main(int argc, char* argv[]) ssize_t numbytes = read(0, &codepoint, sizeof(codepoint)); if ( !numbytes ) { exit(0); } if ( numbytes < 0 ) { error(1, errno, "read(stdin)"); } - if ( numbytes < sizeof(codepoint) ) { error(1, errno, "bad stdin"); } + if ( numbytes < (ssize_t) sizeof(codepoint) ) { error(1, errno, "bad stdin"); } if ( !(kbkey = KBKEY_DECODE(codepoint)) ) { continue; } if ( kbkey == KBKEY_DOWN ) { break; } if ( kbkey == KBKEY_PGDOWN ) { linesleft = HEIGHT-1; break; } diff --git a/utils/pwd.cpp b/utils/pwd.cpp index 1b3d48a4..ca792b07 100644 --- a/utils/pwd.cpp +++ b/utils/pwd.cpp @@ -23,7 +23,7 @@ #include #include -int main(int argc, char* argv[]) +int main(int /*argc*/, char* /*argv*/[]) { const size_t WDSIZE = 4096; char wd[WDSIZE]; diff --git a/utils/type.cpp b/utils/type.cpp index a4d10114..b6ebd8bc 100644 --- a/utils/type.cpp +++ b/utils/type.cpp @@ -89,8 +89,7 @@ int main(int argc, char* argv[]) if ( codepoint >= 0x80 ) { continue; } - char msg[2]; msg[0] = codepoint; msg[1] = '\0'; - printf(msg); + putchar(codepoint & 0xFF); lastwasesc = false; fflush(stdout); } diff --git a/utils/uptime.cpp b/utils/uptime.cpp index 164c386f..a0462d79 100644 --- a/utils/uptime.cpp +++ b/utils/uptime.cpp @@ -52,7 +52,7 @@ void PrintElement(size_t num, const char* single, const char* multiple) prefix = ", "; } -int main(int argc, char* argv[]) +int main(int /*argc*/, char* /*argv*/[]) { uintmax_t usecssinceboot; if ( uptime(&usecssinceboot) ) { perror("uptime"); return 1; }