Procházet zdrojové kódy

[makefile] Add -Wformat-nonliteral as an extra warning category

-Wformat-nonliteral is not enabled by -Wall and needs to be explicitly
 specified.

Modified the few files that use nonliteral format strings to work with
this new setting in place.

Inspired by a patch from Carl Karsten <carl@personnelware.com> and an
identical patch from Rorschach <r0rschach@lavabit.com>.
tags/v0.9.6
Michael Brown před 16 roky
rodič
revize
2e812235f4

+ 1
- 1
src/Makefile.housekeeping Zobrazit soubor

@@ -265,7 +265,7 @@ ifdef BIN
265 265
 #
266 266
 CFLAGS		+= -I include -I arch/$(ARCH)/include -I .
267 267
 CFLAGS		+= -Os -ffreestanding
268
-CFLAGS		+= -Wall -W
268
+CFLAGS		+= -Wall -W -Wformat-nonliteral
269 269
 CFLAGS		+= -g
270 270
 CFLAGS		+= $(EXTRA_CFLAGS)
271 271
 ASFLAGS		+= $(EXTRA_ASFLAGS)

+ 1
- 1
src/drivers/net/3c595.c Zobrazit soubor

@@ -363,7 +363,7 @@ vxgetlink(void)
363 363
         if (n > 0) {
364 364
           printf("/");
365 365
 	}
366
-        printf(conn_tab[k].name);
366
+        printf("%s", conn_tab[k].name );
367 367
         n++;
368 368
       }
369 369
     }

+ 1
- 1
src/drivers/net/forcedeth.c Zobrazit soubor

@@ -452,7 +452,7 @@ static int reg_delay(int offset, u32 mask,
452 452
 		delaymax -= delay;
453 453
 		if (delaymax < 0) {
454 454
 			if (msg)
455
-				printf(msg);
455
+				printf("%s", msg);
456 456
 			return 1;
457 457
 		}
458 458
 	} while ((readl(base + offset) & mask) != target);

+ 1
- 1
src/drivers/net/via-rhine.c Zobrazit soubor

@@ -1008,7 +1008,7 @@ rhine_probe1 (struct nic *nic, struct pci_device *pci, int ioaddr, int chip_id,
1008 1008
     unsigned char mode3_reg;
1009 1009
 
1010 1010
     if (rhine_debug > 0 && did_version++ == 0)
1011
-	printf (version);
1011
+	printf ("%s",version);
1012 1012
 
1013 1013
     // get revision id.
1014 1014
     pci_read_config_byte(pci, PCI_REVISION, &revision_id);

+ 2
- 2
src/include/gpxe/xfer.h Zobrazit soubor

@@ -149,8 +149,8 @@ extern int xfer_deliver_raw ( struct xfer_interface *xfer,
149 149
 			      const void *data, size_t len );
150 150
 extern int xfer_vprintf ( struct xfer_interface *xfer,
151 151
 			  const char *format, va_list args );
152
-extern int xfer_printf ( struct xfer_interface *xfer,
153
-			 const char *format, ... );
152
+extern int __attribute__ (( format ( printf, 2, 3 ) ))
153
+xfer_printf ( struct xfer_interface *xfer, const char *format, ... );
154 154
 extern int xfer_seek ( struct xfer_interface *xfer, off_t offset, int whence );
155 155
 
156 156
 extern void ignore_xfer_close ( struct xfer_interface *xfer, int rc );

+ 41
- 20
src/net/tcp/ftp.c Zobrazit soubor

@@ -109,23 +109,39 @@ static void ftp_done ( struct ftp_request *ftp, int rc ) {
109 109
  *
110 110
  */
111 111
 
112
+/** An FTP control channel string */
113
+struct ftp_control_string {
114
+	/** Literal portion */
115
+	const char *literal;
116
+	/** Variable portion
117
+	 *
118
+	 * @v ftp	FTP request
119
+	 * @ret string	Variable portion of string
120
+	 */
121
+	const char * ( *variable ) ( struct ftp_request *ftp );
122
+};
123
+
112 124
 /**
113
- * FTP control channel strings
125
+ * Retrieve FTP pathname
114 126
  *
115
- * These are used as printf() format strings.  Since only one of them
116
- * (RETR) takes an argument, we always supply that argument to the
117
- * snprintf() call.
127
+ * @v ftp		FTP request
128
+ * @ret path		FTP pathname
118 129
  */
119
-static const char * ftp_strings[] = {
120
-	[FTP_CONNECT]	= NULL,
121
-	[FTP_USER]	= "USER anonymous\r\n",
122
-	[FTP_PASS]	= "PASS etherboot@etherboot.org\r\n",
123
-	[FTP_TYPE]	= "TYPE I\r\n",
124
-	[FTP_PASV]	= "PASV\r\n",
125
-	[FTP_RETR]	= "RETR %s\r\n",
126
-	[FTP_WAIT]	= NULL,
127
-	[FTP_QUIT]	= "QUIT\r\n",
128
-	[FTP_DONE]	= NULL,
130
+static const char * ftp_uri_path ( struct ftp_request *ftp ) {
131
+	return ftp->uri->path;
132
+}
133
+
134
+/** FTP control channel strings */
135
+static struct ftp_control_string ftp_strings[] = {
136
+	[FTP_CONNECT]	= { NULL, NULL },
137
+	[FTP_USER]	= { "USER anonymous", NULL },
138
+	[FTP_PASS]	= { "PASS etherboot@etherboot.org", NULL },
139
+	[FTP_TYPE]	= { "TYPE I", NULL },
140
+	[FTP_PASV]	= { "PASV", NULL },
141
+	[FTP_RETR]	= { "RETR ", ftp_uri_path },
142
+	[FTP_WAIT]	= { NULL, NULL },
143
+	[FTP_QUIT]	= { "QUIT", NULL },
144
+	[FTP_DONE]	= { NULL, NULL },
129 145
 };
130 146
 
131 147
 /**
@@ -178,18 +194,23 @@ static void ftp_parse_value ( char **text, uint8_t *value, size_t len ) {
178 194
  *
179 195
  */
180 196
 static void ftp_next_state ( struct ftp_request *ftp ) {
197
+	struct ftp_control_string *ftp_string;
198
+	const char *literal;
199
+	const char *variable;
181 200
 
182 201
 	/* Move to next state */
183 202
 	if ( ftp->state < FTP_DONE )
184 203
 		ftp->state++;
185 204
 
186 205
 	/* Send control string if needed */
187
-	if ( ftp_strings[ftp->state] != NULL ) {
188
-		DBGC ( ftp, "FTP %p sending ", ftp );
189
-		DBGC ( ftp, ftp_strings[ftp->state], ftp->uri->path );
190
-		xfer_printf ( &ftp->control, ftp_strings[ftp->state],
191
-			      ftp->uri->path );
192
-	}	
206
+	ftp_string = &ftp_strings[ftp->state];
207
+	literal = ftp_string->literal;
208
+	variable = ( ftp_string->variable ?
209
+		     ftp_string->variable ( ftp ) : "" );
210
+	if ( literal ) {
211
+		DBGC ( ftp, "FTP %p sending %s%s\n", ftp, literal, variable );
212
+		xfer_printf ( &ftp->control, "%s%s\r\n", literal, variable );
213
+	}
193 214
 }
194 215
 
195 216
 /**

Načítá se…
Zrušit
Uložit