Repository: lucy-charmonizer
Updated Branches:
  refs/heads/master d2547ec4f -> e1cc19923


Trim whitespace around 'cc' argument

Some Perl setups have a 'cc' config value with leading whitespace.


Project: http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/commit/e1cc1992
Tree: http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/tree/e1cc1992
Diff: http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/diff/e1cc1992

Branch: refs/heads/master
Commit: e1cc199239ceff488b092b25a74e51aa2e8f31c9
Parents: d2547ec
Author: Nick Wellnhofer <[email protected]>
Authored: Fri Sep 5 21:09:16 2014 +0200
Committer: Nick Wellnhofer <[email protected]>
Committed: Fri Sep 5 21:27:06 2014 +0200

----------------------------------------------------------------------
 src/Charmonizer/Probe.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/e1cc1992/src/Charmonizer/Probe.c
----------------------------------------------------------------------
diff --git a/src/Charmonizer/Probe.c b/src/Charmonizer/Probe.c
index 8e6e98f..4f5bbd6 100644
--- a/src/Charmonizer/Probe.c
+++ b/src/Charmonizer/Probe.c
@@ -17,6 +17,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <ctype.h>
 #include "Charmonizer/Probe.h"
 #include "Charmonizer/Core/HeaderChecker.h"
 #include "Charmonizer/Core/ConfWriter.h"
@@ -69,11 +70,30 @@ chaz_Probe_parse_cli_args(int argc, const char *argv[],
             args->code_coverage = 1;
         }
         else if (memcmp(arg, "--cc=", 5) == 0) {
-            if (strlen(arg) > CHAZ_PROBE_MAX_CC_LEN - 5) {
+            size_t len = strlen(arg);
+            size_t l   = 5;
+            size_t r   = len;
+            size_t trimmed_len;
+
+            if (len > CHAZ_PROBE_MAX_CC_LEN - 5) {
                 fprintf(stderr, "Exceeded max length for compiler command");
                 exit(1);
             }
-            strcpy(args->cc, arg + 5);
+
+            /*
+             * Some Perl setups have a 'cc' config value with leading
+             * whitespace.
+             */
+            while (isspace(arg[l])) {
+                ++l;
+            }
+            while (r > l && isspace(arg[r-1])) {
+                --r;
+            }
+
+            trimmed_len = r - l;
+            memcpy(args->cc, arg + l, trimmed_len);
+            args->cc[trimmed_len] = '\0';
         }
     } /* preserve value of i */
 

Reply via email to