diff options
author | Max Kellermann <max@duempel.org> | 2014-01-22 21:03:45 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-01-22 21:37:21 +0100 |
commit | 6c41e8f63f6ef0eab548d49b75eb18e465009a17 (patch) | |
tree | 45ae294ad823706e20a7fdb7623548833c3efd7c | |
parent | fa67a4e956461019e35bd6029e9df24bce680d66 (diff) | |
download | mpd-6c41e8f63f6ef0eab548d49b75eb18e465009a17.tar.gz mpd-6c41e8f63f6ef0eab548d49b75eb18e465009a17.tar.xz mpd-6c41e8f63f6ef0eab548d49b75eb18e465009a17.zip |
db/upnp: check offset<total at end of loop
-rw-r--r-- | src/db/upnp/ContentDirectoryService.cxx | 23 |
1 files changed, 7 insertions, 16 deletions
diff --git a/src/db/upnp/ContentDirectoryService.cxx b/src/db/upnp/ContentDirectoryService.cxx index 3bf6e159d..af7ce949b 100644 --- a/src/db/upnp/ContentDirectoryService.cxx +++ b/src/db/upnp/ContentDirectoryService.cxx @@ -114,20 +114,15 @@ ContentDirectoryService::readDir(UpnpClient_Handle handle, UPnPDirContent &dirbuf, Error &error) { - unsigned offset = 0; - unsigned total = 1000;// Updated on first read. + unsigned offset = 0, total = -1, count; - while (offset < total) { - unsigned count; + do { if (!readDirSlice(handle, objectId, offset, m_rdreqcnt, dirbuf, count, total, error)) return false; - if (count == 0) - return true; - offset += count; - } + } while (count > 0 && offset < total); return true; } @@ -139,10 +134,9 @@ ContentDirectoryService::search(UpnpClient_Handle hdl, UPnPDirContent &dirbuf, Error &error) { - unsigned offset = 0; - unsigned total = 1000;// Updated on first read. + unsigned offset = 0, total = -1, count; - while (offset < total) { + do { char ofbuf[100]; sprintf(ofbuf, "%d", offset); @@ -173,7 +167,7 @@ ContentDirectoryService::search(UpnpClient_Handle hdl, const char *value = ixmlwrap::getFirstElementValue(response, "NumberReturned"); - const unsigned count = value != nullptr + count = value != nullptr ? ParseUnsigned(value) : 0; @@ -187,10 +181,7 @@ ContentDirectoryService::search(UpnpClient_Handle hdl, ixmlDocument_free(response); if (!success) return false; - - if (count == 0) - break; - } + } while (count > 0 && offset < total); return true; } |