lsof: explicit size for device major:minor buffer.
Major and minor get 12 bits and 20 bits respectively, so when displayed
that's up to 3 digits (but normally 2), a ':', and up to 5 digits (but
normally 2).
diff --git a/toys/pending/lsof.c b/toys/pending/lsof.c
index 2ab4177..e4b5311 100644
--- a/toys/pending/lsof.c
+++ b/toys/pending/lsof.c
@@ -330,10 +330,10 @@
{
FILE *fp;
unsigned long long offset;
- char device[10];
long inode;
- char *line = NULL;
+ char *line = NULL, device[10]; // xxx:xxxxx\0
size_t line_length = 0;
+ struct file_info *fi;
snprintf(toybuf, sizeof(toybuf), "/proc/%d/maps", pi->pid);
fp = fopen(toybuf, "r");
@@ -342,10 +342,8 @@
while (getline(&line, &line_length, fp) > 0) {
int name_pos;
- if (sscanf(line, "%*x-%*x %*s %llx %s %ld %n",
+ if (sscanf(line, "%*x-%*x %*s %llx %9s %ld %n",
&offset, device, &inode, &name_pos) >= 3) {
- struct file_info *fi;
-
// Ignore non-file maps.
if (inode == 0 || !strcmp(device, "00:00")) continue;
// TODO: show unique maps even if they have a non-zero offset?