From 3928a7e359053aefb370d222306307e46cc8e9b1 Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Thu, 28 Jul 2022 23:37:15 +0900 Subject: [PATCH] Remove more uses of const_cast (#2006) Follows on to #2004. --- src/curl.cpp | 2 +- src/fdcache_entity.cpp | 2 +- src/fdcache_entity.h | 2 +- src/s3fs.cpp | 1 + src/s3fs_xml.cpp | 18 +++++++++--------- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/curl.cpp b/src/curl.cpp index d608308..b73e3c6 100644 --- a/src/curl.cpp +++ b/src/curl.cpp @@ -803,7 +803,7 @@ bool S3fsCurl::PushbackSseKeys(const std::string& input) } else { char* pbase64_key; - if(NULL != (pbase64_key = s3fs_base64(reinterpret_cast(const_cast(onekey.c_str())), onekey.length()))) { + if(NULL != (pbase64_key = s3fs_base64(reinterpret_cast(onekey.c_str()), onekey.length()))) { raw_key = onekey; base64_key = pbase64_key; delete[] pbase64_key; diff --git a/src/fdcache_entity.cpp b/src/fdcache_entity.cpp index d199b40..8c2b530 100644 --- a/src/fdcache_entity.cpp +++ b/src/fdcache_entity.cpp @@ -770,7 +770,7 @@ bool FdEntity::RenamePath(const std::string& newpath, std::string& fentmapkey) bool FdEntity::IsModified() const { - AutoLock auto_data_lock(const_cast(&fdent_data_lock)); + AutoLock auto_data_lock(&fdent_data_lock); return pagelist.IsModified(); } diff --git a/src/fdcache_entity.h b/src/fdcache_entity.h index 705b64b..2942fbc 100644 --- a/src/fdcache_entity.h +++ b/src/fdcache_entity.h @@ -58,7 +58,7 @@ class FdEntity headers_t orgmeta; // original headers at opening off_t size_orgmeta; // original file size in original headers - pthread_mutex_t fdent_data_lock;// protects the following members + mutable pthread_mutex_t fdent_data_lock;// protects the following members PageList pagelist; std::string cachepath; // local cache file path // (if this is empty, does not load/save pagelist.) diff --git a/src/s3fs.cpp b/src/s3fs.cpp index 6e98837..34dcc8e 100644 --- a/src/s3fs.cpp +++ b/src/s3fs.cpp @@ -3759,6 +3759,7 @@ static bool set_mountpoint_attribute(struct stat& mpst) // static int set_bucket(const char* arg) { + // TODO: Mutates input. Consider some other tokenization. char *bucket_name = const_cast(arg); if(strstr(arg, ":")){ if(strstr(arg, "://")){ diff --git a/src/s3fs_xml.cpp b/src/s3fs_xml.cpp index 2341a16..9b7e0da 100644 --- a/src/s3fs_xml.cpp +++ b/src/s3fs_xml.cpp @@ -94,7 +94,7 @@ static xmlChar* get_base_exp(xmlDocPtr doc, const char* exp) xmlXPathContextPtr ctx = xmlXPathNewContext(doc); if(!noxmlns && GetXmlNsUrl(doc, xmlnsurl)){ - xmlXPathRegisterNs(ctx, reinterpret_cast(const_cast("s3")), reinterpret_cast(const_cast(xmlnsurl.c_str()))); + xmlXPathRegisterNs(ctx, reinterpret_cast("s3"), reinterpret_cast(xmlnsurl.c_str())); exp_string = "/s3:ListBucketResult/s3:"; } else { exp_string = "/ListBucketResult/"; @@ -102,7 +102,7 @@ static xmlChar* get_base_exp(xmlDocPtr doc, const char* exp) exp_string += exp; - if(NULL == (marker_xp = xmlXPathEvalExpression(reinterpret_cast(const_cast(exp_string.c_str())), ctx))){ + if(NULL == (marker_xp = xmlXPathEvalExpression(reinterpret_cast(exp_string.c_str()), ctx))){ xmlXPathFreeContext(ctx); return NULL; } @@ -217,7 +217,7 @@ static xmlChar* get_exp_value_xml(xmlDocPtr doc, xmlXPathContextPtr ctx, const c xmlChar* exp_value; // search exp_key tag - if(NULL == (exp = xmlXPathEvalExpression(reinterpret_cast(const_cast(exp_key)), ctx))){ + if(NULL == (exp = xmlXPathEvalExpression(reinterpret_cast(exp_key), ctx))){ S3FS_PRN_ERR("Could not find key(%s).", exp_key); return NULL; } @@ -253,7 +253,7 @@ bool get_incomp_mpu_list(xmlDocPtr doc, incomp_mpu_list_t& list) std::string ex_date; if(!noxmlns && GetXmlNsUrl(doc, xmlnsurl)){ - xmlXPathRegisterNs(ctx, reinterpret_cast(const_cast("s3")), reinterpret_cast(const_cast(xmlnsurl.c_str()))); + xmlXPathRegisterNs(ctx, reinterpret_cast("s3"), reinterpret_cast(xmlnsurl.c_str())); ex_upload += "s3:"; ex_key += "s3:"; ex_id += "s3:"; @@ -266,7 +266,7 @@ bool get_incomp_mpu_list(xmlDocPtr doc, incomp_mpu_list_t& list) // get "Upload" Tags xmlXPathObjectPtr upload_xp; - if(NULL == (upload_xp = xmlXPathEvalExpression(reinterpret_cast(const_cast(ex_upload.c_str())), ctx))){ + if(NULL == (upload_xp = xmlXPathEvalExpression(reinterpret_cast(ex_upload.c_str()), ctx))){ S3FS_PRN_ERR("xmlXPathEvalExpression returns null."); return false; } @@ -342,7 +342,7 @@ int append_objects_from_xml_ex(const char* path, xmlDocPtr doc, xmlXPathContextP xmlXPathObjectPtr contents_xp; xmlNodeSetPtr content_nodes; - if(NULL == (contents_xp = xmlXPathEvalExpression(reinterpret_cast(const_cast(ex_contents)), ctx))){ + if(NULL == (contents_xp = xmlXPathEvalExpression(reinterpret_cast(ex_contents), ctx))){ S3FS_PRN_ERR("xmlXPathEvalExpression returns null."); return -1; } @@ -361,7 +361,7 @@ int append_objects_from_xml_ex(const char* path, xmlDocPtr doc, xmlXPathContextP // object name xmlXPathObjectPtr key; - if(NULL == (key = xmlXPathEvalExpression(reinterpret_cast(const_cast(ex_key)), ctx))){ + if(NULL == (key = xmlXPathEvalExpression(reinterpret_cast(ex_key), ctx))){ S3FS_PRN_WARN("key is null. but continue."); continue; } @@ -383,7 +383,7 @@ int append_objects_from_xml_ex(const char* path, xmlDocPtr doc, xmlXPathContextP if(!isCPrefix && ex_etag){ // Get ETag xmlXPathObjectPtr ETag; - if(NULL != (ETag = xmlXPathEvalExpression(reinterpret_cast(const_cast(ex_etag)), ctx))){ + if(NULL != (ETag = xmlXPathEvalExpression(reinterpret_cast(ex_etag), ctx))){ if(xmlXPathNodeSetIsEmpty(ETag->nodesetval)){ S3FS_PRN_INFO("ETag->nodesetval is empty."); }else{ @@ -439,7 +439,7 @@ int append_objects_from_xml(const char* path, xmlDocPtr doc, S3ObjList& head) xmlXPathContextPtr ctx = xmlXPathNewContext(doc); if(!noxmlns && GetXmlNsUrl(doc, xmlnsurl)){ - xmlXPathRegisterNs(ctx, reinterpret_cast(const_cast("s3")), reinterpret_cast(const_cast(xmlnsurl.c_str()))); + xmlXPathRegisterNs(ctx, reinterpret_cast("s3"), reinterpret_cast(xmlnsurl.c_str())); ex_contents+= "s3:"; ex_key += "s3:"; ex_cprefix += "s3:";