From: Paul Floyd Date: Sun, 27 Aug 2023 07:35:03 +0000 (+0200) Subject: Allow spaces in .valgrindrc files X-Git-Tag: VALGRIND_3_22_0~113 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=843fc19ccca36e08c8dc479dee59aedcbbc42e74;p=thirdparty%2Fvalgrind.git Allow spaces in .valgrindrc files 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 --- diff --git a/NEWS b/NEWS index 63d86bf51d..96eb06af8a 100644 --- 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 diff --git a/coregrind/m_commandline.c b/coregrind/m_commandline.c index 27c53ba705..e9fdb9bb4c 100644 --- a/coregrind/m_commandline.c +++ b/coregrind/m_commandline.c @@ -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] ); diff --git a/none/tests/Makefile.am b/none/tests/Makefile.am index c0dd7c21db..253d4a140c 100644 --- a/none/tests/Makefile.am +++ b/none/tests/Makefile.am @@ -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 index 0000000000..e69de29bb2 diff --git a/none/tests/rc_option_with_spaces.vgtest b/none/tests/rc_option_with_spaces.vgtest new file mode 100644 index 0000000000..a64dcc99b0 --- /dev/null +++ b/none/tests/rc_option_with_spaces.vgtest @@ -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