Skip to contentSkip to conversation

floppy: make local variable non-static

PATCH Applied Rasmus Villemoes 2 participants 2 messages Dec 1, 2015 – Dec 8, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 floppy: make local variable non-static

There's no reason for temparea to be static, since it's only used for temporary sprintf output. It's not immediately obvious that the output will always fit (in the worst case, the output including '\0' is exactly 32 bytes), so save a future reader from worrying about that.

---
 drivers/block/floppy.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/block/floppy.c +3 -2
index 331363e7de0f..9e251201dd48 100644
@@ -3585,7 +3585,7 @@ static void __init config_types(void)
 		unsigned int type = UDP->cmos;
 		struct floppy_drive_params *params;
 		const char *name = NULL;
-		static char temparea[32];
+		char temparea[32];
 
 		if (type < ARRAY_SIZE(default_drive_params)) {
 			params = &default_drive_params[type].params;
@@ -3596,7 +3596,8 @@ static void __init config_types(void)
 				allowed_drive_mask &= ~(1 << drive);
 		} else {
 			params = &default_drive_params[0].params;
-			sprintf(temparea, "unknown type %d (usb?)", type);
+			snprintf(temparea, sizeof(temparea),
+				 "unknown type %d (usb?)", type);
 			name = temparea;
 		}
 		if (name) {
Signature · 1 line
2.6.1
Applied
#1 lore raw
Quoted 6 lines · Rasmus Villemoes

There's no reason for temparea to be static, since it's only used for temporary sprintf output. It's not immediately obvious that the output will always fit (in the worst case, the output including '\0' is exactly 32 bytes), so save a future reader from worrying about that.

Applied, thanks.

(I have applied this to trivial.git, as was too lazy to revive floppy tree just for this :) ).

Signature · 2 lines
Jiri Kosina
SUSE Labs