summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ace/Managed_Object.cpp17
-rw-r--r--ace/Managed_Object.h10
2 files changed, 14 insertions, 13 deletions
diff --git a/ace/Managed_Object.cpp b/ace/Managed_Object.cpp
index b6c15a0ae83..3d5ba1529cb 100644
--- a/ace/Managed_Object.cpp
+++ b/ace/Managed_Object.cpp
@@ -23,7 +23,7 @@ ACE_Managed_Cleanup<TYPE>::object (void)
template <class TYPE>
int
-ACE_Managed_Object<TYPE>::get_object (u_int &id, TYPE *&object)
+ACE_Managed_Object<TYPE>::get_object (int &id, TYPE *&object)
{
// Use the ACE_Object_Manager instance's lock.
ACE_MT (ACE_Thread_Mutex &lock = *ACE_Object_Manager::instance ()->lock_);
@@ -43,6 +43,7 @@ ACE_Managed_Object<TYPE>::get_object (u_int &id, TYPE *&object)
}
else
{
+ id = ACE_Object_Manager::next_managed_object;
ACE_Object_Manager::managed_object[
ACE_Object_Manager::next_managed_object++] = object;
return 0;
@@ -56,9 +57,9 @@ ACE_Managed_Object<TYPE>::get_object (u_int &id, TYPE *&object)
return -1;
}
}
- else if (id >= ACE_Object_Manager::next_managed_object)
+ else if (id < 0 || (u_int) id >= ACE_Object_Manager::next_managed_object)
{
- // Unknown, non-zero id.
+ // Unknown, non-zero, or negative id.
object = 0;
errno = ENOENT;
return -1;
@@ -67,22 +68,22 @@ ACE_Managed_Object<TYPE>::get_object (u_int &id, TYPE *&object)
{
// id is known, so return the object. Cast its type based
// on the type of the function template parameter.
- object = (TYPE *) ACE_Object_Manager::managed_object[id];
+ object = (TYPE *) ACE_Object_Manager::managed_object[id - 1];
return 0;
}
}
template <class TYPE>
TYPE *
-ACE_Managed_Object<TYPE>::get_object (u_int &id)
+ACE_Managed_Object<TYPE>::get_object (int id)
{
// Use the ACE_Object_Manager instance's lock.
ACE_MT (ACE_Thread_Mutex &lock = *ACE_Object_Manager::instance ()->lock_);
ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, lock, 0));
- if (id == 0 || id >= ACE_Object_Manager::next_managed_object)
+ if (id <= 0 || (u_int) id > ACE_Object_Manager::next_managed_object)
{
- // Unknown managed object id.
+ // Unknown or invalid managed object id.
errno = ENOENT;
return 0;
}
@@ -91,7 +92,7 @@ ACE_Managed_Object<TYPE>::get_object (u_int &id)
// id is known, so return the object. Cast its type based
// on the type of the function template parameter.
return &((ACE_Managed_Cleanup<TYPE> *)
- ACE_Object_Manager::managed_object[id])->object ();
+ ACE_Object_Manager::managed_object[id - 1])->object ();
}
}
diff --git a/ace/Managed_Object.h b/ace/Managed_Object.h
index c00cc52ecde..a6e827169a9 100644
--- a/ace/Managed_Object.h
+++ b/ace/Managed_Object.h
@@ -60,7 +60,7 @@ class ACE_Managed_Object
// that it holds in calls to get_object ().
{
public:
- static int get_object (u_int &id, TYPE *&object);
+ static int get_object (int &id, TYPE *&object);
// Get the object identified by "id". If "id" is 0, allocates a new
// instance, and sets "id" to the new identifier for that instance.
// Returns 0 on success. On failure, returns -1 and sets errno to:
@@ -69,11 +69,11 @@ public:
// ENOSPC if no more table slots are available: see the
// ACE_MAX_MANAGED_OBJECTS config variable.
- static TYPE *get_object (u_int &id);
+ static TYPE *get_object (int id);
// Get the object identified by "id". Returns a pointer to the
- // object, or 0 if any error was encountered. Because no other
- // error indication is provided, it should _only_ be used for
- // accessing preallocated objects.
+ // object, or 0 if any error was encountered (and sets errno to
+ // ENOENT). Because no other error indication is provided, it
+ // should _only_ be used for accessing preallocated objects.
};
#if defined (ACE_TEMPLATES_REQUIRE_SOURCE)