From ceec5c6d538a88867a92d826e33cddae6a80c545 Mon Sep 17 00:00:00 2001 From: Jose Antonio Ortega Ruiz Date: Wed, 20 Mar 2019 00:06:22 +0000 Subject: Fix: correctly rewind tape According to the specification, if M < 0, the tape is skipped backwards M blocks, or to the beginning of the tape, whichever comes first. In the implementation, we don't check to verify that we aren't seeking past the beginning of the file. This causes fseek(3) to fail, and it leaves us at the position we were at. Diagnosis and fix by Kevin Brunelle. --- mixlib/xmix_device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mixlib/xmix_device.c b/mixlib/xmix_device.c index 0c07549..8d4084c 100644 --- a/mixlib/xmix_device.c +++ b/mixlib/xmix_device.c @@ -155,7 +155,7 @@ ioc_ (mix_device_t *dev, mix_short_t arg) if (dev->type >= mix_dev_TAPE_0 && dev->type <= mix_dev_TAPE_7) { - if (m == 0) rewind (file); + if (m == 0 || (ftell (file) + m <= 0 )) rewind (file); else fseek (file, m, SEEK_CUR); } if (dev->type >= mix_dev_DISK_0 && dev->type <= mix_dev_DISK_7) -- cgit v1.2.3