From cddb87420bad8e61f0cddfa1028dc0c87fb9ba04 Mon Sep 17 00:00:00 2001 From: jakob Date: Thu, 6 Jul 2017 16:52:32 +0200 Subject: [PATCH 1/2] Fix overwrite of getopt optind Using 'optind' in getopt_long() shadows actual 'optind' being provided by getopt, thus prevents any future options change from using optind. See https://www.gnu.org/software/libc/manual/html_node/Getopt-Long-Options.html#index-getopt_005flong --- i3lock.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/i3lock.c b/i3lock.c index 87a77b1..af678aa 100644 --- a/i3lock.c +++ b/i3lock.c @@ -819,7 +819,7 @@ int main(int argc, char *argv[]) { #endif int curs_choice = CURS_NONE; int o; - int optind = 0; + int longoptind = 0; struct option longopts[] = { {"version", no_argument, NULL, 'v'}, {"nofork", no_argument, NULL, 'n'}, @@ -843,7 +843,7 @@ int main(int argc, char *argv[]) { errx(EXIT_FAILURE, "pw->pw_name is NULL.\n"); char *optstring = "hvnbdc:p:ui:teI:f"; - while ((o = getopt_long(argc, argv, optstring, longopts, &optind)) != -1) { + while ((o = getopt_long(argc, argv, optstring, longopts, &longoptind)) != -1) { switch (o) { case 'v': errx(EXIT_SUCCESS, "version " VERSION " © 2010 Michael Stapelberg"); @@ -894,7 +894,7 @@ int main(int argc, char *argv[]) { ignore_empty_password = true; break; case 0: - if (strcmp(longopts[optind].name, "debug") == 0) + if (strcmp(longopts[longoptind].name, "debug") == 0) debug_mode = true; break; case 'f': From 76d9960dbe86d3f32fbed054e5e27d2903aea710 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Sun, 13 Aug 2017 18:06:04 +0300 Subject: [PATCH 2/2] Change the locale discovery procedure to treat empty string same as unset This is explained in the commit message here: https://github.com/xkbcommon/libxkbcommon/commit/f468f0b2430e15cc262c5745445580bd0dc64ef0 --- i3lock.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/i3lock.c b/i3lock.c index 87a77b1..208e4ac 100644 --- a/i3lock.c +++ b/i3lock.c @@ -977,11 +977,11 @@ int main(int argc, char *argv[]) { errx(EXIT_FAILURE, "Could not load keymap"); const char *locale = getenv("LC_ALL"); - if (!locale) + if (!locale || !*locale) locale = getenv("LC_CTYPE"); - if (!locale) + if (!locale || !*locale) locale = getenv("LANG"); - if (!locale) { + if (!locale || !*locale) { if (debug_mode) fprintf(stderr, "Can't detect your locale, fallback to C\n"); locale = "C";