Skip to contentSkip to conversation

devlist: Remove an unnecessary sprintf

PATCH In review Namhyung Kim 3 participants 6 messages Sep 18, 2012

lore
Share & tools
lore

Namhyung Kim

author
#0 lore raw

PATCH 1/2 devlist: Remove an unnecessary sprintf

The 'filename' is not used in the loop anymore.

Signed-off-by Namhyung Kim <namhyung(a)gmail.com>
---
 src/devlist.cpp |    1 -
 1 file changed, 1 deletion(-)
src/devlist.cpp +0 -1
index 5ec0a8b..828f47f 100644
@@ -147,7 +147,6 @@ void collect_open_devices(void)
 					continue;
 				dev->pid = strtoull(entry->d_name, NULL, 10);
 				strncpy(dev->device, link, 251);
-				sprintf(filename, "/proc/%s/comm", entry->d_name);
 				strncpy(dev->comm, read_sysfs_string("/proc/%s/comm", entry->d_name).c_str(), 31);
 				target->push_back(dev);
 
Signature · 1 line
1.7.9.2
author
#1 lore raw

PATCH 2/2 devlist: NULL terminate struct devuser fields

As strncpy doesn't guarantee the destination buffer is NULL- terminated, do it explicitly.

Signed-off-by Namhyung Kim <namhyung(a)gmail.com>
---
 src/devlist.cpp |    2 ++
 1 file changed, 2 insertions(+)
src/devlist.cpp +2 -0
index 828f47f..71898af 100644
@@ -147,7 +147,9 @@ void collect_open_devices(void)
 					continue;
 				dev->pid = strtoull(entry->d_name, NULL, 10);
 				strncpy(dev->device, link, 251);
+				dev->device[251] = '\0';
 				strncpy(dev->comm, read_sysfs_string("/proc/%s/comm", entry->d_name).c_str(), 31);
+				dev->comm[31] = '\0';
 				target->push_back(dev);
 
 			}
Signature · 1 line
1.7.9.2
#2 lore raw

Re: [Powertop] [PATCH 2/2] devlist: NULL terminate struct devuser fields

Quoted 10 lines · Namhyung Kim

Date: Wed, 19 Sep 2012 00:13:18 +0900
From: Namhyung Kim <namhyung(a)gmail.com>
To: powertop(a)lists.01.org
Subject: [Powertop] [PATCH 2/2] devlist: NULL terminate struct devuser
fields
X-Mailer: git-send-email 1.7.9.2

As strncpy doesn't guarantee the destination buffer is NULL- terminated, do it explicitly.

looks good.

	-ss
Quoted 27 lines
Signed-off-by Namhyung Kim <namhyung(a)gmail.com>
---
 src/devlist.cpp |    2 ++
 1 file changed, 2 insertions(+)
src/devlist.cpp +2 -0
index 828f47f..71898af 100644
@@ -147,7 +147,9 @@ void collect_open_devices(void)
 					continue;
 				dev->pid = strtoull(entry->d_name, NULL, 10);
 				strncpy(dev->device, link, 251);
+				dev->device[251] = '\0';
 				strncpy(dev->comm, read_sysfs_string("/proc/%s/comm", entry->d_name).c_str(), 31);
+				dev->comm[31] = '\0';
 				target->push_back(dev);
 
 			}
Signature · 6 lines
1.7.9.2

_______________________________________________
PowerTop mailing list
PowerTop(a)lists.01.org
https://lists.01.org/mailman/listinfo/powertop
#3 lore raw

Re: [Powertop] [PATCH 2/2] devlist: NULL terminate struct devuser fields

In reply to Namhyung Kim
Quoted 13 lines · Namhyung Kim

As strncpy doesn't guarantee the destination buffer is NULL- terminated, do it explicitly.

Signed-off-by Namhyung Kim <namhyung(a)gmail.com>
---
  src/devlist.cpp |    2 ++
  1 file changed, 2 insertions(+)
src/devlist.cpp +0 -0
index 828f47f..71898af 100644

src/devlist.cpp void collect_open_devices(void) · line 155

Quoted 9 lines
src/devlist.cpp +2 -0
@@ -147,7 +147,9 @@ void collect_open_devices(void)
  					continue;
  				dev->pid = strtoull(entry->d_name, NULL, 10);
  				strncpy(dev->device, link, 251);
+				dev->device[251] = '\0';
  				strncpy(dev->comm, read_sysfs_string("/proc/%s/comm", entry->d_name).c_str(), 31);
+				dev->comm[31] = '\0';
  				target->push_back(dev);
 
  			}

Your patch has been merged
Thank You
-C

#4 lore raw
In reply to Namhyung Kim
Quoted 6 lines · Namhyung Kim

Date: Wed, 19 Sep 2012 00:13:17 +0900
From: Namhyung Kim <namhyung(a)gmail.com>
To: powertop(a)lists.01.org
Subject: [Powertop] [PATCH 1/2] devlist: Remove an unnecessary sprintf
X-Mailer: git-send-email 1.7.9.2

Quoted 7 lines

The 'filename' is not used in the loop anymore.

Signed-off-by Namhyung Kim <namhyung(a)gmail.com>
---
 src/devlist.cpp |    1 -
 1 file changed, 1 deletion(-)

looks good.

	-ss
Quoted 20 lines
src/devlist.cpp +0 -1
index 5ec0a8b..828f47f 100644
@@ -147,7 +147,6 @@ void collect_open_devices(void)
 					continue;
 				dev->pid = strtoull(entry->d_name, NULL, 10);
 				strncpy(dev->device, link, 251);
-				sprintf(filename, "/proc/%s/comm", entry->d_name);
 				strncpy(dev->comm, read_sysfs_string("/proc/%s/comm", entry->d_name).c_str(), 31);
 				target->push_back(dev);
 
Signature · 6 lines
1.7.9.2

_______________________________________________
PowerTop mailing list
PowerTop(a)lists.01.org
https://lists.01.org/mailman/listinfo/powertop
#5 lore raw
In reply to Namhyung Kim
Quoted 12 lines · Namhyung Kim

The 'filename' is not used in the loop anymore.

Signed-off-by Namhyung Kim <namhyung(a)gmail.com>
---
  src/devlist.cpp |    1 -
  1 file changed, 1 deletion(-)
src/devlist.cpp +0 -0
index 5ec0a8b..828f47f 100644

src/devlist.cpp void collect_open_devices(void) · line 152

Quoted 7 lines
src/devlist.cpp +0 -1
@@ -147,7 +147,6 @@ void collect_open_devices(void)
  					continue;
  				dev->pid = strtoull(entry->d_name, NULL, 10);
  				strncpy(dev->device, link, 251);
-				sprintf(filename, "/proc/%s/comm", entry->d_name);
  				strncpy(dev->comm, read_sysfs_string("/proc/%s/comm", entry->d_name).c_str(), 31);
  				target->push_back(dev);
 

Your patch has been merged
Thank You
-C