]> git.draconx.ca Git - liblbx.git/commitdiff
liblbx: Improve error handling in lbx_file_seek.
authorNick Bowler <nbowler@draconx.ca>
Tue, 28 Jan 2014 01:28:09 +0000 (20:28 -0500)
committerNick Bowler <nbowler@draconx.ca>
Tue, 28 Jan 2014 01:37:34 +0000 (20:37 -0500)
  - Return an error code for an invaled whence value instead of
    proceeding with uninitialized values.

  - Set an error code on one of the error paths that did not set one.

src/lbx.c

index 30cd156c957e747392046f5c9f9b7637f0580fdc..1198ebbc2c0b13e08aa4cbb7c914ae431d4eb48c 100644 (file)
--- a/src/lbx.c
+++ b/src/lbx.c
@@ -282,10 +282,15 @@ int lbx_file_seek(struct lbx_file_state *f, long offset, int whence)
        case SEEK_END:
                pos = f->limit + offset;
                break;
+       default:
+               lbx_error_raise(LBX_EINVAL);
+               return -1;
        }
 
-       if (pos > f->limit)
+       if (pos > f->limit) {
+               lbx_error_raise(LBX_EINVAL);
                return -1;
+       }
 
        f->lbx->last_file = NULL;
        if (fops->seek(f->lbx->f, f->base + pos, SEEK_SET) != 0)