Skip to contentSkip to conversation

commands: truncate: fix multiple file handling with relative sizes

PATCH Applied Alexander Shiyan 2 participants 2 messages Nov 19, 2025 – Nov 20, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 commands: truncate: fix multiple file handling with relative sizes

Fix bug where processing multiple files with -s +SIZE option would use incorrect sizes for files after the first one, because the size variable was being overwritten.

---
 commands/truncate.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
commands/truncate.c +7 -4
index 5c6d74257d..83661fbaf6 100644
@@ -59,23 +59,26 @@ static int do_truncate(int argc, char *argv[])
 			continue;
 		}
 
+		off_t target_size = size;
+
 		if (modify) {
 			struct stat st;
 
 			if (fstat(fd, &st) == -1) {
 				perror("fstat");
 				ret = 1;
-				goto close;
+				close(fd);
+				continue;
 			}
 
-			size = st.st_size + modify * size;
+			target_size = st.st_size + size;
 		}
 
-		if (ftruncate(fd, size) == -1) {
+		if (ftruncate(fd, target_size) == -1) {
 			perror("truncate");
 			ret = 1;
 		}
-close:
+
 		close(fd);
 	}
 
Signature · 1 line
2.38.2