From da7400ef5c62ee144fc14ba7ca4745349f0b0c72 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Wed, 26 Jun 2013 23:56:43 +0900 Subject: Return std::unique_ptr member as const ref Returning raw pointer has a risk that it may be stolen by std::shared_ptr in accident. --- src/DownloadContext.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/DownloadContext.cc') diff --git a/src/DownloadContext.cc b/src/DownloadContext.cc index 0a76bbf5..6591b3ea 100644 --- a/src/DownloadContext.cc +++ b/src/DownloadContext.cc @@ -156,12 +156,13 @@ void DownloadContext::setAttribute attrs_[key] = std::move(value); } -ContextAttribute* DownloadContext::getAttribute(ContextAttributeType key) +const std::unique_ptr& DownloadContext::getAttribute +(ContextAttributeType key) { assert(key < MAX_CTX_ATTR); const std::unique_ptr& attr = attrs_[key]; if(attr) { - return attr.get(); + return attr; } else { throw DL_ABORT_EX(fmt("No attribute named %s", strContextAttributeType(key))); -- cgit