Code

Improve handling of unmatched quotes in ~/.tigrc
authorJonas Fonseca <fonseca@diku.dk>
Mon, 6 Oct 2008 19:28:50 +0000 (21:28 +0200)
committerJonas Fonseca <fonseca@diku.dk>
Mon, 6 Oct 2008 19:28:50 +0000 (21:28 +0200)
tig.c

diff --git a/tig.c b/tig.c
index 25fb237c6b1d39a2563bcf072ebcdd73614920ce..f81686b70f641aae155d15097e47331f548e7a7d 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -1171,18 +1171,17 @@ option_set_command(int argc, char *argv[])
        }
 
        if (!strcmp(argv[0], "commit-encoding")) {
-               char *arg = argv[2];
-               int delimiter = *arg;
-               int i;
+               const char *arg = argv[2];
+               int arglen = strlen(arg);
 
-               switch (delimiter) {
+               switch (arg[0]) {
                case '"':
                case '\'':
-                       for (arg++, i = 0; arg[i]; i++)
-                               if (arg[i] == delimiter) {
-                                       arg[i] = 0;
-                                       break;
-                               }
+                       if (arglen == 1 || arg[arglen - 1] != arg[0]) {
+                               config_msg = "Unmatched quotation";
+                               return ERR;
+                       }
+                       arg += 1; arglen -= 2;
                default:
                        string_ncopy(opt_encoding, arg, strlen(arg));
                        return OK;