2003-08-12 Andrew Cagney <cagney@redhat.com>
authorAndrew Cagney <cagney@redhat.com>
Tue, 12 Aug 2003 19:34:20 +0000 (19:34 +0000)
committerAndrew Cagney <cagney@redhat.com>
Tue, 12 Aug 2003 19:34:20 +0000 (19:34 +0000)
* Makefile.in (dsrec.o): Update dependencies.
* dsrec.c: Include "gdb_assert.h".
(make_srec): Use snprintf instead of sprintf, use a literal format
string.

gdb/ChangeLog
gdb/Makefile.in
gdb/dsrec.c

index cd4da94c518ad67b5c7870230fae506148fd619a..a68614f225d8e04e5708383c47143ee1b1a3bba5 100644 (file)
@@ -1,3 +1,10 @@
+2003-08-12  Andrew Cagney  <cagney@redhat.com>
+
+       * Makefile.in (dsrec.o): Update dependencies.
+       * dsrec.c: Include "gdb_assert.h".
+       (make_srec): Use snprintf instead of sprintf, use a literal format
+       string.
+
 2003-08-12  Andrew Cagney  <cagney@redhat.com>
 
        * frame.c (deprecated_frame_xmalloc): Use XMALLOC, instead of
index 23896f7e941e966f882eadca1c373a0c3891f22a..436ea1f2936417ee78cf9cd03c95bbd09a809b2f 100644 (file)
@@ -1687,7 +1687,7 @@ disasm.o: disasm.c $(defs_h) $(target_h) $(value_h) $(ui_out_h) \
 doublest.o: doublest.c $(defs_h) $(doublest_h) $(floatformat_h) \
        $(gdb_assert_h) $(gdb_string_h) $(gdbtypes_h)
 dpx2-nat.o: dpx2-nat.c $(defs_h) $(gdbcore_h) $(gdb_string_h)
-dsrec.o: dsrec.c $(defs_h) $(serial_h) $(srec_h)
+dsrec.o: dsrec.c $(defs_h) $(serial_h) $(srec_h) $(gdb_assert_h)
 dummy-frame.o: dummy-frame.c $(defs_h) $(dummy_frame_h) $(regcache_h) \
        $(frame_h) $(inferior_h) $(gdb_assert_h) $(frame_unwind_h) \
        $(command_h) $(gdbcmd_h)
index 5f2c2d703ceea69cf5d6ca1ccab00914e0bf584f..4f111bb810ba42d72085ec9e7fae10f8018c229c 100644 (file)
@@ -23,6 +23,7 @@
 #include "serial.h"
 #include "srec.h"
 #include <time.h>
+#include "gdb_assert.h"
 
 extern void report_transfer_performance (unsigned long, time_t, time_t);
 
@@ -223,10 +224,6 @@ make_srec (char *srec, CORE_ADDR targ_addr, bfd *abfd, asection *sect,
   const static char data_code_table[] = "123";
   const static char term_code_table[] = "987";
   const static char header_code_table[] = "000";
-  const static char *formats[] =
-  {"S%c%02X%04X",
-   "S%c%02X%06X",
-   "S%c%02X%08X"};
   char const *code_table;
   int addr_size;
   int payload_size;
@@ -271,9 +268,10 @@ make_srec (char *srec, CORE_ADDR targ_addr, bfd *abfd, asection *sect,
     payload_size = 0;          /* Term or header packets have no payload */
 
   /* Output the header.  */
-
-  sprintf (srec, formats[addr_size - 2], code_table[addr_size - 2],
-          addr_size + payload_size + 1, (int) targ_addr);
+  snprintf (srec, (*maxrecsize) + 1, "S%c%02X%0*X",
+           code_table[addr_size - 2],
+           addr_size + payload_size + 1,
+           addr_size * 2, (int) targ_addr);
 
   /* Note that the checksum is calculated on the raw data, not the
      hexified data.  It includes the length, address and the data
@@ -287,6 +285,9 @@ make_srec (char *srec, CORE_ADDR targ_addr, bfd *abfd, asection *sect,
               + ((targ_addr >> 16) & 0xff)
               + ((targ_addr >> 24) & 0xff));
 
+  /* NOTE: cagney/2003-08-10: The equation is old.  Check that the
+     recent snprintf changes match that equation.  */
+  gdb_assert (strlen (srec) == 1 + 1 + 2 + addr_size * 2);
   p = srec + 1 + 1 + 2 + addr_size * 2;
 
   /* Build the Srecord.  */
This page took 0.035433 seconds and 4 git commands to generate.