trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sor...@apache.org
Subject git commit: TS-2891: Fix subtle casting bug that prevented Stat ID from being looked up correctly. This commit also makes another cast less ambiguous and fixes a poorly handled error condition.
Date Mon, 16 Jun 2014 21:43:20 GMT
Repository: trafficserver
Updated Branches:
  refs/heads/master 44afb4486 -> 58ca65e1c


TS-2891: Fix subtle casting bug that prevented Stat ID from being looked up correctly.
This commit also makes another cast less ambiguous and fixes a poorly handled error
condition.


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/58ca65e1
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/58ca65e1
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/58ca65e1

Branch: refs/heads/master
Commit: 58ca65e1cb5249810b4bb6b8113dbb9e0eed2915
Parents: 44afb44
Author: Phil Sorber <sorber@apache.org>
Authored: Mon Jun 16 15:23:19 2014 -0600
Committer: Phil Sorber <sorber@apache.org>
Committed: Mon Jun 16 15:42:31 2014 -0600

----------------------------------------------------------------------
 CHANGES                                        |  2 ++
 plugins/experimental/remap_stats/remap_stats.c | 29 ++++++++++++---------
 2 files changed, 18 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/58ca65e1/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 0933411..7a5b9ca 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,8 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache Traffic Server 5.1.0
 
+  *) [TS-2891] Fix casting bug in remap_stats.
+
   *) [TS-2879] Remap errors and redirects should honor keep-alive
 
   *) [TS-2236] Remove trailing null in response body set by fabricate_with_old_api.

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/58ca65e1/plugins/experimental/remap_stats/remap_stats.c
----------------------------------------------------------------------
diff --git a/plugins/experimental/remap_stats/remap_stats.c b/plugins/experimental/remap_stats/remap_stats.c
index 04b1723..427021c 100644
--- a/plugins/experimental/remap_stats/remap_stats.c
+++ b/plugins/experimental/remap_stats/remap_stats.c
@@ -46,7 +46,7 @@ typedef struct
 static void
 stat_add(char *name, TSMgmtInt amount, TSStatPersistence persist_type, TSMutex create_mutex)
 {
-    intptr_t stat_id = -1;
+    int stat_id = -1;
     ENTRY search, *result = NULL;
     static __thread struct hsearch_data stat_cache;
     static __thread bool hash_init = false;
@@ -67,28 +67,31 @@ stat_add(char *name, TSMgmtInt amount, TSStatPersistence persist_type,
TSMutex c
         // so this mutex won't be much overhead and it fixes a race condition
         // in the RecCore. Hopefully this can be removed in the future.
         TSMutexLock(create_mutex);
-        if (TS_ERROR == TSStatFindName((const char *) name, (int *)&stat_id))
+        if (TS_ERROR == TSStatFindName((const char *) name, &stat_id))
         {
             stat_id = TSStatCreate((const char *) name, TS_RECORDDATATYPE_INT, persist_type,
TS_STAT_SYNC_SUM);
             if (stat_id == TS_ERROR)
                 TSDebug(DEBUG_TAG, "Error creating stat_name: %s", name);
             else
-                TSDebug(DEBUG_TAG, "Created stat_name: %s stat_id: %d", name, (int)stat_id);
+                TSDebug(DEBUG_TAG, "Created stat_name: %s stat_id: %d", name, stat_id);
         }
         TSMutexUnlock(create_mutex);
 
-        search.key = TSstrdup(name);
-        search.data = (void *) stat_id;
-        hsearch_r(search, ENTER, &result, &stat_cache);
-        TSDebug(DEBUG_TAG, "Cached stat_name: %s stat_id: %d", name, (int)stat_id);
+        if (stat_id >= 0)
+        {
+            search.key = TSstrdup(name);
+            search.data = (void *)((intptr_t)stat_id);
+            hsearch_r(search, ENTER, &result, &stat_cache);
+            TSDebug(DEBUG_TAG, "Cached stat_name: %s stat_id: %d", name, stat_id);
+        }
     }
     else
-        stat_id = (intptr_t) result->data;
+        stat_id = (int)((intptr_t)result->data);
 
     if (likely(stat_id >= 0))
-        TSStatIntIncrement((int)stat_id, amount);
+        TSStatIntIncrement(stat_id, amount);
     else
-        TSDebug(DEBUG_TAG, "stat error! stat_name: %s stat_id: %d", name, (int)stat_id);
+        TSDebug(DEBUG_TAG, "stat error! stat_name: %s stat_id: %d", name, stat_id);
 }
 
 static char *
@@ -142,7 +145,7 @@ handle_post_remap(TSCont cont, TSEvent event ATS_UNUSED, void *edata)
         TSHttpTxnArgSet(txn, config->txn_slot, txnd);
     else
     {
-        txnd = (void *) ((intptr_t)txnd | (intptr_t)TSHttpTxnArgGet(txn, config->txn_slot));
// We need the hostname pre-remap
+        txnd = (void *) ((uintptr_t)txnd | (uintptr_t)TSHttpTxnArgGet(txn, config->txn_slot));
// We need the hostname pre-remap
         TSHttpTxnArgSet(txn, config->txn_slot, txnd);
     }
 
@@ -170,11 +173,11 @@ handle_txn_close(TSCont cont, TSEvent event ATS_UNUSED, void *edata)
     config = (config_t *) TSContDataGet(cont);
     txnd = TSHttpTxnArgGet(txn, config->txn_slot);
 
-    hostname = (char *) ((intptr_t)txnd & (~((intptr_t) 0x01))); // Get hostname
+    hostname = (char *) ((uintptr_t)txnd & (~((uintptr_t) 0x01))); // Get hostname
 
     if (txnd)
     {
-        if ((intptr_t) txnd & 0x01) // remap succeeded?
+        if ((uintptr_t) txnd & 0x01) // remap succeeded?
         {
             if (!config->post_remap_host)
                 remap = hostname;


Mime
View raw message