OSSP CVS Repository

ossp - Check-in [4740]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 4740
Date: 2004-Oct-14 16:42:34 (local)
2004-Oct-14 14:42:34 (UTC)
User:rse
Branch:
Comment: Better error checking in pth_key_xxx() functions.
Tickets:
Inspections:
Files:
ossp-pkg/pth/ChangeLog      1.626 -> 1.627     3 inserted, 0 deleted
ossp-pkg/pth/pth_data.c      1.31 -> 1.32     8 inserted, 6 deleted

ossp-pkg/pth/ChangeLog 1.626 -> 1.627

--- ChangeLog    2004/10/08 16:17:02     1.626
+++ ChangeLog    2004/10/14 14:42:34     1.627
@@ -21,6 +21,9 @@
                   
   Changes between 2.0.2 and 2.0.3 (12-Sep-2004 to xx-xxx-2004)
 
+   *) Better error checking in pth_key_xxx() functions.
+      [Ralf S. Engelschall]
+
    *) Added PTH_CTRL_FAVOURNEW control which allows the user
       to disable the favouring of new threads on scheduling
       to get more strict priority based scheduling behavior.


ossp-pkg/pth/pth_data.c 1.31 -> 1.32

--- pth_data.c   2004/07/13 10:50:49     1.31
+++ pth_data.c   2004/10/14 14:42:34     1.32
@@ -36,6 +36,8 @@
 
 int pth_key_create(pth_key_t *key, void (*func)(void *))
 {
+    if (key == NULL)
+        return pth_error(FALSE, EINVAL);
     for ((*key) = 0; (*key) < PTH_KEY_MAX; (*key)++) {
         if (pth_keytab[(*key)].used == FALSE) {
             pth_keytab[(*key)].used = TRUE;
@@ -48,20 +50,20 @@
 
 int pth_key_delete(pth_key_t key)
 {
-    if (key >= PTH_KEY_MAX)
+    if (key < 0 || key >= PTH_KEY_MAX)
         return pth_error(FALSE, EINVAL);
     if (!pth_keytab[key].used)
-        return pth_error(FALSE, EINVAL);
+        return pth_error(FALSE, ENOENT);
     pth_keytab[key].used = FALSE;
     return TRUE;
 }
 
 int pth_key_setdata(pth_key_t key, const void *value)
 {
-    if (key >= PTH_KEY_MAX)
+    if (key < 0 || key >= PTH_KEY_MAX)
         return pth_error(FALSE, EINVAL);
     if (!pth_keytab[key].used)
-        return pth_error(FALSE, EINVAL);
+        return pth_error(FALSE, ENOENT);
     if (pth_current->data_value == NULL) {
         pth_current->data_value = (const void **)calloc(1, sizeof(void *)*PTH_KEY_MAX);
         if (pth_current->data_value == NULL)
@@ -81,10 +83,10 @@
 
 void *pth_key_getdata(pth_key_t key)
 {
-    if (key >= PTH_KEY_MAX)
+    if (key < 0 || key >= PTH_KEY_MAX)
         return pth_error((void *)NULL, EINVAL);
     if (!pth_keytab[key].used)
-        return pth_error((void *)NULL, EINVAL);
+        return pth_error((void *)NULL, ENOENT);
     if (pth_current->data_value == NULL)
         return (void *)NULL;
     return (void *)pth_current->data_value[key];

CVSTrac 2.0.1