This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[patch, rfc] Fix Wformat-nonlit prob with dsrec.c
- From: Andrew Cagney <ac131313 at redhat dot com>
- To: gdb-patches at sources dot redhat dot com
- Date: Sun, 10 Aug 2003 14:28:10 -0400
- Subject: [patch, rfc] Fix Wformat-nonlit prob with dsrec.c
Hello,
This fixes a format-nonliteral warning in dsrec.c. It also eliminates
the sprintf replacing it with snprintf.
I should note that I don't have access to a m/c that uses srecords so
`it looks ok ...'. I'm looking to commit this in a few days.
Andrew
2003-08-10 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.
Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.424
diff -u -r1.424 Makefile.in
--- Makefile.in 8 Aug 2003 17:30:35 -0000 1.424
+++ Makefile.in 10 Aug 2003 18:20:29 -0000
@@ -1678,7 +1678,7 @@
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: dsrec.c
===================================================================
RCS file: /cvs/src/src/gdb/dsrec.c,v
retrieving revision 1.11
diff -u -r1.11 dsrec.c
--- dsrec.c 15 Jul 2001 20:34:13 -0000 1.11
+++ dsrec.c 10 Aug 2003 18:20:29 -0000
@@ -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 @@
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 @@
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 @@
+ ((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. */