Skip to content

Commit 013faa4

Browse files
committed
Fix read function to handle zero request size and improve offset logging
1 parent 53786d6 commit 013faa4

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

jme3-android-native/src/native/jme_decode/com_jme3_audio_plugins_NativeVorbisFile.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,11 @@ static size_t FileDesc_read(void *ptr, size_t size, size_t nmemb, void *datasour
4141

4242
size_t req_size = size * nmemb;
4343
ogg_int64_t remaining = wrapper->end - wrapper->current;
44-
size_t to_read = (remaining < (ogg_int64_t) req_size) ? (size_t) remaining : req_size;
45-
46-
if (to_read <= 0)
44+
if (remaining <= 0 || req_size == 0)
4745
{
4846
return 0;
4947
}
48+
size_t to_read = ((uint64_t) remaining < (uint64_t) req_size) ? (size_t) remaining : req_size;
5049

5150
ssize_t total_read = read(wrapper->fd, ptr, to_read);
5251
if (total_read < 0)
@@ -140,18 +139,18 @@ static int FileDesc_clear(void *datasource)
140139
static long FileDesc_tell(void *datasource)
141140
{
142141
FileDescWrapper* wrapper = (FileDescWrapper*)datasource;
143-
long result = lseek64(wrapper->fd, 0, SEEK_CUR);
142+
off64_t result = lseek64(wrapper->fd, 0, SEEK_CUR);
144143

145-
LOGI("FD tell = %ld", result);
144+
LOGI("FD tell = %lld", (long long) result);
146145

147146
if (wrapper->current != result)
148147
{
149148
// Not sure how to deal with this.
150-
LOGI("PROBLEM: stored offset does not match actual: %lld != %ld",
151-
(long long) wrapper->current, result);
149+
LOGI("PROBLEM: stored offset does not match actual: %lld != %lld",
150+
(long long) wrapper->current, (long long) result);
152151
}
153152

154-
return result;
153+
return (long) result;
155154
}
156155

157156
static ov_callbacks FileDescCallbacks = {

0 commit comments

Comments
 (0)