This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] have chew stop dropping the first line in, e.g., CODE_FRAGMENT


Hi.

I was adding a CODE_FRAGMENT and noticed that the first line
of my fragment was being discarded.
That led to finding a couple of bugs in chew.

1) The loop in outputdots doesn't handle the first line properly.

With this change, one may wish to go back and edit some files now that
the first line is no longer discarded.  I can do that if you want,
or leave it to a follow-up patch.  I can imagine this bug has been there
awhile, so I didn't consider doing any cleanup as urgent.

2) skip_past_newline will also skip passed NUL.
I just noticed this by observation, I didn't trip over it.

Ok to commit?

2014-08-04  Doug Evans  <dje@google.com>

	* bfd-in2.h: Regenerate.
	* libcoff.h: Regenerate.

	doc/
	* chew.c (skip_past_newline_1): New function.
	(outputdots): Call it.
	(skip_past_newline): Ditto.

diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index 3886adc..8c77c81 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -1022,6 +1022,7 @@ extern struct coff_comdat_info * bfd_coff_get_comdat_section
 void bfd_init (void);
 
 /* Extracted from opncls.c.  */
+/* Set to N to open the next N BFDs using an alternate id space.  */
 extern unsigned int bfd_use_reserved_id;
 bfd *bfd_fopen (const char *filename, const char *target,
     const char *mode, int fd);
@@ -1206,6 +1207,7 @@ void *bfd_mmap (bfd *abfd, void *addr, bfd_size_type len,
 
 /* Extracted from bfdwin.c.  */
 /* Extracted from section.c.  */
+
 typedef struct bfd_section
 {
   /* The name of the section; the name isn't a copy, the pointer is
@@ -2344,6 +2346,7 @@ unsigned int bfd_arch_mach_octets_per_byte
    (enum bfd_architecture arch, unsigned long machine);
 
 /* Extracted from reloc.c.  */
+
 typedef enum bfd_reloc_status
 {
   /* No errors detected.  */
@@ -2393,6 +2396,7 @@ typedef struct reloc_cache_entry
 }
 arelent;
 
+
 enum complain_overflow
 {
   /* Do not complain on overflow.  */
@@ -2411,6 +2415,7 @@ enum complain_overflow
      unsigned number.  */
   complain_overflow_unsigned
 };
+struct bfd_symbol;             /* Forward declaration.  */
 
 struct reloc_howto_struct
 {
@@ -6027,6 +6032,7 @@ assembler and not (currently) written to any object files.  */
 /* Adapteva EPIPHANY - 8 bit immediate for 16 bit mov instruction.  */
   BFD_RELOC_EPIPHANY_IMM8,
   BFD_RELOC_UNUSED };
+
 typedef enum bfd_reloc_code_real bfd_reloc_code_real_type;
 reloc_howto_type *bfd_reloc_type_lookup
    (bfd *abfd, bfd_reloc_code_real_type code);
@@ -6224,6 +6230,7 @@ bfd_boolean bfd_copy_private_symbol_data
             (ibfd, isymbol, obfd, osymbol))
 
 /* Extracted from bfd.c.  */
+
 enum bfd_direction
   {
     no_direction = 0,
@@ -6508,6 +6515,7 @@ bfd_set_cacheable (bfd * abfd, bfd_boolean val)
   return TRUE;
 }
 
+
 typedef enum bfd_error
 {
   bfd_error_no_error = 0,
@@ -6543,6 +6551,7 @@ const char *bfd_errmsg (bfd_error_type error_tag);
 
 void bfd_perror (const char *message);
 
+
 typedef void (*bfd_error_handler_type) (const char *, ...);
 
 bfd_error_handler_type bfd_set_error_handler (bfd_error_handler_type);
@@ -6551,6 +6560,7 @@ void bfd_set_error_program_name (const char *);
 
 bfd_error_handler_type bfd_get_error_handler (void);
 
+
 typedef void (*bfd_assert_handler_type) (const char *bfd_formatmsg,
                                          const char *bfd_version,
                                          const char *bfd_file,
diff --git a/bfd/doc/chew.c b/bfd/doc/chew.c
index 1f81cae..8405ec4 100644
--- a/bfd/doc/chew.c
+++ b/bfd/doc/chew.c
@@ -265,6 +265,19 @@ skip_white_and_stars (src, idx)
   return idx;
 }
 
+static unsigned int
+skip_past_newline_1 (ptr, idx)
+     string_type *ptr;
+     unsigned int idx;
+{
+  while (at (ptr, idx)
+	 && at (ptr, idx) != '\n')
+    idx++;
+  if (at (ptr, idx) == '\n')
+    return idx + 1;
+  return idx;
+}
+
 /***********************************************************************/
 
 string_type stack[STACK];
@@ -601,10 +614,12 @@ outputdots ()
 
   while (at (tos, idx))
     {
-      if (at (tos, idx) == '\n' && at (tos, idx + 1) == '.')
+      /* Every iteration begins at the start of a line.  */
+      if (at (tos, idx) == '.')
 	{
 	  char c;
-	  idx += 2;
+
+	  idx++;
 
 	  while ((c = at (tos, idx)) && c != '\n')
 	    {
@@ -624,11 +639,13 @@ outputdots ()
 		  idx++;
 		}
 	    }
+	  if (c == '\n')
+	    idx++;
 	  catchar (&out, '\n');
 	}
       else
 	{
-	  idx++;
+	  idx = skip_past_newline_1 (tos, idx);
 	}
     }
 
@@ -1093,10 +1110,7 @@ icatstr ()
 static void
 skip_past_newline ()
 {
-  while (at (ptr, idx)
-	 && at (ptr, idx) != '\n')
-    idx++;
-  idx++;
+  idx = skip_past_newline_1 (ptr, idx);
   pc++;
 }
 
diff --git a/bfd/libcoff.h b/bfd/libcoff.h
index d2c794d..540ddf9 100644
--- a/bfd/libcoff.h
+++ b/bfd/libcoff.h
@@ -625,6 +625,7 @@ extern bfd_boolean ppc_allocate_toc_section
 extern bfd_boolean ppc_process_before_allocation
   (bfd *, struct bfd_link_info *);
 /* Extracted from coffcode.h.  */
+
 typedef struct coff_ptr_struct
 {
   /* Remembers the offset from the first symbol in the file for


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]