This is the mail archive of the 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]

Re: Commit: objcopy: Add --dump-section option

Nick Clifton <> writes:

> Hi Guys,
>   I am applying the attached patch to add a new command line option to
>   objcopy: --dump-section.  This option is the inverse of --add-section
>   in that it dumps the contents of a specified section to a specified
>   file.  The dump is just a raw copy of the contents of the section.  It
>   is not formatted in any way.  This is useful if the section cannot be
>   copied via the --only-section option, or if it needs to be passed to a
>   --add-section option later on.

Hi Nick,

  This patch adds a check of the return code of fwrite.  It was required
to build with full warnings enabled.    Ok to commit?


2014-03-08  Anthony Green  <>

	* objcopy.c (copy_object): Check fwrite return code.

diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index cb2be49..6215919 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -1875,7 +1875,12 @@ copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch)
 	  bfd_byte * contents = xmalloc (size);
 	  if (bfd_get_section_contents (ibfd, sec, contents, 0, size))
-	    fwrite (contents, 1, size, f);
+	    {
+	      if (fwrite (contents, 1, size, f) != size)
+		fatal (_("error writing section contents to %s (error: %s)"),
+		       pdump->filename,
+		       strerror (errno));
+	    }
 	    bfd_nonfatal_message (NULL, ibfd, sec,
 				  _("could not retrieve section contents"));

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