From 6549dede60bc1b2dde4e29aad19cf7ec71076c96 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 30 Aug 2018 15:47:44 +0200 Subject: Sanitize C++11 --- src/loginform.cpp | 4 ++-- src/main.cpp | 14 ++++++++------ src/mainwindow.cpp | 8 ++++---- src/namereplace.cpp | 2 +- src/x11util.cpp | 21 +++++++++++---------- src/x11util.h | 3 ++- 6 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/loginform.cpp b/src/loginform.cpp index 9473875..6e58d94 100644 --- a/src/loginform.cpp +++ b/src/loginform.cpp @@ -113,7 +113,7 @@ void LoginForm::startAuthentication() Global::greeter()->authenticate(username); } -void LoginForm::onPrompt(QString prompt, QLightDM::Greeter::PromptType promptType) +void LoginForm::onPrompt(QString prompt, QLightDM::Greeter::PromptType /* promptType */) { std::cerr << "Prompt: " << prompt.toStdString() << std::endl; Global::greeter()->respond(ui->passwordInput->text()); @@ -129,7 +129,7 @@ void LoginForm::leaveDropDownActivated(int index) else if (actionName == "suspend") Global::power()->suspend(); } -void LoginForm::onMessage(QString message, QLightDM::Greeter::MessageType type) +void LoginForm::onMessage(QString message, QLightDM::Greeter::MessageType /* type */) { std::cerr << "Message: " << message.toStdString() << std::endl; showMessage(message, false); diff --git a/src/main.cpp b/src/main.cpp index fdaada9..3b61d30 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -129,8 +129,8 @@ int main(int argc, char *argv[]) sigemptyset(&usr1.sa_mask); usr1.sa_flags = SA_RESTART; - QSocketNotifier *sn = NULL; - if (sigaction(SIGUSR1, &usr1, 0) == 0 && ::socketpair(AF_UNIX, SOCK_STREAM, 0, sockets) == 0) { + QSocketNotifier *sn = nullptr; + if (sigaction(SIGUSR1, &usr1, nullptr) == 0 && ::socketpair(AF_UNIX, SOCK_STREAM, 0, sockets) == 0) { sn = new QSocketNotifier(sockets[1], QSocketNotifier::Read); QObject::connect(sn, &QSocketNotifier::activated, [](int fd) { char tmp[1000]; @@ -140,13 +140,13 @@ int main(int argc, char *argv[]) // Now set up all the screens QPainter painter(&entire); - MainWindow *focusWindow = 0; + MainWindow *focusWindow = nullptr; QMapIterator it(screens); while (it.hasNext()) { it.next(); MainWindow *w = new MainWindow(primary == it.key(), it.key(), it.value()); w->show(); - if (sn != NULL) { + if (sn != nullptr) { QObject::connect(sn, SIGNAL(activated(int)), w, SLOT(showStandby())); } if (w->showLoginForm()) { @@ -160,7 +160,8 @@ int main(int argc, char *argv[]) if (!entire.isNull()) { qWarning() << "Setting x background"; - AddPixmapToBackground(entire.constBits(), entire.width(), entire.height(), 24, entire.bytesPerLine(), entire.byteCount()); + AddPixmapToBackground(entire.constBits(), entire.width(), entire.height(), + 24, entire.bytesPerLine(), entire.byteCount()); } // Ensure we set the primary screen's widget as active when there @@ -179,7 +180,8 @@ static void createSimpleBackground() if (img.isNull()) return; img = img.scaled(QApplication::desktop()->size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); - AddPixmapToBackground(img.constBits(), img.width(), img.height(), 24, img.bytesPerLine(), img.byteCount()); + AddPixmapToBackground(img.constBits(), img.width(), img.height(), + 24, img.bytesPerLine(), img.byteCount()); } static void sigUsr1(int) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 0ebdb59..b66a73d 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -31,7 +31,7 @@ MainWindow::MainWindow(bool primary, int screen, const QRect &screenRect, QWidge QWidget(parent), m_ScreenRect(screenRect), m_Primary(primary), - m_LoginForm(NULL), + m_LoginForm(nullptr), m_messages(nullptr), m_Clock(nullptr) { @@ -310,7 +310,7 @@ void MainWindow::setBackground() void MainWindow::showStandby() { - if (m_LoginForm != NULL) { + if (m_LoginForm != nullptr) { m_LoginForm->hide(); } QSvgWidget *img = new QSvgWidget(":/resources/gnome-face-tired.svg", this); @@ -324,7 +324,7 @@ void MainWindow::showStandby() QTimer::singleShot(4000, [this, img]() { img->hide(); img->deleteLater(); - if (this->m_LoginForm != NULL) { + if (this->m_LoginForm != nullptr) { m_LoginForm->show(); } }); @@ -346,6 +346,6 @@ int MainWindow::drawClock() QLocale loc; m_Clock->setText(time.toString(loc.dateFormat() + " HH:mm ")); m_Clock->adjustSize(); - ((QWidget*)m_Clock->parent())->adjustSize(); + reinterpret_cast(m_Clock->parent())->adjustSize(); return (60 - time.time().second()) * 1000 + 100; } diff --git a/src/namereplace.cpp b/src/namereplace.cpp index 36d834d..cc93025 100644 --- a/src/namereplace.cpp +++ b/src/namereplace.cpp @@ -45,7 +45,7 @@ void NameReplace::loadSubs() QString replace = line.mid(first + 1, second - first - 1).replace(QString("\\") + delim, QString(delim)); QString flags = line.mid(second + 1); // ... - QRegularExpression::PatternOptions opts = 0; + QRegularExpression::PatternOptions opts = QRegularExpression::NoPatternOption; if (flags.contains("i")) { opts |= QRegularExpression::CaseInsensitiveOption; } diff --git a/src/x11util.cpp b/src/x11util.cpp index f56d31e..775f072 100644 --- a/src/x11util.cpp +++ b/src/x11util.cpp @@ -16,15 +16,16 @@ static int eHandler(Display* dpy, XErrorEvent* e) } extern "C" -void AddPixmapToBackground(unsigned const char* imgData, int width, int height, int depth, int bytesPerLine, int byteCount) +void AddPixmapToBackground(unsigned const char* imgData, const unsigned int width, const unsigned int height, + const unsigned int depth, const int bytesPerLine, const size_t byteCount) { Pixmap pix = 0; - GC gc = NULL; - XImage *xi = NULL; + GC gc = nullptr; + XImage *xi = nullptr; XGCValues gc_init; memset(&gc_init, 0, sizeof(gc_init)); - Display* dpy = XOpenDisplay(NULL); - if (dpy == NULL) + Display* dpy = XOpenDisplay(nullptr); + if (dpy == nullptr) return; XSetErrorHandler(&eHandler); int screen = DefaultScreen(dpy); @@ -32,7 +33,7 @@ void AddPixmapToBackground(unsigned const char* imgData, int width, int height, char *data = (char*)malloc(byteCount); memcpy(data, imgData, byteCount); xi = XCreateImage(dpy, CopyFromParent, depth, ZPixmap, 0, data, width, height, 32, bytesPerLine); - if (xi == NULL) + if (xi == nullptr) goto cleanup; pix = XCreatePixmap(dpy, root, width, height, (unsigned int)DefaultDepth(dpy, screen)); if (pix == 0) @@ -40,23 +41,23 @@ void AddPixmapToBackground(unsigned const char* imgData, int width, int height, gc_init.foreground = BlackPixel(dpy, screen); gc_init.background = WhitePixel(dpy, screen); gc = XCreateGC(dpy, pix, GCForeground|GCBackground, &gc_init); - if (gc == NULL) + if (gc == nullptr) goto cleanup; int res1, res2, res3; res1 = XPutImage(dpy, pix, gc, xi, 0, 0, 0, 0, width, height); res2 = XSetWindowBackgroundPixmap(dpy, root, pix); res3 = XClearWindow(dpy, root); cleanup: - if (gc != NULL) { + if (gc != nullptr) { XFreeGC(dpy, gc); } if (pix != 0) { XFreePixmap(dpy, pix); } - if (xi != NULL) { + if (xi != nullptr) { XDestroyImage(xi); } - if (dpy != NULL) { + if (dpy != nullptr) { XCloseDisplay(dpy); } } diff --git a/src/x11util.h b/src/x11util.h index 81ac0c0..5f8d3e5 100644 --- a/src/x11util.h +++ b/src/x11util.h @@ -3,7 +3,8 @@ extern "C" { #include - void AddPixmapToBackground(unsigned const char* imgData, int width, int height, int depth, int bytesPerLine, int byteCount); + void AddPixmapToBackground(unsigned const char* imgData, const unsigned int width, const unsigned int height, + const unsigned int depth, const int bytesPerLine, const size_t byteCount); } #endif /* X11UTIL_H_ */ -- cgit v1.2.3-55-g7522