diff mbox series

driver: fix crash with --diagnostics-plain-output [PR117942]

Message ID 20241209194018.80156-1-polacek@redhat.com
State New
Headers show
Series driver: fix crash with --diagnostics-plain-output [PR117942] | expand

Commit Message

Marek Polacek Dec. 9, 2024, 7:40 p.m. UTC
Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?

-- >8 --
We are crashing here because decode_cmdline_options_to_array has:

  if (!strcmp (opt, "-fdiagnostics-plain-output"))
    ...

but that doesn't handle the '--FLAG' variant.

gcc/ChangeLog:

	* opts-common.cc (decode_cmdline_options_to_array): Also detect
	--diagnostics-plain-output.
---
 gcc/opts-common.cc | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)


base-commit: d4525729b747827afa62320696709ca499904860

Comments

Joseph Myers Dec. 9, 2024, 9:48 p.m. UTC | #1
On Mon, 9 Dec 2024, Marek Polacek wrote:

> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
> 
> -- >8 --
> We are crashing here because decode_cmdline_options_to_array has:
> 
>   if (!strcmp (opt, "-fdiagnostics-plain-output"))
>     ...
> 
> but that doesn't handle the '--FLAG' variant.
> 
> gcc/ChangeLog:
> 
> 	* opts-common.cc (decode_cmdline_options_to_array): Also detect
> 	--diagnostics-plain-output.

OK.
diff mbox series

Patch

diff --git a/gcc/opts-common.cc b/gcc/opts-common.cc
index 2594e5a5643..e85920bcb65 100644
--- a/gcc/opts-common.cc
+++ b/gcc/opts-common.cc
@@ -1077,7 +1077,9 @@  decode_cmdline_options_to_array (unsigned int argc, const char **argv,
       /* Expand -fdiagnostics-plain-output to its constituents.  This needs
 	 to happen here so that prune_options can handle -fdiagnostics-color
 	 specially.  */
-      if (!strcmp (opt, "-fdiagnostics-plain-output"))
+      if (opt[0] == '-'
+	  && (opt[1] == '-' || opt[1] == 'f')
+	  && !strcmp (opt + 2, "diagnostics-plain-output"))
 	{
 	  /* If you have changed the default diagnostics output, and this new
 	     output is not appropriately "plain" (e.g., the change needs to be