devlist: Remove an unnecessary sprintf
Namhyung Kim
PATCH 1/2 devlist: Remove an unnecessary sprintf
The 'filename' is not used in the loop anymore.
--- src/devlist.cpp | 1 - 1 file changed, 1 deletion(-)
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);
Signature · 1 line
1.7.9.2
Namhyung Kim
PATCH 2/2 devlist: NULL terminate struct devuser fields
As strncpy doesn't guarantee the destination buffer is NULL- terminated, do it explicitly.
--- src/devlist.cpp | 2 ++ 1 file changed, 2 insertions(+)
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); }
Signature · 1 line
1.7.9.2
Sergey Senozhatsky
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.2As 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@@ -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
Chris Ferron
Re: [Powertop] [PATCH 2/2] devlist: NULL terminate struct devuser fields
In reply to Namhyung KimQuoted 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
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
Sergey Senozhatsky
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@@ -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
Chris Ferron
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
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