Commit 6c41e8f6 authored by Max Kellermann's avatar Max Kellermann

db/upnp: check offset<total at end of loop

parent fa67a4e9
...@@ -114,20 +114,15 @@ ContentDirectoryService::readDir(UpnpClient_Handle handle, ...@@ -114,20 +114,15 @@ ContentDirectoryService::readDir(UpnpClient_Handle handle,
UPnPDirContent &dirbuf, UPnPDirContent &dirbuf,
Error &error) Error &error)
{ {
unsigned offset = 0; unsigned offset = 0, total = -1, count;
unsigned total = 1000;// Updated on first read.
while (offset < total) { do {
unsigned count;
if (!readDirSlice(handle, objectId, offset, m_rdreqcnt, dirbuf, if (!readDirSlice(handle, objectId, offset, m_rdreqcnt, dirbuf,
count, total, error)) count, total, error))
return false; return false;
if (count == 0)
return true;
offset += count; offset += count;
} } while (count > 0 && offset < total);
return true; return true;
} }
...@@ -139,10 +134,9 @@ ContentDirectoryService::search(UpnpClient_Handle hdl, ...@@ -139,10 +134,9 @@ ContentDirectoryService::search(UpnpClient_Handle hdl,
UPnPDirContent &dirbuf, UPnPDirContent &dirbuf,
Error &error) Error &error)
{ {
unsigned offset = 0; unsigned offset = 0, total = -1, count;
unsigned total = 1000;// Updated on first read.
while (offset < total) { do {
char ofbuf[100]; char ofbuf[100];
sprintf(ofbuf, "%d", offset); sprintf(ofbuf, "%d", offset);
...@@ -173,7 +167,7 @@ ContentDirectoryService::search(UpnpClient_Handle hdl, ...@@ -173,7 +167,7 @@ ContentDirectoryService::search(UpnpClient_Handle hdl,
const char *value = const char *value =
ixmlwrap::getFirstElementValue(response, "NumberReturned"); ixmlwrap::getFirstElementValue(response, "NumberReturned");
const unsigned count = value != nullptr count = value != nullptr
? ParseUnsigned(value) ? ParseUnsigned(value)
: 0; : 0;
...@@ -187,10 +181,7 @@ ContentDirectoryService::search(UpnpClient_Handle hdl, ...@@ -187,10 +181,7 @@ ContentDirectoryService::search(UpnpClient_Handle hdl,
ixmlDocument_free(response); ixmlDocument_free(response);
if (!success) if (!success)
return false; return false;
} while (count > 0 && offset < total);
if (count == 0)
break;
}
return true; return true;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment