commit c07586d9f3528ca9c280ed4dd583033c90598757
parent 3e9ef3032f0151ced1531387897ea6e8cbf1598b
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Thu, 24 May 2018 20:43:08 +0200
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.
Diffstat:
2 files changed, 12 insertions(+), 17 deletions(-)
diff --git a/src/nano.c b/src/nano.c
@@ -2440,21 +2440,18 @@ int main(int argc, char **argv)
#endif
#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)
punct = mallocstrcpy(NULL, "!.?");
-
- /* If brackets wasn't specified, set its default value. */
if (brackets == NULL)
brackets = mallocstrcpy(NULL, "\"')>]}");
-
- /* If quotestr wasn't specified, set its default value. */
if (quotestr == NULL)
quotestr = mallocstrcpy(NULL, "^([ \t]*[#:>|}])+");
- quoterc = regcomp("ereg, 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("ereg, quotestr, NANO_REG_EXTENDED);
if (quoterc == 0) {
- /* We no longer need quotestr, just quotereg. */
free(quotestr);
quotestr = NULL;
} else {
diff --git a/src/rcfile.c b/src/rcfile.c
@@ -1146,19 +1146,17 @@ void parse_rcfile(FILE *rcstream, bool syntax_only)
#endif
#ifdef ENABLE_JUSTIFY
if (strcasecmp(rcopts[i].name, "punct") == 0) {
- punct = option;
- if (has_blank_mbchars(punct)) {
+ if (has_blank_mbchars(option)) {
rcfile_error(N_("Non-blank characters required"));
- free(punct);
- punct = NULL;
- }
+ free(option);
+ } else
+ punct = option;
} else if (strcasecmp(rcopts[i].name, "brackets") == 0) {
- brackets = option;
- if (has_blank_mbchars(brackets)) {
+ if (has_blank_mbchars(option)) {
rcfile_error(N_("Non-blank characters required"));
- free(brackets);
- brackets = NULL;
- }
+ free(option);
+ } else
+ brackets = option;
} else if (strcasecmp(rcopts[i].name, "quotestr") == 0)
quotestr = option;
else