]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Allow spaces in .valgrindrc files
authorPaul Floyd <pjfloyd@wanadoo.fr>
Sun, 27 Aug 2023 07:35:03 +0000 (09:35 +0200)
committerPaul Floyd <pjfloyd@wanadoo.fr>
Sun, 27 Aug 2023 07:35:03 +0000 (09:35 +0200)
The patch for m_commandline.c comes from the Debian package files.
Also add a regtest and allow --command-line-only=no to override
--command-line-only=yes

NEWS
coregrind/m_commandline.c
none/tests/Makefile.am
none/tests/rc_option_with_spaces.stderr.exp [new file with mode: 0644]
none/tests/rc_option_with_spaces.vgtest [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 63d86bf51de0d820527878727891f016e1378d1e..96eb06af8a7c04dbf0161e39419aaf7904c8d5c6 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -52,6 +52,7 @@ are not entered into bugzilla tend to get forgotten about or ignored.
 472963  Broken regular expression in configure.ac
 473604  Fix bug472219.c compile failure with Clang 16
 473677  make check compile failure with Clang 16 based on GCC 13.x
+n-i-bz  Allow arguments with spaces in .valgrindrc files
 
 To see details of a given bug, visit
   https://bugs.kde.org/show_bug.cgi?id=XXXXXX
index 27c53ba705d53503dc476fcd8fe82641e6294f15..e9fdb9bb4c8879c165eb736d09d2b63e2d25e966 100644 (file)
@@ -98,14 +98,27 @@ static void add_args_from_string ( HChar* s )
 {
    HChar* tmp;
    HChar* cp = s;
+   int quoted = '\0';
    vg_assert(cp);
    while (True) {
+      HChar* out;
       // We have alternating sequences: blanks, non-blanks, blanks...
       // copy the non-blanks sequences, and add terminating '\0'
+      // deal with " or '-quoted strings properly.
       while (VG_(isspace)(*cp)) cp++;
       if (*cp == 0) break;
-      tmp = cp;
-      while ( !VG_(isspace)(*cp) && *cp != 0 ) cp++;
+      tmp = out = cp;
+      while ( (quoted || !VG_(isspace)(*cp)) && *cp) {
+          if (*cp == quoted) {
+              quoted = '\0';
+          } else if (*cp == '\'' || *cp == '"') {
+              quoted = *cp;
+          } else {
+              *out++ = *cp;
+          }
+          cp++;
+      }
+      if (out < cp) *out++ = '\0';
       if ( *cp != 0 ) *cp++ = '\0';       // terminate if not the last
       add_string( VG_(args_for_valgrind), tmp );
    }
@@ -188,6 +201,10 @@ void VG_(split_up_argv)( Int argc, HChar** argv )
       }
       if (0 == VG_(strcmp)(argv[i], "--command-line-only=yes"))
          augment = False;
+      /* mainly to allow overriding the regtest default */
+      if (0 == VG_(strcmp)(argv[i], "--command-line-only=no")) {
+         augment = True;
+      }
       if (argv[i][0] != '-')
        break;
       add_string( tmp_xarray, argv[i] );
index c0dd7c21dbf3ac9dc78a9c429a366f4f0e93a438..253d4a140c1af9c82efe9120eadd14e52bdb2c93 100644 (file)
@@ -188,6 +188,7 @@ EXTRA_DIST = \
        pth_stackalign.stdout.exp pth_stackalign.vgtest \
        pth_2sig.stderr.exp-linux pth_2sig.stderr.exp-solaris pth_2sig.vgtest \
        pth_term_signal.stderr.exp pth_term_signal.vgtest \
+       rc_option_with_spaces.stderr.exp rc_option_with_spaces.vgtest \
        rcrl.stderr.exp rcrl.stdout.exp rcrl.vgtest \
        readline1.stderr.exp readline1.stdout.exp \
        readline1.vgtest \
diff --git a/none/tests/rc_option_with_spaces.stderr.exp b/none/tests/rc_option_with_spaces.stderr.exp
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/none/tests/rc_option_with_spaces.vgtest b/none/tests/rc_option_with_spaces.vgtest
new file mode 100644 (file)
index 0000000..a64dcc9
--- /dev/null
@@ -0,0 +1,5 @@
+prereq: echo "--log-file='file with spaces.log'" > .valgrindrc
+vgopts: --command-line-only=no
+prog: ../../tests/true
+post: test -f "./file with spaces.log"
+cleanup: rm -f "./file with spaces.log" ./.valgrindrc