Verified Commit 5ab9273c authored by Alexander Lohnau's avatar Alexander Lohnau 💬
Browse files

clang-tidy: Force braces around statements

parent 016f1981
......@@ -118,8 +118,9 @@ void KCheckPass::start()
int sfd[2];
char fdbuf[16];
if (m_notifier)
if (m_notifier) {
return;
}
if (::socketpair(AF_LOCAL, SOCK_STREAM, 0, sfd)) {
cantCheck();
return;
......@@ -152,14 +153,17 @@ int KCheckPass::Reader(void *buf, int count)
dord:
ret = ::read(m_fd, (void *)((char *)buf + rlen), count - rlen);
if (ret < 0) {
if (errno == EINTR)
if (errno == EINTR) {
goto dord;
if (errno == EAGAIN)
}
if (errno == EAGAIN) {
break;
}
return -1;
}
if (!ret)
if (!ret) {
break;
}
rlen += ret;
}
return rlen;
......@@ -201,14 +205,16 @@ bool KCheckPass::GRecvArr(char **ret)
int len;
char *buf;
if (!GRecvInt(&len))
if (!GRecvInt(&len)) {
return false;
}
if (!len) {
*ret = nullptr;
return true;
}
if (!(buf = (char *)::malloc(len)))
if (!(buf = (char *)::malloc(len))) {
return false;
}
*ret = buf;
if (GRead(buf, len)) {
return true;
......@@ -228,17 +234,20 @@ void KCheckPass::handleVerify()
if (GRecvInt(&ret)) {
switch (ret) {
case ConvGetBinary:
if (!GRecvArr(&arr))
if (!GRecvArr(&arr)) {
break;
}
// FIXME: not supported
cantCheck();
if (arr)
if (arr) {
::free(arr);
}
return;
case ConvGetNormal:
case ConvGetHidden: {
if (!GRecvArr(&arr))
if (!GRecvArr(&arr)) {
break;
}
if (m_password.isNull()) {
GSendStr(nullptr);
......@@ -250,19 +259,22 @@ void KCheckPass::handleVerify()
m_password.clear();
if (arr)
if (arr) {
::free(arr);
}
return;
}
case ConvPutInfo:
if (!GRecvArr(&arr))
if (!GRecvArr(&arr)) {
break;
}
emit message(QString::fromLocal8Bit(arr));
::free(arr);
return;
case ConvPutError:
if (!GRecvArr(&arr))
if (!GRecvArr(&arr)) {
break;
}
emit error(QString::fromLocal8Bit(arr));
::free(arr);
return;
......@@ -301,11 +313,12 @@ void KCheckPass::reapVerify()
::close(m_fd);
int status;
::kill(m_pid, SIGUSR2);
while (::waitpid(m_pid, &status, 0) < 0)
while (::waitpid(m_pid, &status, 0) < 0) {
if (errno != EINTR) { // This should not happen ...
cantCheck();
return;
}
}
}
void KCheckPass::cantCheck()
......
......@@ -58,14 +58,17 @@ static int Reader(void *buf, int count)
dord:
ret = read(sfd, (void *)((char *)buf + rlen), count - rlen);
if (ret < 0) {
if (errno == EINTR)
if (errno == EINTR) {
goto dord;
if (errno == EAGAIN)
}
if (errno == EAGAIN) {
break;
}
return -1;
}
if (!ret)
if (!ret) {
break;
}
rlen += ret;
}
return rlen;
......@@ -118,8 +121,9 @@ static char *GRecvStr(void)
unsigned len;
char *buf;
if (!(len = GRecvInt()))
if (!(len = GRecvInt())) {
return (char *)0;
}
if (len > 0x1000 || !(buf = malloc(len))) {
message("No memory for read buffer\n");
exit(15);
......@@ -135,8 +139,9 @@ static char *GRecvArr(void)
char *arr;
unsigned const char *up;
if (!(len = (unsigned)GRecvInt()))
if (!(len = (unsigned)GRecvInt())) {
return (char *)0;
}
if (len < 4) {
message("Too short binary authentication data block\n");
exit(15);
......@@ -169,8 +174,9 @@ static char *conv_server(ConvRequest what, const char *prompt)
char *msg;
GSendStr(prompt);
msg = GRecvStr();
if (msg && (GRecvInt() & IsPassword) && !*msg)
if (msg && (GRecvInt() & IsPassword) && !*msg) {
nullpass = 1;
}
return msg;
}
case ConvPutInfo:
......
......@@ -308,10 +308,11 @@ void UnlockApp::screenGeometryChanged(QScreen *screen, const QRect &geo)
void UnlockApp::initialViewSetup()
{
for (QScreen *screen : screens())
for (QScreen *screen : screens()) {
connect(screen, &QScreen::geometryChanged, this, [this, screen](const QRect &geo) {
screenGeometryChanged(screen, geo);
});
}
desktopResized();
}
......
......@@ -44,8 +44,9 @@ static void signalHandler(int signum)
{
ScreenLocker::UnlockApp *instance = qobject_cast<ScreenLocker::UnlockApp *>(QCoreApplication::instance());
if (!instance)
if (!instance) {
return;
}
switch (signum) {
case SIGTERM:
......
......@@ -52,10 +52,11 @@ static int PAM_conv(int num_msg, pam_message_type **msg, struct pam_response **r
struct pam_response *repl;
struct pam_data *pd = (struct pam_data *)appdata_ptr;
if (!(repl = calloc(num_msg, sizeof(struct pam_response))))
if (!(repl = calloc(num_msg, sizeof(struct pam_response)))) {
return PAM_CONV_ERR;
}
for (count = 0; count < num_msg; count++)
for (count = 0; count < num_msg; count++) {
switch (msg[count]->msg_style) {
case PAM_TEXT_INFO:
pd->conv(ConvPutInfo, msg[count]->msg);
......@@ -87,12 +88,13 @@ static int PAM_conv(int num_msg, pam_message_type **msg, struct pam_response **r
repl[count].resp_retcode = PAM_SUCCESS;
break;
}
}
*resp = repl;
return PAM_SUCCESS;
conv_err:
for (; count >= 0; count--)
if (repl[count].resp)
for (; count >= 0; count--) {
if (repl[count].resp) {
switch (msg[count]->msg_style) {
case PAM_PROMPT_ECHO_OFF:
dispose(repl[count].resp);
......@@ -104,6 +106,8 @@ conv_err:
free(repl[count].resp);
break;
}
}
}
free(repl);
return PAM_CONV_ERR;
}
......@@ -141,12 +145,14 @@ AuthReturn Authenticate(const char *method, const char *user, char *(*conv)(Conv
pam_service = KSCREENSAVER_PAM_SERVICE;
}
pam_error = pam_start(pam_service, user, &PAM_conversation, &pamh);
if (pam_error != PAM_SUCCESS)
if (pam_error != PAM_SUCCESS) {
return AuthError;
}
tty = ttyname(0);
if (!tty)
if (!tty) {
tty = getenv("DISPLAY");
}
pam_error = pam_set_item(pamh, PAM_TTY, tty);
if (pam_error != PAM_SUCCESS) {
......
......@@ -87,14 +87,17 @@ static int Reader(void *buf, int count)
dord:
ret = read(sfd, (void *)((char *)buf + rlen), count - rlen);
if (ret < 0) {
if (errno == EINTR)
if (errno == EINTR) {
goto dord;
if (errno == EAGAIN)
}
if (errno == EAGAIN) {
break;
}
return -1;
}
if (!ret)
if (!ret) {
break;
}
rlen += ret;
}
return rlen;
......@@ -147,8 +150,9 @@ static char *GRecvStr(void)
unsigned len;
char *buf;
if (!(len = GRecvInt()))
if (!(len = GRecvInt())) {
return (char *)0;
}
if (len > 0x1000 || !(buf = malloc(len))) {
message("No memory for read buffer\n");
exit(15);
......@@ -164,8 +168,9 @@ static char *GRecvArr(void)
char *arr;
unsigned const char *up;
if (!(len = (unsigned)GRecvInt()))
if (!(len = (unsigned)GRecvInt())) {
return (char *)0;
}
if (len < 4) {
message("Too short binary authentication data block\n");
exit(15);
......@@ -198,8 +203,9 @@ static char *conv_server(ConvRequest what, const char *prompt)
char *msg;
GSendStr(prompt);
msg = GRecvStr();
if (msg && (GRecvInt() & IsPassword) && !*msg)
if (msg && (GRecvInt() & IsPassword) && !*msg) {
nullpass = 1;
}
return msg;
}
case ConvPutAuthSucceeded:
......@@ -324,12 +330,14 @@ int main(int argc, char **argv)
}
uid = getuid();
if (!(p = getenv("LOGNAME")) || !(pw = getpwnam(p)) || pw->pw_uid != uid)
if (!(p = getenv("USER")) || !(pw = getpwnam(p)) || pw->pw_uid != uid)
if (!(p = getenv("LOGNAME")) || !(pw = getpwnam(p)) || pw->pw_uid != uid) {
if (!(p = getenv("USER")) || !(pw = getpwnam(p)) || pw->pw_uid != uid) {
if (!(pw = getpwuid(uid))) {
message("Cannot determinate current user\n");
return AuthError;
}
}
}
if (!(username = strdup(pw->pw_name))) {
message("Out of memory\n");
return AuthError;
......
......@@ -197,8 +197,9 @@ void X11Locker::saveVRoot()
//
void X11Locker::setVRoot(Window win, Window vr)
{
if (gVRoot)
if (gVRoot) {
removeVRoot(gVRoot);
}
unsigned long rw = QX11Info::appRootWindow();
unsigned long vroot_data[1] = {vr};
......@@ -207,14 +208,17 @@ void X11Locker::setVRoot(Window win, Window vr)
unsigned int numChildren;
Window top = win;
while (1) {
if (!XQueryTree(QX11Info::display(), top, &rootReturn, &parentReturn, &children, &numChildren))
if (!XQueryTree(QX11Info::display(), top, &rootReturn, &parentReturn, &children, &numChildren)) {
return;
if (children)
}
if (children) {
XFree((char *)children);
}
if (parentReturn == rw) {
break;
} else
} else {
top = parentReturn;
}
}
XChangeProperty(QX11Info::display(), top, gXA_VROOT, XA_WINDOW, 32, PropModeReplace, (unsigned char *)vroot_data, 1);
......@@ -342,15 +346,17 @@ bool X11Locker::nativeEventFilter(const QByteArray &eventType, void *message, lo
int index = findWindowInfo(xc->window);
if (index >= 0) {
int index2 = xc->above_sibling ? findWindowInfo(xc->above_sibling) : 0;
if (index2 < 0)
if (index2 < 0) {
qCDebug(KSCREENLOCKER) << "Unknown above for ConfigureNotify";
else { // move just above the other window
if (index2 < index)
} else { // move just above the other window
if (index2 < index) {
++index2;
}
m_windowInfo.move(index, index2);
}
} else
} else {
qCDebug(KSCREENLOCKER) << "Unknown toplevel for ConfigureNotify";
}
// kDebug() << "ConfigureNotify:";
// the stacking order changed, so let's change the stacking order again to what we want
stayOnTop();
......@@ -363,10 +369,11 @@ bool X11Locker::nativeEventFilter(const QByteArray &eventType, void *message, lo
if (xm->event == QX11Info::appRootWindow()) {
qCDebug(KSCREENLOCKER) << "MapNotify:" << xm->window;
int index = findWindowInfo(xm->window);
if (index >= 0)
if (index >= 0) {
m_windowInfo[index].viewable = true;
else
} else {
qCDebug(KSCREENLOCKER) << "Unknown toplevel for MapNotify";
}
if (m_allowedWindows.contains(xm->window)) {
if (m_lockWindows.contains(xm->window)) {
qCDebug(KSCREENLOCKER) << "uhoh! duplicate!";
......@@ -394,10 +401,11 @@ bool X11Locker::nativeEventFilter(const QByteArray &eventType, void *message, lo
if (xu->event == QX11Info::appRootWindow()) {
qCDebug(KSCREENLOCKER) << "UnmapNotify:" << xu->window;
int index = findWindowInfo(xu->window);
if (index >= 0)
if (index >= 0) {
m_windowInfo[index].viewable = false;
else
} else {
qCDebug(KSCREENLOCKER) << "Unknown toplevel for MapNotify";
}
m_lockWindows.removeAll(xu->window);
if (m_focusedLockWindow == xu->event && !m_lockWindows.empty()) {
// The currently focused window vanished, just focus the first one in the list
......@@ -412,9 +420,9 @@ bool X11Locker::nativeEventFilter(const QByteArray &eventType, void *message, lo
if (xc->parent == QX11Info::appRootWindow()) {
qCDebug(KSCREENLOCKER) << "CreateNotify:" << xc->window;
int index = findWindowInfo(xc->window);
if (index >= 0)
if (index >= 0) {
qCDebug(KSCREENLOCKER) << "Already existing toplevel for CreateNotify";
else {
} else {
WindowInfo info;
info.window = xc->window;
info.viewable = false;
......@@ -428,10 +436,11 @@ bool X11Locker::nativeEventFilter(const QByteArray &eventType, void *message, lo
xcb_destroy_notify_event_t *xd = reinterpret_cast<xcb_destroy_notify_event_t *>(event);
if (xd->event == QX11Info::appRootWindow()) {
int index = findWindowInfo(xd->window);
if (index >= 0)
if (index >= 0) {
m_windowInfo.removeAt(index);
else
} else {
qCDebug(KSCREENLOCKER) << "Unknown toplevel for DestroyNotify";
}
ret = true;
}
break;
......@@ -440,15 +449,16 @@ bool X11Locker::nativeEventFilter(const QByteArray &eventType, void *message, lo
xcb_reparent_notify_event_t *xr = reinterpret_cast<xcb_reparent_notify_event_t *>(event);
if (xr->event == QX11Info::appRootWindow() && xr->parent != QX11Info::appRootWindow()) {
int index = findWindowInfo(xr->window);
if (index >= 0)
if (index >= 0) {
m_windowInfo.removeAt(index);
else
} else {
qCDebug(KSCREENLOCKER) << "Unknown toplevel for ReparentNotify away";
}
} else if (xr->parent == QX11Info::appRootWindow()) {
int index = findWindowInfo(xr->window);
if (index >= 0)
if (index >= 0) {
qCDebug(KSCREENLOCKER) << "Already existing toplevel for ReparentNotify";
else {
} else {
WindowInfo info;
info.window = xr->window;
info.viewable = false;
......@@ -463,8 +473,9 @@ bool X11Locker::nativeEventFilter(const QByteArray &eventType, void *message, lo
int index = findWindowInfo(xc->window);
if (index >= 0) {
m_windowInfo.move(index, xc->place == PlaceOnTop ? m_windowInfo.size() - 1 : 0);
} else
} else {
qCDebug(KSCREENLOCKER) << "Unknown toplevel for CirculateNotify";
}
}
break;
}
......@@ -474,9 +485,11 @@ bool X11Locker::nativeEventFilter(const QByteArray &eventType, void *message, lo
int X11Locker::findWindowInfo(Window w)
{
for (int i = 0; i < m_windowInfo.size(); ++i)
if (m_windowInfo[i].window == w)
for (int i = 0; i < m_windowInfo.size(); ++i) {
if (m_windowInfo[i].window == w) {
return i;
}
}
return -1;
}
......@@ -489,14 +502,16 @@ void X11Locker::stayOnTop()
// thus avoiding possible infinite loops
QVector<Window> stack(m_lockWindows.count() + 1);
int count = 0;
for (WId w : qAsConst(m_lockWindows))
for (WId w : qAsConst(m_lockWindows)) {
stack[count++] = w;
}
// finally, the lock window
stack[count++] = m_background->winId();
// do the actual restacking if needed
XRaiseWindow(QX11Info::display(), stack[0]);
if (count > 1)
if (count > 1) {
XRestackWindows(QX11Info::display(), stack.data(), count);
}
XFlush(QX11Info::display());
}
......
Supports Markdown
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