ls: fix a bug where we may use uninintialized variable
This commit is contained in:
parent
4b8171cd7a
commit
51f1b6c0e0
@ -837,7 +837,8 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
int dnfiles;
|
int dnfiles;
|
||||||
int dndirs;
|
int dndirs;
|
||||||
int i;
|
int i;
|
||||||
USE_FEATURE_LS_COLOR(char *color_opt;)
|
/* need to initialize since --color has _an optional_ argument */
|
||||||
|
USE_FEATURE_LS_COLOR(const char *color_opt = "always";)
|
||||||
|
|
||||||
INIT_G();
|
INIT_G();
|
||||||
|
|
||||||
@ -888,15 +889,15 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
if (ENABLE_FEATURE_LS_COLOR_IS_DEFAULT && isatty(STDOUT_FILENO)) {
|
if (ENABLE_FEATURE_LS_COLOR_IS_DEFAULT && isatty(STDOUT_FILENO)) {
|
||||||
char *p = getenv("LS_COLORS");
|
char *p = getenv("LS_COLORS");
|
||||||
/* LS_COLORS is unset, or (not empty && not "none") ? */
|
/* LS_COLORS is unset, or (not empty && not "none") ? */
|
||||||
if (!p || (p[0] && strcmp(p, "none")))
|
if (!p || (p[0] && strcmp(p, "none") != 0))
|
||||||
show_color = 1;
|
show_color = 1;
|
||||||
}
|
}
|
||||||
if (opt & (1 << i)) { /* next flag after short options */
|
if (opt & (1 << i)) { /* next flag after short options */
|
||||||
if (!color_opt || !strcmp("always", color_opt))
|
if (strcmp("always", color_opt) == 0)
|
||||||
show_color = 1;
|
show_color = 1;
|
||||||
else if (color_opt && !strcmp("never", color_opt))
|
else if (strcmp("never", color_opt) == 0)
|
||||||
show_color = 0;
|
show_color = 0;
|
||||||
else if (color_opt && !strcmp("auto", color_opt) && isatty(STDOUT_FILENO))
|
else if (strcmp("auto", color_opt) == 0 && isatty(STDOUT_FILENO))
|
||||||
show_color = 1;
|
show_color = 1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user