[1/7] Change completion_tracker to use char type

Message ID 87d0uridpt.fsf@tromey.com
State New, archived
Headers

Commit Message

Tom Tromey Aug. 9, 2018, 6:42 p.m. UTC
  >>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:

Pedro> See comment about use of int vs char here:
Pedro>  https://sourceware.org/ml/gdb-patches/2017-07/msg00228.html
Pedro> Look for "Why int".

Thanks.  How about just this patch, that adds a couple of casts at the
necessary spots?

Tom

commit 5683b8e5ff3dabcea180e0ce84c236189f047cb0
Author: Tom Tromey <tom@tromey.com>
Date:   Thu Aug 9 12:38:39 2018 -0600

    Avoid -Wnarrowing warnings from quote_char()
    
    This adds a couple of casts to avoid -Wnarrowing warnings coming from
    the use of quote_char().
    
    2018-08-09  Tom Tromey  <tom@tromey.com>
    
            * linespec.c (complete_linespec_component): Add cast to "char".
            * completer.c (completion_tracker::build_completion_result): Add
            cast to "char".
  

Comments

Pedro Alves Aug. 9, 2018, 6:50 p.m. UTC | #1
On 08/09/2018 07:42 PM, Tom Tromey wrote:
>>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:
> 
> Pedro> See comment about use of int vs char here:
> Pedro>  https://sourceware.org/ml/gdb-patches/2017-07/msg00228.html
> Pedro> Look for "Why int".
> 
> Thanks.  How about just this patch, that adds a couple of casts at the
> necessary spots?

LGTM.

Thanks,
Pedro Alves
  

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index b405915c43..2a284fbc10 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,11 @@ 
 2018-08-09  Tom Tromey  <tom@tromey.com>
 
+	* linespec.c (complete_linespec_component): Add cast to "char".
+	* completer.c (completion_tracker::build_completion_result): Add
+	cast to "char".
+
+2018-08-09  Tom Tromey  <tom@tromey.com>
+
 	* riscv-tdep.h: Minor formatting fixes.
 
 2018-08-09  Simon Marchi  <simon.marchi@ericsson.com>
diff --git a/gdb/completer.c b/gdb/completer.c
index 3e87ed454c..1c285262de 100644
--- a/gdb/completer.c
+++ b/gdb/completer.c
@@ -2032,7 +2032,7 @@  completion_tracker::build_completion_result (const char *text,
       /* We don't rely on readline appending the quote char as
 	 delimiter as then readline wouldn't append the ' ' after the
 	 completion.  */
-      char buf[2] = { quote_char () };
+      char buf[2] = { (char) quote_char () };
 
       match_list[0] = reconcat (match_list[0], match_list[0],
 				buf, (char *) NULL);
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 790ddf4740..dcaaaefaaa 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -2894,7 +2894,7 @@  complete_linespec_component (linespec_parser *parser,
 	     new "quote" char.  */
 	  if (tracker.quote_char ())
 	    {
-	      char quote_char_str[2] = { tracker.quote_char () };
+	      char quote_char_str[2] = { (char) tracker.quote_char () };
 
 	      fn = reconcat (fn, fn, quote_char_str, (char *) NULL);
 	      tracker.set_quote_char (':');