tweaks: condense some repetitious comments, and check before assigning

Check that the option argument is okay (contains no blank characters),
before assigning it to the relevant variable.
This commit is contained in:
Benno Schulenberg 2018-05-24 20:43:08 +02:00
parent 3e9ef3032f
commit c07586d9f3
2 changed files with 12 additions and 17 deletions

View File

@ -2440,21 +2440,18 @@ int main(int argc, char **argv)
#endif #endif
#ifdef ENABLE_JUSTIFY #ifdef ENABLE_JUSTIFY
/* If punct wasn't specified, set its default value. */ /* Set the default value for things that weren't specified. */
if (punct == NULL) if (punct == NULL)
punct = mallocstrcpy(NULL, "!.?"); punct = mallocstrcpy(NULL, "!.?");
/* If brackets wasn't specified, set its default value. */
if (brackets == NULL) if (brackets == NULL)
brackets = mallocstrcpy(NULL, "\"')>]}"); brackets = mallocstrcpy(NULL, "\"')>]}");
/* If quotestr wasn't specified, set its default value. */
if (quotestr == NULL) if (quotestr == NULL)
quotestr = mallocstrcpy(NULL, "^([ \t]*[#:>|}])+"); quotestr = mallocstrcpy(NULL, "^([ \t]*[#:>|}])+");
quoterc = regcomp(&quotereg, quotestr, NANO_REG_EXTENDED);
/* Compile the quoting regex, and free it when it's good; otherwise,
* retrieve and store the error message, to be shown when justifying. */
quoterc = regcomp(&quotereg, quotestr, NANO_REG_EXTENDED);
if (quoterc == 0) { if (quoterc == 0) {
/* We no longer need quotestr, just quotereg. */
free(quotestr); free(quotestr);
quotestr = NULL; quotestr = NULL;
} else { } else {

View File

@ -1146,19 +1146,17 @@ void parse_rcfile(FILE *rcstream, bool syntax_only)
#endif #endif
#ifdef ENABLE_JUSTIFY #ifdef ENABLE_JUSTIFY
if (strcasecmp(rcopts[i].name, "punct") == 0) { if (strcasecmp(rcopts[i].name, "punct") == 0) {
if (has_blank_mbchars(option)) {
rcfile_error(N_("Non-blank characters required"));
free(option);
} else
punct = option; punct = option;
if (has_blank_mbchars(punct)) {
rcfile_error(N_("Non-blank characters required"));
free(punct);
punct = NULL;
}
} else if (strcasecmp(rcopts[i].name, "brackets") == 0) { } else if (strcasecmp(rcopts[i].name, "brackets") == 0) {
brackets = option; if (has_blank_mbchars(option)) {
if (has_blank_mbchars(brackets)) {
rcfile_error(N_("Non-blank characters required")); rcfile_error(N_("Non-blank characters required"));
free(brackets); free(option);
brackets = NULL; } else
} brackets = option;
} else if (strcasecmp(rcopts[i].name, "quotestr") == 0) } else if (strcasecmp(rcopts[i].name, "quotestr") == 0)
quotestr = option; quotestr = option;
else else