Skip to content

Commit 601e85f

Browse files
kurokclaude
andcommitted
Fix truncated fd numbers in -F field output
When fd numbers >= 10000, fd_to_string() truncates them to fit the fixed-width FDLEN buffer (e.g., 12345 becomes *345). This truncation is appropriate for the tabular display but incorrect for -F (field) output which is designed for machine parsing. In the -F output path, print numeric fd values directly using printf("%d") instead of going through fd_to_string(), avoiding the FDLEN buffer size constraint. Fixes #311 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 761ca77 commit 601e85f

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/print.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,7 @@ static int printinaddr(struct lsof_context *ctx) {
11101110
*/
11111111
if (nl < 2)
11121112

1113-
addr_too_long :
1113+
addr_too_long:
11141114

11151115
{
11161116
(void)snpf(Namech, Namechl, "network addresses too long");
@@ -1892,8 +1892,12 @@ int print_proc(struct lsof_context *ctx) {
18921892
lc = st = 0;
18931893
if (FieldSel[LSOF_FIX_FD].st) {
18941894

1895-
fd_to_string(Lf->fd_type, Lf->fd_num, fd);
1896-
(void)printf("%c%s%c", LSOF_FID_FD, fd, Terminator);
1895+
if (Lf->fd_type == LSOF_FD_NUMERIC)
1896+
(void)printf("%c%d%c", LSOF_FID_FD, Lf->fd_num, Terminator);
1897+
else {
1898+
fd_to_string(Lf->fd_type, Lf->fd_num, fd);
1899+
(void)printf("%c%s%c", LSOF_FID_FD, fd, Terminator);
1900+
}
18971901
lc++;
18981902
}
18991903
/*

0 commit comments

Comments
 (0)