On 01/17/2013 05:09 AM, Daniel P. Berrange wrote:
From: "Daniel P. Berrange" <berrange(a)redhat.com>
The QEMU driver default max port is 65535, but it then increments
this by 1 to 65536. This maps to 0 in an unsigned short :-( This
was apparently done so that for() loops could use "< max" instead
of "<= max". Remove this insanity and just make the loop do the
right thing.
---
src/qemu/qemu_conf.c | 4 ----
src/util/virportallocator.c | 4 ++--
2 files changed, 2 insertions(+), 6 deletions(-)
@@ -103,7 +103,7 @@ int virPortAllocatorAcquire(virPortAllocatorPtr
pa,
*port = 0;
virObjectLock(pa);
- for (i = pa->start ; i < pa->end && !*port; i++) {
+ for (i = pa->start ; i <= pa->end && !*port; i++) {
This won't work. When pa->end is 65535 (the maximum value of unsigned
short), then the loop will iterate to 0, because you set up the loop
index to be unsigned short. For things to work, you need this
additional patch:
diff --git i/src/util/virportallocator.c w/src/util/virportallocator.c
index d80347a..35f2157 100644
--- i/src/util/virportallocator.c
+++ w/src/util/virportallocator.c
@@ -97,7 +97,7 @@ int virPortAllocatorAcquire(virPortAllocatorPtr pa,
unsigned short *port)
{
int ret = -1;
- unsigned short i;
+ int i;
int fd = -1;
*port = 0;
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library
http://libvirt.org