dj(1): fix segfault when bses are mismatched

This commit is contained in:
dtb 2024-07-03 17:59:21 -06:00
parent f4b97be1f1
commit 2167f35f58
Signed by: trinity
GPG Key ID: 34C0543BBB6AF81B

View File

@ -35,15 +35,15 @@ char *program_name = "dj";
* writing ends of its jockeyed "pipe". User-configurable members are noted
* with their relevant options. */
struct Io{
int bs; /* buffer size (-bB) */
int bs; /* buffer size (-bB) */
size_t bufuse; /* buffer usage */
char *buf; /* buffer */
int bytes; /* bytes processed */
size_t bytes; /* bytes processed */
int fd; /* file descriptor */
int fl; /* file opening flags */
char *fn; /* file name (may be stdin_name or stdout_name) (-io) */
int prec; /* partial records processed */
int rec; /* records processed */
size_t prec; /* partial records processed */
size_t rec; /* records processed */
long seek; /* bytes to seek/skip (will be 0 after skippage) (-sS) */
};
@ -197,6 +197,7 @@ int main(int argc, char *argv[]){
noerror = 0;
for(i = 0; i < 2; ++i){
io[i].bs = 1024 /* 1 KiB */; /* GNU dd(1) default; POSIX says 512B */
io[i].bufuse = 0;
io[i].bytes = 0;
io[i].fd = i == 0 ? STDIN_FILENO : STDOUT_FILENO;
io[i].fn = i == 0 ? stdin_name : stdout_name;