Fix a bunch of compiler warnings. Not all, but a lot.

This commit is contained in:
Andreas Kling 2019-02-25 19:05:51 +01:00
parent 15fb917f28
commit 901b7d5d91
Notes: sideshowbarker 2024-07-19 15:38:02 +09:00
10 changed files with 29 additions and 191 deletions

View file

@ -13,7 +13,7 @@ typedef unsigned int dword;
static constexpr const char* h = "0123456789abcdef";
template<typename PutChFunc>
[[gnu::always_inline]] int print_hex(PutChFunc putch, char*& bufptr, dword number, byte fields)
[[gnu::always_inline]] inline int print_hex(PutChFunc putch, char*& bufptr, dword number, byte fields)
{
int ret = 0;
byte shr_count = fields * 4;
@ -26,7 +26,7 @@ template<typename PutChFunc>
}
template<typename PutChFunc>
[[gnu::always_inline]] int print_number(PutChFunc putch, char*& bufptr, dword number, bool leftPad, bool zeroPad, dword fieldWidth)
[[gnu::always_inline]] inline int print_number(PutChFunc putch, char*& bufptr, dword number, bool leftPad, bool zeroPad, dword fieldWidth)
{
dword divisor = 1000000000;
char ch;
@ -67,7 +67,7 @@ template<typename PutChFunc>
}
template<typename PutChFunc>
[[gnu::always_inline]] int print_octal_number(PutChFunc putch, char*& bufptr, dword number, bool leftPad, bool zeroPad, dword fieldWidth)
[[gnu::always_inline]] inline int print_octal_number(PutChFunc putch, char*& bufptr, dword number, bool leftPad, bool zeroPad, dword fieldWidth)
{
dword divisor = 134217728;
char ch;
@ -108,7 +108,7 @@ template<typename PutChFunc>
}
template<typename PutChFunc>
[[gnu::always_inline]] int print_string(PutChFunc putch, char*& bufptr, const char* str, bool leftPad, dword fieldWidth)
[[gnu::always_inline]] inline int print_string(PutChFunc putch, char*& bufptr, const char* str, bool leftPad, dword fieldWidth)
{
size_t len = strlen(str);
if (!fieldWidth || fieldWidth < len)
@ -129,7 +129,7 @@ template<typename PutChFunc>
template<typename PutChFunc>
[[gnu::always_inline]] int print_signed_number(PutChFunc putch, char*& bufptr, int number, bool leftPad, bool zeroPad, dword fieldWidth)
[[gnu::always_inline]] inline int print_signed_number(PutChFunc putch, char*& bufptr, int number, bool leftPad, bool zeroPad, dword fieldWidth)
{
if (number < 0) {
putch(bufptr, '-');
@ -139,7 +139,7 @@ template<typename PutChFunc>
}
template<typename PutChFunc>
[[gnu::always_inline]] int printf_internal(PutChFunc putch, char* buffer, const char*& fmt, char*& ap)
[[gnu::always_inline]] inline int printf_internal(PutChFunc putch, char* buffer, const char*& fmt, char*& ap)
{
const char *p;

View file

@ -34,8 +34,8 @@ double round(double);
float roundf(float);
double fabs(double);
float fabsf(float);
double fmod(double);
float fmodf(float);
double fmod(double, double);
float fmodf(float, float);
double exp(double);
float expf(float);
double frexp(double, int* exp);
@ -49,7 +49,7 @@ float sqrtf(float);
double modf(double, double*);
float modff(float, float*);
double ldexp(double, int exp);
double ldexpf(float, int exp);
float ldexpf(float, int exp);
double pow(double x, double y);

View file

@ -15,6 +15,8 @@ char* BC;
int tgetent(char* bp, const char* name)
{
(void)bp;
(void)name;
#ifdef TERMCAP_DEBUG
fprintf(stderr, "tgetent: bp=%p, name='%s'\n", bp, name);
#endif
@ -67,7 +69,7 @@ void ensure_caps()
caps->set("li", "25");
}
char* tgetstr(char* id, char** area)
char* tgetstr(const char* id, char** area)
{
ensure_caps();
#ifdef TERMCAP_DEBUG
@ -85,8 +87,9 @@ char* tgetstr(char* id, char** area)
return nullptr;
}
int tgetflag(char* id)
int tgetflag(const char* id)
{
(void)id;
#ifdef TERMCAP_DEBUG
fprintf(stderr, "tgetflag: '%s'\n", id);
#endif
@ -96,7 +99,7 @@ int tgetflag(char* id)
return 0;
}
int tgetnum(char* id)
int tgetnum(const char* id)
{
#ifdef TERMCAP_DEBUG
fprintf(stderr, "tgetnum: '%s'\n", id);
@ -109,11 +112,15 @@ int tgetnum(char* id)
char* tgoto(const char* cap, int col, int row)
{
(void)cap;
(void)col;
(void)row;
assert(false);
}
int tputs(const char* str, int affcnt, int (*putc)(int))
{
(void)affcnt;
size_t len = strlen(str);
for (size_t i = 0; i < len; ++i)
putc(str[i]);

View file

@ -9,9 +9,9 @@ extern char* UP;
extern char* BC;
int tgetent(char* bp, const char* name);
int tgetflag(char* id);
int tgetnum(char* id);
char* tgetstr(char* id, char** area);
int tgetflag(const char* id);
int tgetnum(const char* id);
char* tgetstr(const char* id, char** area);
char* tgoto(const char* cap, int col, int row);
int tputs(const char* str, int affcnt, int (*putc)(int));

View file

@ -94,7 +94,7 @@ char *asctime(const struct tm*)
assert(false);
}
size_t strftime(char *s, size_t max, const char *format, const struct tm *tm)
size_t strftime(char*, size_t, const char*, const struct tm*)
{
assert(false);
}

View file

@ -16,6 +16,9 @@ extern "C" {
int chown(const char* pathname, uid_t owner, gid_t group)
{
(void)pathname;
(void)owner;
(void)group;
assert(false);
}

View file

@ -12,6 +12,8 @@ GApplication& GApplication::the()
GApplication::GApplication(int argc, char** argv)
{
(void)argc;
(void)argv;
ASSERT(!s_the);
s_the = this;
m_event_loop = make<GEventLoop>();

View file

@ -353,7 +353,7 @@ void Painter::set_pixel(const Point& p, Color color)
m_target->scanline(point.y())[point.x()] = color.value();
}
[[gnu::always_inline]] void Painter::set_pixel_with_draw_op(dword& pixel, const Color& color)
[[gnu::always_inline]] inline void Painter::set_pixel_with_draw_op(dword& pixel, const Color& color)
{
if (m_draw_op == DrawOp::Copy)
pixel = color.value();

View file

@ -18,7 +18,6 @@
#include <LibGUI/GApplication.h>
#include <signal.h>
static GWindow* make_font_test_window();
static GWindow* make_launcher_window();
void handle_sigchld(int)
@ -35,11 +34,6 @@ int main(int argc, char** argv)
signal(SIGCHLD, handle_sigchld);
#if 0
auto* font_test_window = make_font_test_window();
font_test_window->show();
#endif
auto* launcher_window = make_launcher_window();
launcher_window->set_should_exit_app_on_close(true);
launcher_window->show();
@ -47,35 +41,6 @@ int main(int argc, char** argv)
return app.exec();
}
GWindow* make_font_test_window()
{
auto* window = new GWindow;
window->set_title("Font test");
window->set_rect({ 480, 100, 300, 80 });
auto* widget = new GWidget;
window->set_main_widget(widget);
widget->set_relative_rect({ 0, 0, 300, 80 });
auto* l1 = new GLabel(widget);
l1->set_relative_rect({ 0, 0, 300, 20 });
l1->set_text("0123456789");
auto* l2 = new GLabel(widget);
l2->set_relative_rect({ 0, 20, 300, 20 });
l2->set_text("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
auto* l3 = new GLabel(widget);
l3->set_relative_rect({ 0, 40, 300, 20 });
l3->set_text("abcdefghijklmnopqrstuvwxyz");
auto* l4 = new GLabel(widget);
l4->set_relative_rect({ 0, 60, 300, 20 });
l4->set_text("!\"#$%&'()*+,-./:;<=>?@[\\]^_{|}~");
return window;
}
GWindow* make_launcher_window()
{
auto* window = new GWindow;

View file

@ -54,117 +54,6 @@ void handle_sigint(int)
g->was_interrupted = true;
}
static int sh_busy(int, char**)
{
struct sigaction sa;
sa.sa_handler = did_receive_signal;
sa.sa_flags = 0;
sa.sa_mask = 0;
sa.sa_restorer = nullptr;
int rc = sigaction(SIGUSR1, &sa, nullptr);
assert(rc == 0);
printf("listening for signal SIGUSR1 while looping in userspace...\n");
for (;;) {
for (volatile int i = 0; i < 100000; ++i)
;
if (g_got_signal)
break;
}
g_got_signal = false;
return 0;
}
static int sh_fork(int, char**)
{
pid_t pid = fork();
printf("getpid()=%d, fork()=%d\n", getpid(), pid);
return 0;
}
static int sh_fe(int, char**)
{
pid_t pid = fork();
if (!pid) {
int rc = execvp("/bin/ps", nullptr);
if (rc < 0) {
perror("execvp");
exit(1);
}
}
return 0;
}
static int sh_fef(int, char**)
{
pid_t pid = fork();
if (!pid) {
int rc = execvp("/bin/psx", nullptr);
if (rc < 0) {
perror("execvp");
exit(1);
}
}
return 0;
}
static int sh_wt(int, char**)
{
const char* rodata_ptr = "foo";
printf("Writing to rodata=%p...\n", rodata_ptr);
*const_cast<char*>(rodata_ptr) = 0;
char* text_ptr = (char*)sh_fef;
printf("Writing to text=%p...\n", text_ptr);
*text_ptr = 0;
return 0;
}
static int sh_mf(int, char**)
{
int rc;
int fd = open("/Banner.txt", O_RDONLY);
if (fd < 0) {
perror("open(/Banner.txt)");
return 1;
}
printf("opened /Banner.txt, calling mmap...\n");
byte* data = (byte*)mmap(nullptr, getpagesize(), PROT_READ, MAP_PRIVATE, fd, 0);
if (data == MAP_FAILED) {
perror("mmap()");
goto close_it;
}
printf("mapped file @ %p\n", data);
printf("contents: %b %b %b %b\n", data[0], data[1], data[2], data[3]);
rc = munmap(data, getpagesize());
printf("munmap() returned %d\n", rc);
close_it:
rc = close(fd);
printf("close() returned %d\n", rc);
return 0;
}
static int sh_mp(int, char**)
{
int fd = open("/kernel.map", O_RDONLY);
if (fd < 0) {
perror("open(/kernel.map)");
return 1;
}
printf("opened /kernel.map, calling mmap...\n");
byte* data = (byte*)mmap(nullptr, getpagesize() * 10, PROT_READ, MAP_PRIVATE, fd, 0);
if (data == MAP_FAILED) {
perror("mmap()");
return 1;
}
printf("mapped file @ %p\n", data);
printf("contents: %c%c%c%c%c%c%c%c...\n", data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7]);
printf("leaving it open :)\n");
return 0;
}
static int sh_exit(int, char**)
{
printf("Good-bye!\n");
@ -227,34 +116,6 @@ static bool handle_builtin(int argc, char** argv, int& retval)
retval = sh_exit(argc, argv);
return true;
}
if (!strcmp(argv[0], "fe")) {
retval = sh_fe(argc, argv);
return true;
}
if (!strcmp(argv[0], "fef")) {
retval = sh_fef(argc, argv);
return true;
}
if (!strcmp(argv[0], "busy")) {
retval = sh_busy(argc, argv);
return true;
}
if (!strcmp(argv[0], "wt")) {
retval = sh_wt(argc, argv);
return true;
}
if (!strcmp(argv[0], "mf")) {
retval = sh_mf(argc, argv);
return true;
}
if (!strcmp(argv[0], "mp")) {
retval = sh_mp(argc, argv);
return true;
}
if (!strcmp(argv[0], "fork")) {
retval = sh_fork(argc, argv);
return true;
}
return false;
}