Skip to contentSkip to conversation

oprofile: Fix format string mismatch in oprofile_perf.c

PATCH In review Masanari Iida 2 participants 2 messages Apr 29, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 oprofile: Fix format string mismatch in oprofile_perf.c

Fix format string mismatch in oprofile_perf_create_files.

---
 drivers/oprofile/oprofile_perf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/oprofile/oprofile_perf.c +1 -1
index d5b2732..968e6dc 100644
@@ -146,7 +146,7 @@ static int oprofile_perf_create_files(struct dentry *root)
 		struct dentry *dir;
 		char buf[4];
 
-		snprintf(buf, sizeof buf, "%d", i);
+		snprintf(buf, sizeof buf, "%u", i);
 		dir = oprofilefs_mkdir(root, buf);
 		oprofilefs_create_ulong(dir, "enabled", &counter_config[i].enabled);
 		oprofilefs_create_ulong(dir, "event", &counter_config[i].event);
Signature · 1 line
2.0.0.rc1
#1 lore raw
Quoted 1 line · Masanari Iida

Fix format string mismatch in oprofile_perf_create_files.

Please provide a compiler warning.

drivers/oprofile/oprofile_perf.c static int oprofile_perf_create_files(struct dentry *root)

Quoted 11 lines
---
 drivers/oprofile/oprofile_perf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/oprofile/oprofile_perf.c +0 -0
index d5b2732..968e6dc 100644
@@ -146,7 +146,7 @@ static int oprofile_perf_create_files(struct dentry *root)
        unsigned int i;

        for (i = 0; i < num_counters; i++) {

drivers/oprofile/oprofile_perf.c static int oprofile_perf_create_files(struct dentry *root) · line 149

Quoted 5 lines
drivers/oprofile/oprofile_perf.c +1 -1
 		struct dentry *dir;
 		char buf[4];
 
-		snprintf(buf, sizeof buf, "%d", i);
+		snprintf(buf, sizeof buf, "%u", i);

Since num_counters is int we better fix this by changing the i declaration to int which avoids comparing unsigned/signed.

-Robert

Quoted 6 lines
drivers/oprofile/oprofile_perf.c +0 -0
 		dir = oprofilefs_mkdir(root, buf);
 		oprofilefs_create_ulong(dir, "enabled", &counter_config[i].enabled);
 		oprofilefs_create_ulong(dir, "event", &counter_config[i].event);
Signature · 1 line
2.0.0.rc1