Index: ls.1 =================================================================== --- ls.1 (revision 331729) +++ ls.1 (working copy) @@ -659,7 +659,8 @@ .Ar f is the foreground color and .Ar b -is the background color. +is the background color. If the string contains an odd number of characters, +the default value for the background is selected. .Pp The color designators are as follows: .Pp Index: print.c =================================================================== --- print.c (revision 331729) +++ print.c (working copy) @@ -611,25 +611,21 @@ void parsecolors(const char *cs) { - int i; int j; - size_t len; + size_t i; + char overrides[C_NUMCOLORS * 2]; char c[2]; short legacy_warn = 0; - if (cs == NULL) - cs = ""; /* LSCOLORS not set */ - len = strlen(cs); - for (i = 0; i < (int)C_NUMCOLORS; i++) { + strncpy(overrides, defcolors, C_NUMCOLORS * 2); + if (cs != NULL) + memcpy(overrides, cs, MIN(strlen(cs), C_NUMCOLORS * 2)); + + for (i = 0; i < C_NUMCOLORS; i++) { colors[i].bold = 0; + c[0] = overrides[2 * i]; + c[1] = overrides[2 * i + 1]; - if (len <= 2 * (size_t)i) { - c[0] = defcolors[2 * i]; - c[1] = defcolors[2 * i + 1]; - } else { - c[0] = cs[2 * i]; - c[1] = cs[2 * i + 1]; - } for (j = 0; j < 2; j++) { /* Legacy colours used 0-7 */ if (c[j] >= '0' && c[j] <= '7') {