From 601e85fd560f1a72b2da51fe2de5af271cd0e3b4 Mon Sep 17 00:00:00 2001 From: kurok <22548029+kurok@users.noreply.github.com> Date: Thu, 12 Mar 2026 08:57:17 +0000 Subject: [PATCH] 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 --- src/print.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/print.c b/src/print.c index 494f9eb3..224d567e 100644 --- a/src/print.c +++ b/src/print.c @@ -1110,7 +1110,7 @@ static int printinaddr(struct lsof_context *ctx) { */ if (nl < 2) - addr_too_long : + addr_too_long: { (void)snpf(Namech, Namechl, "network addresses too long"); @@ -1892,8 +1892,12 @@ int print_proc(struct lsof_context *ctx) { lc = st = 0; if (FieldSel[LSOF_FIX_FD].st) { - fd_to_string(Lf->fd_type, Lf->fd_num, fd); - (void)printf("%c%s%c", LSOF_FID_FD, fd, Terminator); + if (Lf->fd_type == LSOF_FD_NUMERIC) + (void)printf("%c%d%c", LSOF_FID_FD, Lf->fd_num, Terminator); + else { + fd_to_string(Lf->fd_type, Lf->fd_num, fd); + (void)printf("%c%s%c", LSOF_FID_FD, fd, Terminator); + } lc++; } /*