Skip to content

Commit b80d86f

Browse files
committed
Update nNumberOfBytesToRead calculation
1 parent f81c7b3 commit b80d86f

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

src/O2FS/Systems/O2MusicSystem.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,14 @@ namespace O2FS
9191
// Convert the BMS into OJN file.
9292
auto data = LoadChart(hFile);
9393

94+
// Calculate the number of bytes to read to avoid out of range error
95+
int count = nNumberOfBytesToRead;
96+
if (offset + count > data.size())
97+
count = data.size() - offset;
98+
9499
// Fill the buffer with converted OJN data at requested offset
95-
memcpy(&buffer[0], &data[offset], nNumberOfBytesToRead);
96-
*lpNumberOfBytesRead = nNumberOfBytesToRead;
100+
memcpy(&buffer[0], &data[offset], count);
101+
*lpNumberOfBytesRead = count;
97102

98103
// Release the HANDLE lock so the HANDLE can be hooked again after this call.
99104
handles.erase(fileName);

0 commit comments

Comments
 (0)