[libbluray-devel] udf: improved error checks
hpi1
git at videolan.org
Fri Jul 1 18:03:27 CEST 2016
libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Sun Jun 26 19:19:22 2016 +0300| [b683a904f7d736c1874b6b85c23e0afdaaaa8796] | committer: hpi1
udf: improved error checks
> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=b683a904f7d736c1874b6b85c23e0afdaaaa8796
---
src/libbluray/disc/udf_fs.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/src/libbluray/disc/udf_fs.c b/src/libbluray/disc/udf_fs.c
index e7c683c..bcb624c 100644
--- a/src/libbluray/disc/udf_fs.c
+++ b/src/libbluray/disc/udf_fs.c
@@ -159,7 +159,11 @@ static int _bi_close(struct udfread_block_input *bi_gen)
static uint32_t _bi_size(struct udfread_block_input *bi_gen)
{
UDF_BI *bi = (UDF_BI *)bi_gen;
- return file_size(bi->fp) / UDF_BLOCK_SIZE;
+ int64_t size = file_size(bi->fp);
+ if (size >= 0) {
+ return size / UDF_BLOCK_SIZE;
+ }
+ return 0;
}
static int _bi_read(struct udfread_block_input *bi_gen, uint32_t lba, void *buf, uint32_t nblocks, int flags)
@@ -167,11 +171,12 @@ static int _bi_read(struct udfread_block_input *bi_gen, uint32_t lba, void *buf,
(void)flags;
UDF_BI *bi = (UDF_BI *)bi_gen;
int got = -1;
+ int64_t pos = (int64_t)lba * UDF_BLOCK_SIZE;
/* seek + read must be atomic */
bd_mutex_lock(&bi->mutex);
- if (file_seek(bi->fp, SEEK_SET, (int64_t)lba * UDF_BLOCK_SIZE) >= 0) {
+ if (file_seek(bi->fp, SEEK_SET, pos) == pos) {
int64_t bytes = file_read(bi->fp, (uint8_t*)buf, (int64_t)nblocks * UDF_BLOCK_SIZE);
if (bytes > 0) {
got = bytes / UDF_BLOCK_SIZE;
More information about the libbluray-devel
mailing list